public void AllReactionsInMappingAreTriggeredOnMatchingPropertyUpdates()
        {
            // Arrange

            const string propertyName1 = "PropertyName1";
            const string propertyName2 = "PropertyName2";

            var updateReactionMock1 = new Mock <IUpdateReaction>();
            var updateReactionMock2 = new Mock <IUpdateReaction>();

            updateReactionMock1.Setup(u => u.UpdateCollection(
                                          It.IsAny <ICollectionView>(),
                                          It.IsAny <IUserPreferences>()));

            updateReactionMock2.Setup(u => u.UpdateCollection(
                                          It.IsAny <ICollectionView>(),
                                          It.IsAny <IUserPreferences>()));

            var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> >
            {
                [propertyName1] = new[] { updateReactionMock1.Object },
                [propertyName2] = new[] { updateReactionMock2.Object }
            };

            var mapping             = new TestingUpdateReactionMapping(mappingTable);
            var userPreferencesMock = new Mock <IUserPreferences>();
            var collectionView      = Mock.Of <ICollectionView>();

            var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object);

            manager.Initialize(collectionView);

            // Calling Initialize will invoke IUpdateReaction.UpdateCollection
            // Reset calls so that it is possible to verify the number of times
            // it is called as a result of raising PropertyChanged

            updateReactionMock1.ResetCalls();
            updateReactionMock2.ResetCalls();

            // Act

            userPreferencesMock.Raise(u => u.PropertyChanged += null,
                                      new PropertyChangedEventArgs(propertyName1));

            userPreferencesMock.Raise(u => u.PropertyChanged += null,
                                      new PropertyChangedEventArgs(propertyName2));

            // Assert

            updateReactionMock1.Verify(u => u.UpdateCollection(
                                           It.IsAny <ICollectionView>(),
                                           It.IsAny <IUserPreferences>()),
                                       Times.Exactly(1));

            updateReactionMock2.Verify(u => u.UpdateCollection(
                                           It.IsAny <ICollectionView>(),
                                           It.IsAny <IUserPreferences>()),
                                       Times.Exactly(1));
        }
        public void ReactionIsNotTriggeredIfCollectionViewIsNull()
        {
            // Arrange

            const string propertyName       = "PropertyName";
            var          updateReactionMock = new Mock <IUpdateReaction>();

            updateReactionMock
            .Setup(u => u.UpdateCollection(
                       It.IsAny <ICollectionView>(),
                       It.IsAny <IUserPreferences>()));

            var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> >
            {
                [propertyName] = new[] { updateReactionMock.Object }
            };

            var mapping             = new TestingUpdateReactionMapping(mappingTable);
            var userPreferencesMock = new Mock <IUserPreferences>();

            var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object);

            manager.Initialize(null);

            // Calling Initialize will invoke IUpdateReaction.UpdateCollection
            // Reset calls so that it is possible to verify the number of times
            // it is called as a result of raising PropertyChanged

            updateReactionMock.ResetCalls();

            // Act

            userPreferencesMock.Raise(u => u.PropertyChanged += null,
                                      new PropertyChangedEventArgs(propertyName));

            // Assert

            updateReactionMock.Verify(u => u.UpdateCollection(
                                          It.IsAny <ICollectionView>(),
                                          It.IsAny <IUserPreferences>()),
                                      Times.Never);
        }
예제 #3
0
        public void ReactionInMappingIsNotTriggeredOnNonMatchingPropertyUpdate()
        {
            // Arrange

            var updateReactionMock = new Mock <IUpdateReaction>();

            updateReactionMock
            .Setup(u => u.UpdateCollection(
                       It.IsAny <ICollectionView>(),
                       It.IsAny <IUserPreferences>()));

            var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> >
            {
                ["MappedProperty"] = new[] { updateReactionMock.Object }
            };

            var mapping             = new TestingUpdateReactionMapping(mappingTable);
            var userPreferencesMock = new Mock <IUserPreferences>();
            var collectionView      = Mock.Of <ICollectionView>();

            var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object);

            manager.Initialize(collectionView);

            // Calling Initialize will invoke IUpdateReaction.UpdateCollection
            // Reset calls so that it is possible to verify the number of times
            // it is called as a result of raising PropertyChanged

            updateReactionMock.Invocations.Clear();

            // Act

            userPreferencesMock.Raise(u => u.PropertyChanged += null,
                                      new PropertyChangedEventArgs("UnmappedPropertyName"));

            // Assert

            updateReactionMock.Verify(u => u.UpdateCollection(
                                          It.IsAny <ICollectionView>(),
                                          It.IsAny <IUserPreferences>()),
                                      Times.Never);
        }