I am new to C# programming.
I am trying to automate some API tests and passing payload in a POST request using RestSharp library. That payload looks like this
public class Payload
{
public string firstPayload = @"{
" + "\n" +
@" ""channel"": ""XYZ"",
" + "\n" +
@" ""Email"": ""abc@abc.com""
" + "\n" +
@"}";
}
I call this payload in the Test Project. This request will look something like this in Postman (JSON)
{
"channel": "XYZ",
"Email": "abc@abc.com"
}
But since I can't use the same email over and over, now I want to add (DateTime.Now) in YYYYMMDDTHHMMSS format with the email, so that everytime I run my test, it's a unique email. The email should look like "abc20220825124587@abc.com"
But I am not sure how to add current date time within the verbatim string firstPayload C# code
You can do something like this
var payload = $@"
{{
""channel"": ""XYZ"",
""Email"": ""abc{DateTime.Now}@abc.com""
}}";
You don't need to manually add "/n"
when using string literal