Private unit attribute test of a class / C#

Asked

Viewed 144 times

-1

I’m trying to create a unit test to ensure that an attribute of an X class is actually changed. But to compare it at the end of my test, something like:

 Assert.Equal(_sampleClass.Email, mockEmail);

I need it to have a value different from what is set in the constructor, since if it does, it can never perform what is below the condition:

public class SampleClass(){

    private string Id {get; private set};
    private string Name {get; private set}
    private StatusClass Status {get; private set}

    public SampleClass(string id, string name)
    {
        this.Id = id,
        this.Name = name,
        this.Status = StatusClass.Accepted
    }

    public void ChangeStatus(email){

        if(this.Status == StatusClass.Accepted)
            // get out of the method

        this.Email = email;
    }
}

I am looking for a way through unit tests to exchange the attribute Class status...

1 answer

2


At that point is that the practices of the TDD comes to the surface.

These private properties should not be tested. Either they should be public, or their inaccessibility shows that they are lacking methods for consultation and should be tested elsewhere, because they are not part of this unit in fact.

  • I have, I will review the logic and understand some way to test the method in question. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.