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

            const string filePathServiceOutput = "FilePathServiceOutput";

            var info    = new DocumentMetadataInfo();
            var builder = new DocumentMetadataFactoryBuilder();

            builder.FilePathServiceMock
            .Setup(f => f.ReducePath(
                       It.IsAny <string>(),
                       It.IsAny <int>()))
            .Returns(filePathServiceOutput);

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info, DateTime.UtcNow);

            // Assert

            Assert.That(metadata.DisplayName, Is.EqualTo(filePathServiceOutput));
        }
Example #2
0
        public void CreateWithInfoAndActivatedTimeSetsProjectBrush()
        {
            // Arrange

            var projectBrush = Brushes.MidnightBlue;

            var info    = new DocumentMetadataInfo();
            var builder = new DocumentMetadataFactoryBuilder();

            builder.ProjectBrushServiceMock
            .Setup(p => p.GetBrush(
                       It.IsAny <string>(),
                       It.IsAny <IUserPreferences>()))
            .Returns(projectBrush);

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info, DateTime.UtcNow);

            // Assert

            Assert.That(metadata.ProjectBrush, Is.EqualTo(projectBrush));
        }
Example #3
0
        public void CorrectedFullNameEqualsPathCasingRestorerOutput()
        {
            // Arrange

            const string correctedCasing = "FullName";
            const string lowerCase       = "fullname";

            var builder = new DocumentMetadataFactoryBuilder();

            builder.PathCasingRestorerMock
            .Setup(p => p.RestoreCasing(lowerCase))
            .Returns(correctedCasing);

            var factory = builder.CreateDocumentMetadataFactory(false);

            var info = new DocumentMetadataInfo
            {
                FullName = lowerCase
            };

            // Act

            var metadata = factory.Create(info);

            // Assert

            builder.PathCasingRestorerMock.Verify(p => p.RestoreCasing(lowerCase));
            Assert.That(metadata.CorrectedFullName, Is.EqualTo(correctedCasing));
        }
Example #4
0
        public void CreateSetsMetadataIcon()
        {
            // Arrange

            const string extension = ".extension";

            var info = new DocumentMetadataInfo
            {
                FullName = $"FullName{extension}"
            };

            var builder = new DocumentMetadataFactoryBuilder();
            var icon    = Mock.Of <BitmapSource>();

            builder.DocumentIconServiceMock
            .Setup(d => d.GetIcon(extension))
            .Returns(icon);

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info);

            // Assert

            builder.DocumentIconServiceMock.Verify(d =>
                                                   d.GetIcon(extension));

            Assert.That(metadata.Icon, Is.EqualTo(icon));
        }
        public void ExecuteSynchronizesDocumentsIfNoWindowActivated()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "DocumentName"
            };

            var documentMockList = new List <Document>();
            var documents        = CreateDocuments(documentMockList);

            var dte2 = Mock.Of <DTE2>(d =>
                                      d.Documents == documents &&
                                      d.Solution == Mock.Of <Solution>());

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var documentMetadataManager = Mock.Of <IDocumentMetadataManager>();
            var command = CreateActivateWindow(dte2, documentMetadataManager);

            // Act

            command.Execute(metadata);

            // Assert

            Mock.Get(documentMetadataManager).Verify(d =>
                                                     d.Synchronize(documents, true));
        }
Example #6
0
        public void CreateWithInfoUsesFilePathServiceToSetDisplayName()
        {
            // Arrange

            const string filePathServiceOutput = "Output";
            const string preHighlightSuffix    = "[PreHighlight]";
            const string highlightSuffix       = "[Highlight]";
            const string postHighlightSuffix   = "[PostHighlight]";

            var info    = new DocumentMetadataInfo();
            var builder = new DocumentMetadataFactoryBuilder();

            builder.FilePathServiceMock
            .Setup(f => f.ReducePath(
                       It.IsAny <string>(),
                       It.IsAny <int>()))
            .Returns(filePathServiceOutput);

            builder.DisplayNameHighlightEvaluatorMock
            .Setup(d => d.GetPreHighlight(
                       It.IsAny <string>(),
                       It.IsAny <bool>()))
            .Returns <string, bool>((str, b) => str + preHighlightSuffix);

            builder.DisplayNameHighlightEvaluatorMock
            .Setup(d => d.GetHighlight(
                       It.IsAny <string>(),
                       It.IsAny <bool>()))
            .Returns <string, bool>((str, b) => str + highlightSuffix);

            builder.DisplayNameHighlightEvaluatorMock
            .Setup(d => d.GetPostHighlight(
                       It.IsAny <string>(),
                       It.IsAny <bool>()))
            .Returns <string, bool>((str, b) => str + postHighlightSuffix);

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info);

            // Assert

            builder.DisplayNameHighlightEvaluatorMock.Verify(d =>
                                                             d.GetPreHighlight(filePathServiceOutput, It.IsAny <bool>()));

            builder.DisplayNameHighlightEvaluatorMock.Verify(d =>
                                                             d.GetHighlight(filePathServiceOutput, It.IsAny <bool>()));

            builder.DisplayNameHighlightEvaluatorMock.Verify(d =>
                                                             d.GetPostHighlight(filePathServiceOutput, It.IsAny <bool>()));

            var expected =
                $"{filePathServiceOutput}{preHighlightSuffix}" +
                $"{filePathServiceOutput}{highlightSuffix}" +
                $"{filePathServiceOutput}{postHighlightSuffix}";

            Assert.That(metadata.DisplayName, Is.EqualTo(expected));
        }
