dimanche 1 décembre 2019

Is Assert.Equal method from xUnit checking the same reference or looking for two different object instances?

I started to use xUnit infrastructure. So I tried to use void Assert.Equal(string expected, string actual) method.

[Fact]
public void CanChangeProductName()
{
    // Arrange
    var p = new Product()
    {
        Name = "Name",
        Price = 180M
    };
    var new_name = "NewName";
    // Act
    p.Name = (string)new_name.Clone(); // ?
    // Assert
    Assert.Equal(new_name, p.Name);
}

And wondered, should I use string.Clone() method to create truly new object instead of comparison the same link to single object?

Aucun commentaire:

Enregistrer un commentaire