mercredi 31 août 2016

Issue testing null check using NUnit

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?

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, "");

    }

Aucun commentaire:

Enregistrer un commentaire