Beispiel #1
0
        public void OldNameIsConverterToFullName()
        {
            // Arrange

            const string oldFileName = "OldFileName.txt";
            const string newFileName = "NewFileName.txt";
            const string path        = @"C:\Directory\SubDirectory\";

            const string newFullName     = path + newFileName;
            const string expectedOldName = path + oldFileName;

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();
            var service             = new ProjectItemsEventsService(metadataManagerMock.Object);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == newFullName));

            // Act

            service.ItemRenamed(projectItem, oldFileName);

            // Assert

            metadataManagerMock.Verify(m => m.UpdateFullName(
                                           newFullName,
                                           expectedOldName));
        }
Beispiel #2
0
        public void RenamingDocumentCallsDocumentMetadataManager()
        {
            // Arrange

            var metadataManager = Mock.Of <IDocumentMetadataManager>(m =>
                                                                     m.UpdateFullName(
                                                                         It.IsAny <string>(),
                                                                         It.IsAny <string>()) == true);

            var service = new ProjectItemsEventsService(metadataManager);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == "NewName") &&
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFile));

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            Mock.Get(metadataManager).Verify(m => m.UpdateFullName(
                                                 It.IsAny <string>(),
                                                 It.IsAny <string>()));
        }
Beispiel #3
0
        public void OldNameIsConverterToFullName()
        {
            // Arrange

            const string oldFileName = "OldFileName.txt";
            const string newFileName = "NewFileName.txt";
            const string path        = @"C:\Directory\SubDirectory\";

            const string newFullName     = path + newFileName;
            const string expectedOldName = path + oldFileName;

            var metadataManager = Mock.Of <IDocumentMetadataManager>(m =>
                                                                     m.UpdateFullName(
                                                                         It.IsAny <string>(),
                                                                         It.IsAny <string>()) == true);

            var service = new ProjectItemsEventsService(metadataManager);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == newFullName) &&
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFile));

            // Act

            service.ItemRenamed(projectItem, oldFileName);

            // Assert

            Mock.Get(metadataManager).Verify(m => m.UpdateFullName(
                                                 newFullName,
                                                 expectedOldName));
        }
Beispiel #4
0
        public void MetadataIsSynchronizedIfRenamingDocumentFails()
        {
            // Arrange

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();

            metadataManagerMock
            .Setup(m => m.UpdateFullName(
                       It.IsAny <string>(),
                       It.IsAny <string>()))
            .Throws <Exception>();

            var service   = new ProjectItemsEventsService(metadataManagerMock.Object);
            var documents = Mock.Of <Documents>();

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == "NewName") &&
                                                    p.DTE == Mock.Of <DTE>(d => d.Documents == documents) &&
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFile));

            // Act, Assert

            Assert.DoesNotThrow(() =>
                                service.ItemRenamed(projectItem, "OldName"));

            metadataManagerMock.Verify(m =>
                                       m.Synchronize(documents, true),
                                       Times.Once);
        }
Beispiel #5
0
        public void MetadataIsSynchronizedDependingOnRenamingItemSuccess(bool renameSuccess)
        {
            // Arrange

            var metadataManager = Mock.Of <IDocumentMetadataManager>(m =>
                                                                     m.UpdateFullName(
                                                                         It.IsAny <string>(),
                                                                         It.IsAny <string>()) == renameSuccess);

            var service   = new ProjectItemsEventsService(metadataManager);
            var documents = Mock.Of <Documents>();

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == "NewName") &&
                                                    p.DTE == Mock.Of <DTE>(d => d.Documents == documents) &&
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFile));

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            var times = renameSuccess
                ? Times.Never()
                : Times.Once();

            Mock.Get(metadataManager).Verify(m => m.Synchronize(documents, true), times);
        }
Beispiel #6
0
        public void RenamingNullDocumentProjectItemDoesNotCallDocumentMetadataManager()
        {
            // Arrange

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();
            var service             = new ProjectItemsEventsService(metadataManagerMock.Object);

            var projectItem = Mock.Of <ProjectItem>();

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            metadataManagerMock.Verify(m => m.UpdateFullName(
                                           It.IsAny <string>(),
                                           It.IsAny <string>()),
                                       Times.Never);
        }
Beispiel #7
0
        public void RenamingProjectItemWithUnparsableKindDoesNotThrowException()
        {
            // Arrange

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();
            var service             = new ProjectItemsEventsService(metadataManagerMock.Object);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Kind == "UnparsableKind");

            // Act, Assert

            Assert.DoesNotThrow(() =>
                                service.ItemRenamed(projectItem, "OldName"));

            metadataManagerMock.Verify(m => m.UpdateFullName(
                                           It.IsAny <string>(),
                                           It.IsAny <string>()),
                                       Times.Never);
        }
Beispiel #8
0
        public void RenamingDocumentCallsDocumentMetadataManager()
        {
            // Arrange

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();
            var service             = new ProjectItemsEventsService(metadataManagerMock.Object);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Document == Mock.Of <Document>(d =>
                                                                                     d.FullName == "NewName"));

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            metadataManagerMock.Verify(m => m.UpdateFullName(
                                           It.IsAny <string>(),
                                           It.IsAny <string>()));
        }
Beispiel #9
0
        public void RenamingNullDocumentProjectItemDoesNotCallDocumentMetadataManager()
        {
            // Arrange

            var metadataManagerMock = new Mock <IDocumentMetadataManager>();
            var service             = new ProjectItemsEventsService(metadataManagerMock.Object);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFile));

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            metadataManagerMock.Verify(m => m.UpdateFullName(
                                           It.IsAny <string>(),
                                           It.IsAny <string>()),
                                       Times.Never);
        }
Beispiel #10
0
        public void SynchronizeIsCalledWhenProjectItemTypeIsPhysicalFolder()
        {
            // Arrange

            var documents       = Mock.Of <Documents>();
            var metadataManager = Mock.Of <IDocumentMetadataManager>();
            var service         = new ProjectItemsEventsService(metadataManager);

            var projectItem = Mock.Of <ProjectItem>(p =>
                                                    p.DTE == Mock.Of <DTE>(dte =>
                                                                           dte.Documents == documents) &&
                                                    p.Kind == CreateKindString(VSConstants.GUID_ItemType_PhysicalFolder));

            // Act

            service.ItemRenamed(projectItem, "OldName");

            // Assert

            Mock.Get(metadataManager).Verify(m => m.Synchronize(
                                                 documents,
                                                 true));
        }