Example #7
0
        public void CreateSetsDisplayNamePreHighlight()
        {
            // Arrange

            const string preHighlight = "PreHighlight";

            var info    = new DocumentMetadataInfo();
            var builder = new DocumentMetadataFactoryBuilder();

            builder.DisplayNameHighlightEvaluatorMock
            .Setup(d => d.GetPreHighlight(
                       It.IsAny <string>(),
                       It.IsAny <bool>()))
            .Returns(preHighlight);

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info);

            // Assert

            Assert.That(metadata.DisplayNamePreHighlight, Is.EqualTo(preHighlight));
        }
Example #8
0
        public void ExecuteDoesNotThrowExceptionWithNullProjectItem()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "FullName"
            };

            var projectItemServiceMock = new Mock <IProjectItemService>();

            projectItemServiceMock
            .Setup(s => s.FindProjectItem(It.IsAny <string>()))
            .Returns <ProjectItem>(null);

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var command = new OpenTestFile(
                projectItemServiceMock.Object,
                Mock.Of <ITestFileNameEvaluator>());

            // Act, Assert

            Assert.DoesNotThrow(() => command.Execute(metadata));
        }
Example #9
0
        public void ExecuteActivatesDocumentWindowForEvaluatedTestFile()
        {
            // Arrange

            const string fullName     = "FullName";
            const string testFileName = "TestFileName";

            var info = new DocumentMetadataInfo
            {
                FullName = fullName
            };

            var windowMock = new Mock <Window>();

            var evaluator = Mock.Of <ITestFileNameEvaluator>(t =>
                                                             t.EvaluateTestFileName(fullName) == testFileName);

            var projectItemService = Mock.Of <IProjectItemService>(s =>
                                                                   s.FindProjectItem(testFileName) == Mock.Of <ProjectItem>(p =>
                                                                                                                            p.Open(Constants.vsViewKindCode) == windowMock.Object));

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var command = new OpenTestFile(projectItemService, evaluator);

            // Act

            command.Execute(metadata);

            // Assert

            windowMock.Verify(w => w.Activate());
        }
Example #10
0
        public void CreatePassesPathSegmentCountFromUserPreferencesToFilePathService()
        {
            // Arrange

            const int pathSegmentCount = 7;

            var info = new DocumentMetadataInfo();

            var builder = new DocumentMetadataFactoryBuilder
            {
                UserPreferences = Mock.Of <IUserPreferences>(u =>
                                                             u.PathSegmentCount == pathSegmentCount)
            };

            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            factory.Create(info);

            // Assert

            builder.FilePathServiceMock.Verify(f => f.ReducePath(
                                                   It.IsAny <string>(),
                                                   pathSegmentCount));
        }
