Exemple #1
0
        public void SourceControlledFileSystem_WriteQueuedFiles_Batching()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";
            string file3 = @"Z:\Y\XXX \2.lll";

            this.fileSystem.AddFile(file1, new MockFileData(""));
            this.fileSystem.AddFile(file3, new MockFileData(""));
            List <string> executionOrder = new List <string>();

            // Act
            testSubject.QueueFileWrite(file1, () => { executionOrder.Add(file1); return(false); });
            testSubject.QueueFileWrite(file2, () => { executionOrder.Add(file2); return(true); });
            testSubject.QueueFileWrite(file3, () => { executionOrder.Add(file3); return(true); });
            testSubject.WriteQueuedFiles().Should().BeFalse("Expected to fail");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file2);
            this.queryEditAndSave.AssertEditRequested(file1, file3);
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
            CollectionAssert.AreEqual(new[] { file1 }, executionOrder.ToArray(), "Only the first was expected to execute");

            // Act (write again)
            this.queryEditAndSave.Reset();
            executionOrder.Clear();

            // Assert (the test subject should have been cleared from previous state)
            testSubject.WriteQueuedFiles().Should().BeTrue("Should succeed since there's nothing pending");
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
            this.queryEditAndSave.AssertNoCreateRequested();
            this.queryEditAndSave.AssertNoEditRequested();
            executionOrder.Should().BeEmpty("Unexpected execution occurred");
        }
Exemple #2
0
        public void SourceControlledFileSystem_WriteQueuedFiles_NoisyPromptForCreateOperationIsRequired()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.queryEditAndSave.QuerySaveFilesVerification = flags =>
            {
                if (flags == VsQuerySaveFlags.SilentMode)
                {
                    return(tagVSQuerySaveResult.QSR_NoSave_NoisyPromptRequired);
                }
                if (flags == VsQuerySaveFlags.DefaultOperation)
                {
                    return(tagVSQuerySaveResult.QSR_SaveOK);
                }

                return(tagVSQuerySaveResult.QSR_ForceSaveAs);
            };
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            testSubject.WriteQueuedFiles().Should().BeTrue("Failed to checkout");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file1, file1); // Twice silent and then noisy
        }
Exemple #3
0
        public void SourceControlledFileSystem_FileExistOrQueuedToBeWritten()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file = @"Z:\Y\XXX \n.lll";

            // Case 1: file exists
            this.fileSystem.AddFile(file, new MockFileData(""));

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file.ToLowerInvariant()).Should().BeTrue();

            // Case 2: file not exists, but pending
            foreach (var filePath in fileSystem.AllFiles)
            {
                fileSystem.RemoveFile(filePath);
            }
            testSubject.QueueFileWrite(file, () => true);

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file.ToUpperInvariant()).Should().BeTrue();

            // Case 3: file not exists and not pending
            testSubject.WriteQueuedFiles();

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file).Should().BeFalse();
        }
        public void SourceControlledFileSystem_FileExistOrQueuedToBeWritten()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file = @"Z:\Y\XXX \n.lll";

            // Case 1: file exists
            this.fileSystem.RegisterFile(file);

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file.ToLowerInvariant()).Should().BeTrue();

            // Case 2: file not exists, but pending
            this.fileSystem.ClearFiles();
            testSubject.QueueFileWrite(file, () => true);

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file.ToUpperInvariant()).Should().BeTrue();

            // Case 3: file not exists and not pending
            testSubject.WriteQueuedFiles();

            // Act + Assert
            testSubject.FileExistOrQueuedToBeWritten(file).Should().BeFalse();
        }
        public void SourceControlledFileSystem_FileExistOrQueuedToBeWritten()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file = @"Z:\Y\XXX \n.lll";

            // Case 1: file exists
            this.fileSystem.RegisterFile(file);

            // Act + Verify
            Assert.IsTrue(testSubject.FileExistOrQueuedToBeWritten(file.ToLowerInvariant()));

            // Case 2: file not exists, but pending
            this.fileSystem.ClearFiles();
            testSubject.QueueFileWrite(file, () => true);

            // Act + Verify
            Assert.IsTrue(testSubject.FileExistOrQueuedToBeWritten(file.ToUpperInvariant()));

            // Case 3: file not exists and not pending
            testSubject.WriteQueuedFiles();

            // Act + Verify
            Assert.IsFalse(testSubject.FileExistOrQueuedToBeWritten(file));
        }
        public void SourceControlledFileSystem_QueueFileWrite_QueryNewFile()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file         = @"Z:\Y\XXX \n.lll";
            bool   pendExecuted = false;

            // Act
            testSubject.QueueFileWrite(file, () => pendExecuted = true);
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Not expecting any errors");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file);
            this.queryEditAndSave.AssertNoEditRequested();
            Assert.IsTrue(pendExecuted, "Expected to be executed");
        }
