Unit testing the Viewmodel

前端 未结 6 2214
既然无缘
既然无缘 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条回答
  •  旧时难觅i
    2021-02-05 18:39

    You can do something like this:

        [TestMethod]
        [Tag("Property")]
        public void FirstNameTest()
        {
            bool didFire = false;
            ViewModel = new CustomerViewModel();
            ViewModel.PropertyChanged += (s, e) =>
                                             {
                                                 didFire = true;
                                                 Assert.AreEqual("Firstname", e.PropertyName);
                                                 Assert.AreEqual("Test", ViewModel.Firstname);
                                             };
            ViewModel.Firstname = "Test";
            Assert.IsTrue(didFire);
        }
    

提交回复
热议问题