I am a junior dev that is new to unit testing. My company uses NUnit and I am trying to test a null check in a service method I created. Any idea what my Assert statement should look like if I am trying to test if string acctName = "" ? For some reason string acctName is getting compiler error that says
"The name does not exist in the current context."
MY METHOD:
public Dict getOrder(Client client)
{
string acctName = client != null ? client.AccountName : "";
Dict replacements = new Replacement
{
{COMPANY_NAME, acctName}
};
return new Dict(replacements);
}
MY TEST:
public void getOrderNullTest()
{
//Arrange
Client myTestClient = null;
//Act
contentService.getOrder(myTestClient);
//Assert
Assert.AreEqual(string acctName, "");
}
Client.AccountName? Are you sure it'sstring, and that the property is defined by the class?This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers.which usually leads to votes to close these as off topic.Assert.AreEqual(string acctName, "")which is a syntax error,string acctNamewhich is for when you are defining a method, not trying to call it. Hope that helps.