Exemple #7
0
        public void SourceControlledFileSystem_QueueFileWrites_OneCallbackForAllFiles()
        {
            // Arrange
            var testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            var files       = new List <string> {
                @"Z:\Y\XXX\first.txt", @"Z:\Y\XXX\second.txt"
            };
            var callback = new Mock <Func <bool> >();

            // Act
            testSubject.QueueFileWrites(files, callback.Object);
            testSubject.WriteQueuedFiles();

            // Assert
            callback.Verify(x => x(), Times.Once);
        }
Exemple #8
0
        public void SourceControlledFileSystem_QueueFileWrite_QueryNewFile()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file         = @"Z:\Y\XXX \n.lll";
            bool   pendExecuted = false;

            // Act
            testSubject.QueueFileWrite(file, () => pendExecuted = true);
            testSubject.WriteQueuedFiles().Should().BeTrue("Not expecting any errors");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file);
            this.queryEditAndSave.AssertNoEditRequested();
            pendExecuted.Should().BeTrue("Expected to be executed");
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_QueryEditFilesFailed()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.fileSystem.RegisterFile(file1);
            this.queryEditAndSave.QueryEditFilesVerdict = tagVSQueryEditResult.QER_EditNotOK;
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            testSubject.WriteQueuedFiles().Should().BeFalse("Failed to checkout");

            // Assert
            this.queryEditAndSave.AssertEditRequested(file1);
        }
        public void SourceControlledFileSystem_QueueFileWrite_QueryNewFile()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file = @"Z:\Y\XXX \n.lll";
            bool pendExecuted = false;

            // Act
            testSubject.QueueFileWrite(file, () => pendExecuted = true);
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Not expecting any errors");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file);
            this.queryEditAndSave.AssertNoEditRequested();
            Assert.IsTrue(pendExecuted, "Expected to be executed");
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_CheckoutFileWhenWhenDebugging()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.fileSystem.RegisterFile(file1);
            this.queryEditAndSave.VerifyQueryEditFlags |= (uint)VsQueryEditFlags.NoReload;
            KnownUIContextsAccessor.MonitorSelectionService.SetContext(VSConstants.UICONTEXT.Debugging_guid, true);
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Not expecting any errors");

            // Verify
            this.queryEditAndSave.AssertEditRequested(file1);
        }
Exemple #12
0
        public void SourceControlledFileSystem_WriteQueuedFiles_FailureInWriteOperation()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";

            // Act
            testSubject.QueueFileWrite(file1, () => false);
            testSubject.QueueFileWrite(file2, () => true);
            testSubject.WriteQueuedFiles().Should().BeFalse("Expecting a failure");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file1, file2);
            this.queryEditAndSave.AssertNoEditRequested();
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
        }
Exemple #13
0
        public void SourceControlledFileSystem_WriteQueuedFiles_CheckoutFileWhenBuilding()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.fileSystem.AddFile(file1, new MockFileData(""));
            this.queryEditAndSave.VerifyQueryEditFlags |= (uint)VsQueryEditFlags.NoReload;
            KnownUIContextsAccessor.MonitorSelectionService.SetContext(VSConstants.UICONTEXT.SolutionBuilding_guid, true);
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            testSubject.WriteQueuedFiles().Should().BeTrue("Not expecting any errors");

            // Assert
            this.queryEditAndSave.AssertEditRequested(file1);
        }
