Ejemplo n.º 1
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 MappingTableMapsCorrespondingUpdateReaction(
            string mappingKey,
            Type updateReactionType)
        {
            // Arrange

            var allUpdateReactions = CreateUpdateReactions();

            // Act

            var mapping = new UpdateReactionMapping(allUpdateReactions);

            // Assert

            Assert.That(mapping.MappingTable, Contains.Key(mappingKey));

            var reactionsForMapping = mapping.MappingTable[mappingKey];
            var matchingReaction    = reactionsForMapping
                                      .SingleOrDefault(reaction => reaction.GetType() == updateReactionType);

            Assert.That(matchingReaction, Is.Not.Null);
        }