Unit testing the Viewmodel

前端 未结 6 2085
既然无缘
既然无缘 2021-02-05 18:03

I am sort of new to TDD. I have started creating the properties I need on the view model as plain auto property.

public string Firstname { get; set; }

6条回答
  •  余生分开走
    2021-02-05 18:35

    Perhaps there is more background to this code that is not being revealed, but what I am seeing seems unnecessarily complicated. Why bother hooking into the RaisePropertyChanged event at all? Just check the property after setting it.

    [TestMethod]
    [Tag("Property")]
    public void FirstNameTest()
    {
        var expected = "John";
        var sut = new CustomerViewModel();
    
        sut.Firstname = expected;
    
        Assert.AreEqual(expected, sut.Firstname);
    }
    

    This also turns the test into a true unit test.

提交回复
热议问题