Example #11
0
        public void CreateReturnsNewDocumentMetadata()
        {
            // Arrange

            var builder = new DocumentMetadataFactoryBuilder();
            var factory = builder.CreateDocumentMetadataFactory(true);
            var info    = new DocumentMetadataInfo();

            // Act

            var metadata = factory.Create(info);

            // Assert

            Assert.That(metadata, Is.Not.Null);
        }
        public void UpdateFullNameMatchesOldNameWithCorrectedFullName()
        {
            // Arrange

            const string oldName          = "OldName";
            const string newName          = "NewName";
            const string correctedOldName = "CorrectedOldName";

            var metadataFactoryBuilder = new DocumentMetadataFactoryBuilder();

            metadataFactoryBuilder.PathCasingRestorerMock
            .Setup(p => p.RestoreCasing(It.IsAny <string>()))
            .Returns(correctedOldName);

            var factory = metadataFactoryBuilder.CreateDocumentMetadataFactory(false);

            var metadataManagerBuilder = new DocumentMetadataManagerBuilder
            {
                DocumentMetadataFactory = factory
            };

            metadataManagerBuilder.TimeProviderMock.Setup(t => t.UtcNow)
            .Returns(() => DateTime.UtcNow);

            var manager = metadataManagerBuilder.CreateDocumentMetadataManager();

            var documentMockList = new List <Document>
            {
                CreateDocument(oldName)
            };

            var documents = CreateDocuments(documentMockList);

            manager.Synchronize(documents, false);

            // Act

            manager.UpdateFullName(newName, correctedOldName);

            // Assert

            var collection =
                (IList <DocumentMetadata>)manager.ActiveDocumentMetadata.SourceCollection;

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection[0].FullName, Is.EqualTo(newName));
        }
        public void ExecuteFindsProjectItemAndOpensWindowIfNoDocumentWindowExists()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "DocumentName"
            };

            var window           = Mock.Of <Window>();
            var windowsMock      = CreateWindows(new List <Window>());
            var documentMockList = new List <Document>
            {
                Mock.Of <Document>(d =>
                                   d.FullName == info.FullName &&
                                   d.Windows == windowsMock)
            };

            var documents = CreateDocuments(documentMockList);

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var dte2 = Mock.Of <DTE2>(d =>
                                      d.Documents == documents);

            var projectItemService = Mock.Of <IProjectItemService>(s =>
                                                                   s.FindProjectItem(info.FullName) == Mock.Of <ProjectItem>(p =>
                                                                                                                             p.Open(Constants.vsViewKindPrimary) == window));

            var command = CreateActivateWindow(
                dte2: dte2,
                projectItemService: projectItemService);

            // Act

            command.Execute(metadata);

            // Assert

            Mock.Get(projectItemService).Verify(s =>
                                                s.FindProjectItem(info.FullName));

            Mock.Get(window).Verify(w => w.Activate());
        }
Example #14
0
        public void FullNameEqualsMetadataInfoValue()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "FullName"
            };

            var builder = new DocumentMetadataFactoryBuilder();
            var factory = builder.CreateDocumentMetadataFactory(true);

            // Act

            var metadata = factory.Create(info);

            // Assert

            Assert.That(metadata.FullName, Is.EqualTo(info.FullName));
        }
Example #15
0
        public void ExecuteClosesDocument()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "FullName"
            };

            var documentMock = new Mock <Document>();

            documentMock.Setup(d => d.FullName).Returns(info.FullName);

            var documentMockList = new List <Document>
            {
                documentMock.Object
            };

            var documents = CreateDocuments(documentMockList);

            var dte2Mock = new Mock <DTE2>();

            dte2Mock.Setup(d => d.Documents).Returns(documents);

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var command = new CloseDocument(
                dte2Mock.Object,
                new DocumentMetadataEqualityService());

            // Act

            command.Execute(metadata);

            // Assert

            documentMock.Verify(d => d.Close(It.IsAny <vsSaveChanges>()));
        }
        public void ExecuteActivatesFirstDocumentWindow()
        {
            // Arrange

            var info = new DocumentMetadataInfo
            {
                FullName = "DocumentName"
            };

            var windowMock = new Mock <Window>();
            var windowList = new List <Window>
            {
                windowMock.Object
            };

            var windowsMock      = CreateWindows(windowList);
            var documentMockList = new List <Document>
            {
                Mock.Of <Document>(d =>
                                   d.FullName == info.FullName &&
                                   d.Windows == windowsMock)
            };

            var documents = CreateDocuments(documentMockList);
            var dte2      = Mock.Of <DTE2>(d => d.Documents == documents);

            var builder  = new DocumentMetadataFactoryBuilder();
            var factory  = builder.CreateDocumentMetadataFactory(true);
            var metadata = factory.Create(info);

            var command = new ActivateWindow(dte2);

            // Act

            command.Execute(metadata);

            // Assert

            windowMock.Verify(w => w.Activate());
        }
        public void UpdateFullNameSetsUsageOrder()
        {
            // Arrange

            const string oldName = "OldName";

            var metadataFactoryBuilder = new DocumentMetadataFactoryBuilder();
            var factory = metadataFactoryBuilder.CreateDocumentMetadataFactory(true);

            var metadataManagerBuilder = new DocumentMetadataManagerBuilder
            {
                DocumentMetadataFactory = factory
            };

            metadataManagerBuilder.TimeProviderMock.Setup(t => t.UtcNow)
            .Returns(() => DateTime.UtcNow);

            var manager = metadataManagerBuilder.CreateDocumentMetadataManager();

            var documentMockList = new List <Document>
            {
                CreateDocument(oldName)
            };

            var documents = CreateDocuments(documentMockList);

            manager.Synchronize(documents, false);

            // Act

            manager.UpdateFullName("NewName", oldName);

            // Assert

            metadataManagerBuilder.NormalizedUsageOrderServiceMock
            .Verify(n => n.SetUsageOrder(
                        It.IsAny <IList <DocumentMetadata> >(),
                        It.IsAny <IUserPreferences>()));
        }