Exemple #14
0
        public void SourceControlledFileSystem_WriteQueuedFiles_QueryEditFilesFailed()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.fileSystem.AddFile(file1, new MockFileData(""));
            this.queryEditAndSave.QueryEditFilesVerdict  = tagVSQueryEditResult.QER_EditNotOK;
            this.queryEditAndSave.QueryEditFilesMoreInfo = tagVSQueryEditResultFlags.QER_EditNotPossible | tagVSQueryEditResultFlags.QER_NoisyPromptRequired;
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            testSubject.WriteQueuedFiles().Should().BeFalse("Failed to checkout");

            // Assert
            this.queryEditAndSave.AssertEditRequested(file1);
            this.logger.AssertPartialOutputStrings("QER_NoisyPromptRequired, QER_EditNotPossible"); // expecting a logged message containing the "more info" code
        }
Exemple #15
0
        public void SourceControlledFileSystem_WriteQueuedFiles_Failed()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";

            this.queryEditAndSave.QuerySaveFilesVerification = flags =>
            {
                return(tagVSQuerySaveResult.QSR_NoSave_UserCanceled);
            };
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            testSubject.WriteQueuedFiles().Should().BeFalse("Should not have attempted to write the files");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file1);
            this.logger.AssertPartialOutputStrings(tagVSQuerySaveResult.QSR_NoSave_UserCanceled.ToString()); // expecting the result code in the output message
        }
Exemple #16
0
        public void SourceControlledFileSystem_FilesExistOrQueuedToBeWritten_ReturnsIfAllFilesAreQueuedOrWritten(bool firstFileExists, bool secondFileExists, bool expectedResult)
        {
            var testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            var files       = new List <string> {
                @"Z:\Y\XXX\first.txt", @"Z:\Y\XXX\second.txt"
            };

            if (firstFileExists)
            {
                fileSystem.AddFile(files.First(), new MockFileData(""));
            }
            if (secondFileExists)
            {
                fileSystem.AddFile(files.Last(), new MockFileData(""));
            }

            var result = testSubject.FilesExistOrQueuedToBeWritten(files);

            result.Should().Be(expectedResult);
        }
