Example #1
0
        public void CollectionUpdateUsesFilePathService()
        {
            // Arrange

            const int    pathSegmentCount = 7;
            const string correctedName    = "CorrectedName";

            var filePathServiceMock = new Mock <IFilePathService>();

            var preferences = Mock.Of <IUserPreferences>(u =>
                                                         u.PathSegmentCount == pathSegmentCount);

            var updateReaction = new PathSegmentCountReaction(
                filePathServiceMock.Object);

            var info         = new DocumentMetadataInfo();
            var metadataList = new List <DocumentMetadata>
            {
                new DocumentMetadata(info, correctedName, null)
            };

            var view = new ListCollectionView(metadataList);

            // Act

            updateReaction.UpdateCollection(view, preferences);

            // Assert

            filePathServiceMock.Verify(f => f.ReducePath(
                                           correctedName,
                                           pathSegmentCount));
        }
        public void CollectionUpdateRefreshesCollectionView()
        {
            // Arrange

            var updateReaction = new PathSegmentCountReaction(
                Mock.Of <IDisplayNameHighlightEvaluator>(),
                Mock.Of <IFilePathService>());

            var collectionViewMock = new Mock <ICollectionView>
            {
                DefaultValue = DefaultValue.Mock
            };

            collectionViewMock
            .Setup(c => c.SourceCollection)
            .Returns(new List <DocumentMetadata>());

            // Act

            updateReaction.UpdateCollection(
                collectionViewMock.Object,
                Mock.Of <IUserPreferences>());

            // Assert

            collectionViewMock.Verify(c => c.Refresh());
        }
        public void CollectionUpdateUpdatesAllItemsInCollectionViewSource()
        {
            // Arrange

            const string highlight = "Highlight";

            var highlightEvaluator = Mock.Of <IDisplayNameHighlightEvaluator>(d =>
                                                                              d.GetHighlight(
                                                                                  It.IsAny <string>(),
                                                                                  It.IsAny <bool>()) == highlight);

            var updateReaction = new PathSegmentCountReaction(
                highlightEvaluator,
                Mock.Of <IFilePathService>());

            var info = new DocumentMetadataInfo();

            var includeInView = new DocumentMetadata(info, string.Empty, null)
            {
                IsActive = false
            };

            var excludeFromView = new DocumentMetadata(info, string.Empty, null)
            {
                IsActive = false
            };

            var list = new List <DocumentMetadata>
            {
                includeInView,
                excludeFromView
            };

            var view = new ListCollectionView(list)
            {
                Filter = obj =>
                {
                    // Use IsActive as indication of being included in filter
                    // in this test

                    var metadata = (DocumentMetadata)obj;
                    metadata.IsActive = metadata == includeInView;
                    return(metadata.IsActive);
                }
            };

            // Act

            updateReaction.UpdateCollection(view, Mock.Of <IUserPreferences>());

            // Assert

            Assert.AreEqual(highlight, includeInView.DisplayNameHighlight);
            Assert.AreEqual(highlight, excludeFromView.DisplayNameHighlight);

            Assert.IsTrue(includeInView.IsActive);
            Assert.IsFalse(excludeFromView.IsActive);
        }
        public void CollectionUpdateSetsDisplayNameHighlight()
        {
            // Arrange

            const string highlight   = "Highlight";
            const string reducedPath = "ReducedPath";

            var filePathService = Mock.Of <IFilePathService>(f =>
                                                             f.ReducePath(
                                                                 It.IsAny <string>(),
                                                                 It.IsAny <int>()) == reducedPath);

            var highlightEvaluatorMock = new Mock <IDisplayNameHighlightEvaluator>();

            highlightEvaluatorMock
            .Setup(h => h.GetHighlight(
                       reducedPath,
                       It.IsAny <bool>()))
            .Returns(highlight);

            var info     = new DocumentMetadataInfo();
            var metadata = new DocumentMetadata(info, "CorrectedName", null);

            var metadataList = new List <DocumentMetadata>
            {
                metadata
            };

            var view = new ListCollectionView(metadataList);

            var updateReaction = new PathSegmentCountReaction(
                highlightEvaluatorMock.Object,
                filePathService);

            // Act

            updateReaction.UpdateCollection(view, Mock.Of <IUserPreferences>());

            // Assert

            highlightEvaluatorMock.Verify(h => h.GetHighlight(
                                              reducedPath,
                                              It.IsAny <bool>()));

            Assert.That(metadata.DisplayNameHighlight, Is.EqualTo(highlight));
        }
Example #5
0
        public void CollectionUpdateRefreshesCollectionView()
        {
            // Arrange

            var updateReaction = new PathSegmentCountReaction(
                Mock.Of <IFilePathService>());

            var collectionViewMock = new Mock <ICollectionView>
            {
                DefaultValue = DefaultValue.Mock
            };

            // Act

            updateReaction.UpdateCollection(
                collectionViewMock.Object,
                Mock.Of <IUserPreferences>());

            // Assert

            collectionViewMock.Verify(c => c.Refresh());
        }