public void IsAdvertisementValid_WhenChangingFromFalseToTrue_CallsPropertyChangedEvent() { // Arrange var adModel = GetNewEmptyAdvertisement(); var adViewModel = GetAdvertisementViewModel(adModel); var eventAssert = new PropertyChangedEventAssert(adModel); adViewModel.HasErrors.Should().Be(false, "Populated Ad has invalid name"); adViewModel.HasErrors.Should().Be(false, "Populated Ad has invalid text"); // Act eventAssert.ExpectNothing(); adViewModel.Name = TEST_AD_NAME; adViewModel.HasErrors.Should().Be(true, "Name is now valid"); adViewModel.IsEntityValid.Should().Be(false, "Ad is still invalid."); adViewModel.Text = TEST_AD_TEXT; // Assert adViewModel.HasErrors.Should().Be(true, "Text should now be valid"); adViewModel.IsEntityValid.Should().Be(true, "If all fields are valid, the Ad is valid"); eventAssert.Expect("Name"); eventAssert.Expect("HasErrors"); eventAssert.Expect("Text"); eventAssert.Expect("HasErrors"); eventAssert.Expect("IsEntityValid"); }
public void Name_WhenModified_PerformsPropertyChangedCallback() { // Arrange const string AD_NAME = "Test ad 1 name"; const string NEW_AD_NAME = "New ad name"; var testAd = new Advertisement { Name = AD_NAME }; var eventAssert = new PropertyChangedEventAssert(testAd); testAd.Name.Should().Be(AD_NAME, "Ad name set properly"); eventAssert.ExpectNothing(); testAd.Name = NEW_AD_NAME; eventAssert.Expect("Name"); }
public void Name_WhenModifiedFromValidToInvalidChangesHasErrors_PerformsPropertyChangedCallback() { // Arrange const string PAPER_NAME = "Paper 1 name"; const string NEW_PAPER_NAME = ""; var paper = new Newspaper() { Name = PAPER_NAME }; var eventAssert = new PropertyChangedEventAssert(paper); paper.Name.Should().Be(PAPER_NAME, "Ad name set properly"); eventAssert.ExpectNothing(); paper.Name = NEW_PAPER_NAME; eventAssert.Expect("Name"); }
public void HasErrors_WhenModified_PerformsPropertyChangedCallbackOnNameAndHasErrors() { // Arrange var adModel = GetNewPopulatedAdvertisement(); var adViewModel = GetAdvertisementViewModel(adModel); adModel.HasErrors.Should().Be(true, "Name should be valid"); var eventAssert = new PropertyChangedEventAssert(adModel); eventAssert.ExpectNothing(); // Act adViewModel.Name = null; // Assert eventAssert.Expect("Name"); eventAssert.Expect("HasErrors"); }
public void Name_WhenModified_PerformsPropertyChangedCallback() { // Arrange var paper = GetPopulatedNewspaper(); var vm = GetNewspaperViewModel(paper); paper.Name.Should().Be(TEST_PAPER_NAME, "Name should be set."); // Act var eventAssert = new PropertyChangedEventAssert(paper); eventAssert.ExpectNothing(); vm.Name = NEW_PAPER_NAME; // Assert paper.Name.Should().Be(NEW_PAPER_NAME, "ViewModel should set new name in the model"); eventAssert.Expect("Name"); }
public void Name_WhenModified_PerformsPropertyChangedCallback() { // Arrange const string PAPER_NAME = "Paper 1 name"; const string NEW_PAPER_NAME = "New paper 1 name"; var paper = new Newspaper() {Name = PAPER_NAME}; var eventAssert = new PropertyChangedEventAssert(paper); paper.Name.Should().Be(PAPER_NAME, "Ad name set properly"); eventAssert.ExpectNothing(); paper.Name = NEW_PAPER_NAME; eventAssert.Expect("Name"); }
public void Name_WhenModified_PerformsPropertyChangedCallback() { // Arrange const string AD_NAME = "Test ad 1 name"; const string NEW_AD_NAME = "New ad name"; var testAd = new Advertisement {Name = AD_NAME}; var eventAssert = new PropertyChangedEventAssert(testAd); testAd.Name.Should().Be(AD_NAME, "Ad name set properly"); eventAssert.ExpectNothing(); testAd.Name = NEW_AD_NAME; eventAssert.Expect("Name"); }
public void Name_WhenSettingNewValidValue_SetsNewValueInModel() { // Arrange var vm = GetValidNewspaperItemViewModel(); var newName = new String(vm.Name.ToCharArray()) + "_Changed"; var propertyChangedEvent = new PropertyChangedEventAssert(vm); propertyChangedEvent.ExpectNothing("No events should be pending."); // Act vm.Name = newName; // Assert vm.Model.Name.Should().Be(newName, "New value has been assigned to the property."); }
public void Name_WhenSettingNewValidValue_InvokesPropertyChangedOnNameProperty() { // Arrange var vm = GetValidNewspaperItemViewModel(); var newName = new String(vm.Name.ToCharArray()) + "_Changed"; var propertyChangedEvent = new PropertyChangedEventAssert(vm); propertyChangedEvent.ExpectNothing("No events should be pending."); // Act vm.Name = newName; // Assert propertyChangedEvent.Expect("Name"); }
public void Name_SetWithSameValueAsInModel_DoesNotInvokePropertyChanged() { // Arrange var vm = GetValidNewspaperItemViewModel(); var currentName = new String(vm.Name.ToCharArray()); var propetyChangedEvent = new PropertyChangedEventAssert(vm); propetyChangedEvent.ExpectNothing("No events should be pending."); // Act vm.Name = currentName; // Assert propetyChangedEvent.ExpectNothing( "No PropertyChanged event should be invoked because the model and assigned values are equal."); }
public void Text_WhenSettingNewValidValue_SetsNewValueInModel() { // Arrange var vm = GetValidAdvertisementItemViewModel(); var newText = new String(vm.Text.ToCharArray()) + "_Changed"; var propertyChangedEvent = new PropertyChangedEventAssert(vm); propertyChangedEvent.ExpectNothing("No events should be pending."); // Act vm.Text = newText; // Assert vm.Model.Text.Should().Be(newText, "New value has been assigned to the property."); }
public void Text_WhenSettingNewValidValue_InvokesPropertyChangedOnNameProperty() { // Arrange var vm = GetValidAdvertisementItemViewModel(); var newText = new String(vm.Text.ToCharArray()) + "_Changed"; var propertyChangedEvent = new PropertyChangedEventAssert(vm); propertyChangedEvent.ExpectNothing("No events should be pending."); // Act vm.Text = newText; // Assert propertyChangedEvent.Expect("Text"); }