Exemple #17
0
        public void SourceControlledFileSystem_QueueFileWrite_WriteQueuedFiles_ExecutionOrder()
        {
            // Arrange
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.logger, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";
            string file3 = @"Z:\Y\XXX \2.lll";

            this.fileSystem.AddFile(file1, new MockFileData(""));
            List <string> executionOrder = new List <string>();

            // Act
            testSubject.QueueFileWrite(file1, () => { executionOrder.Add(file1); return(true); });
            testSubject.QueueFileWrite(file2, () => { executionOrder.Add(file2); return(true); });
            testSubject.QueueFileWrite(file3, () => { executionOrder.Add(file3); return(true); });
            testSubject.WriteQueuedFiles().Should().BeTrue("Not expecting any errors");

            // Assert
            this.queryEditAndSave.AssertCreateRequested(file2, file3);
            this.queryEditAndSave.AssertEditRequested(file1);
            CollectionAssert.AreEqual(new[] { file1, file2, file3 }, executionOrder.ToArray(), "Unexpected execution order");
        }
        public void SourceControlledFileSystem_QueueFileWrite_WriteQueuedFiles_ExecutionOrder()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";
            string file3 = @"Z:\Y\XXX \2.lll";
            this.fileSystem.RegisterFile(file1);
            List<string> executionOrder = new List<string>();

            // Act
            testSubject.QueueFileWrite(file1, () => { executionOrder.Add(file1); return true; });
            testSubject.QueueFileWrite(file2, () => { executionOrder.Add(file2); return true; });
            testSubject.QueueFileWrite(file3, () => { executionOrder.Add(file3); return true; });
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Not expecting any errors");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file2, file3);
            this.queryEditAndSave.AssertEditRequested(file1);
            CollectionAssert.AreEqual(new[] { file1, file2, file3 }, executionOrder.ToArray(), "Unexpected execution order");
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_CheckoutFileWhenBuilding()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            this.fileSystem.RegisterFile(file1);
            this.queryEditAndSave.VerifyQueryEditFlags |= (uint)VsQueryEditFlags.NoReload;
            KnownUIContextsAccessor.MonitorSelectionService.SetContext(VSConstants.UICONTEXT.SolutionBuilding_guid, true);
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Not expecting any errors");

            // Verify
            this.queryEditAndSave.AssertEditRequested(file1);
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_QueryEditFilesFailed()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            this.fileSystem.RegisterFile(file1);
            this.queryEditAndSave.QueryEditFilesVerdict = tagVSQueryEditResult.QER_EditNotOK;
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            Assert.IsFalse(testSubject.WriteQueuedFiles(), "Failed to checkout");

            // Verify
            this.queryEditAndSave.AssertEditRequested(file1);
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_NoisyPromptForCreateOperationIsRequired()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            this.queryEditAndSave.QuerySaveFilesVerification = flags =>
            {
                if (flags == VsQuerySaveFlags.SilentMode)
                {
                     return tagVSQuerySaveResult.QSR_NoSave_NoisyPromptRequired;
                }
                if (flags == VsQuerySaveFlags.DefaultOperation)
                {
                    return tagVSQuerySaveResult.QSR_SaveOK;
                }

                return tagVSQuerySaveResult.QSR_ForceSaveAs;
            };
            testSubject.QueueFileWrite(file1, () => true);

            // Act
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Failed to checkout");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file1, file1); // Twice silent and then noisy
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_Batching()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";
            string file3 = @"Z:\Y\XXX \2.lll";
            this.fileSystem.RegisterFile(file1);
            this.fileSystem.RegisterFile(file3);
            List<string> executionOrder = new List<string>();

            // Act
            testSubject.QueueFileWrite(file1, () => { executionOrder.Add(file1); return false; });
            testSubject.QueueFileWrite(file2, () => { executionOrder.Add(file2); return true; });
            testSubject.QueueFileWrite(file3, () => { executionOrder.Add(file3); return true; });
            Assert.IsFalse(testSubject.WriteQueuedFiles(), "Expected to fail");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file2);
            this.queryEditAndSave.AssertEditRequested(file1, file3);
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
            CollectionAssert.AreEqual(new[] { file1 }, executionOrder.ToArray(), "Only the first was expected to execute");

            // Act (write again)
            this.queryEditAndSave.Reset();
            executionOrder.Clear();

            // Verify (the test subject should have been cleared from previous state)
            Assert.IsTrue(testSubject.WriteQueuedFiles(), "Should succeed since there's nothing pending");
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
            this.queryEditAndSave.AssertNoCreateRequested();
            this.queryEditAndSave.AssertNoEditRequested();
            Assert.AreEqual(0, executionOrder.Count, "Unexpected execution occurred");
        }
        public void SourceControlledFileSystem_WriteQueuedFiles_FailureInWriteOperation()
        {
            // Setup
            SourceControlledFileSystem testSubject = new SourceControlledFileSystem(this.serviceProvider, this.fileSystem);
            string file1 = @"Z:\Y\XXX \1.lll";
            string file2 = @"Z:\Y\XXX \3.lll";

            // Act
            testSubject.QueueFileWrite(file1, () => false);
            testSubject.QueueFileWrite(file2, () => true);
            Assert.IsFalse(testSubject.WriteQueuedFiles(), "Expecting a failure");

            // Verify
            this.queryEditAndSave.AssertCreateRequested(file1, file2);
            this.queryEditAndSave.AssertNoEditRequested();
            this.queryEditAndSave.AssertAllBatchesCompleted(1);
        }