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));
        }
Example #2
0
        /// <summary>
        /// Create and return a new <see cref="DocumentMetadataManager"/>,
        /// configured with the properties available in this builder instance
        /// </summary>
        /// <returns>
        /// A new <see cref="DocumentMetadataManager"/> for use in unit tests
        /// </returns>
        public DocumentMetadataManager CreateDocumentMetadataManager()
        {
            if (DocumentMetadataFactory == null)
            {
                var builder = new DocumentMetadataFactoryBuilder(TimeProviderMock);
                DocumentMetadataFactory = builder.CreateDocumentMetadataFactory(true);
            }

            if (UserPreferences == null)
            {
                UserPreferences = UserPreferencesBuilder.CreateUserPreferences();
            }

            if (UpdateReactionMapping == null)
            {
                var displayNameHighlightEvaluator = new DisplayNameHighlightEvaluator();
                var filePathService = new FilePathService();

                var updateReactions = new IUpdateReaction[]
                {
                    new AssignProjectColoursReaction(Mock.Of <IProjectBrushService>()),
                    new GroupByProjectReaction(),
                    new PathSegmentCountReaction(displayNameHighlightEvaluator, filePathService),
                    new SelectedSortOptionReaction(SortOptionsService),
                    new ShowRecentUsageReaction(NormalizedUsageOrderServiceMock.Object)
                };

                UpdateReactionMapping = new UpdateReactionMapping(updateReactions);
            }

            if (UpdateReactionManager == null)
            {
                UpdateReactionManager = new UpdateReactionManager(
                    UpdateReactionMapping,
                    UserPreferences);
            }

            var manager = new DocumentMetadataManager(
                CollectionViewGenerator ?? new CollectionViewGenerator(),
                CountdownTimer ?? new TestingCountdownTimer(),
                DocumentMetadataEqualityService ?? new DocumentMetadataEqualityService(),
                DocumentMetadataFactory,
                NormalizedUsageOrderServiceMock.Object,
                ProjectItemServiceMock.Object,
                TimeProviderMock.Object,
                UpdateReactionManager,
                UserPreferences);

            // Initialization logic in the constructor of
            // DocumentMetadataManager will make calls on the mock
            // NormalizedUsageOrderService. Reset calls so that these are not
            // counted in the tests that the created DocumentMetadataManager
            // will be used in.

            NormalizedUsageOrderServiceMock.Invocations.Clear();

            return(manager);
        }
        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);
        }
Example #4
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);
        }