Example #1
0
        public void ProjectBindingOperation_GenerateNewProjectRuleSetPath_DesiredFileNameExists_AppendsNumberToFileName()
        {
            // General setup
            const string            ruleSetRootPath = @"X:\";
            const string            fileName        = "NameTaken";
            ProjectBindingOperation testSubject     = this.CreateTestSubject();

            // Test case 1: desired name exists
            // Arrange
            this.sccFileSystem.RegisterFile($"X:\\NameTaken.ruleset");

            // Act
            string actual = testSubject.GenerateNewProjectRuleSetPath
                            (
                ruleSetRootPath,
                fileName
                            );

            // Assert
            actual.Should().Be($"X:\\{fileName}-1.ruleset", "Expected to append running number to desired file name, skipping the default one since exists");

            // Test case 2: desired name + 1 + 2 exists
            // Arrange
            this.sccFileSystem.RegisterFile(@"X:\NameTaken-1.ruleset");
            this.sccFileSystem.RegisterFile(@"X:\NameTaken-2.ruleset");

            // Act
            actual = testSubject.GenerateNewProjectRuleSetPath
                     (
                ruleSetRootPath,
                fileName
                     );

            // Assert
            actual.Should().Be(@"X:\NameTaken-3.ruleset", "Expected to append running number to desired file name");

            // Test case 3: has a pending write (not exists yet)
            ((ISourceControlledFileSystem)this.sccFileSystem).QueueFileWrite(@"X:\NameTaken-3.ruleset", () => true);

            // Act
            actual = testSubject.GenerateNewProjectRuleSetPath
                     (
                ruleSetRootPath,
                fileName
                     );

            // Assert
            actual.Should().Be(@"X:\NameTaken-4.ruleset", "Expected to append running number to desired file name, skipping 3 since pending write");
        }
        public void ProjectBindingOperation_GenerateNewProjectRuleSetPath_NoAvailableFileNames_AppendsGuid()
        {
            // Arrange
            const string            fileName        = "fileTaken";
            const string            ruleSetRootPath = @"X:\";
            ProjectBindingOperation testSubject     = this.CreateTestSubject();

            string[] existingFiles = Enumerable.Range(0, 10).Select(i => $@"X:\{fileName}-{i}.ruleset").ToArray();

            fileSystem.AddFile($@"X:\{fileName}.ruleset", new MockFileData(""));

            foreach (var existingFile in existingFiles)
            {
                fileSystem.AddFile(existingFile, new MockFileData(""));
            }

            // Act
            string actual = testSubject.GenerateNewProjectRuleSetPath
                            (
                ruleSetRootPath,
                fileName
                            );

            // Assert
            string actualFileName = Path.GetFileNameWithoutExtension(actual);

            actualFileName.Should().HaveLength(fileName.Length + 32 + 1, "Expected to append GUID to desired file name, actual: " + actualFileName);
        }
Example #3
0
        public void ProjectBindingOperation_GenerateNewProjectRuleSetPath_FileNameHasDot_AppendsExtension()
        {
            // Arrange
            const string            ruleSetRootPath = @"X:\";
            const string            fileName        = "My.File.With.Dots";
            ProjectBindingOperation testSubject     = this.CreateTestSubject();
            string expected = $"X:\\My.File.With.Dots.ruleset";

            // Act
            string actual = testSubject.GenerateNewProjectRuleSetPath
                            (
                ruleSetRootPath,
                fileName
                            );

            // Assert
            actual.Should().Be(expected);
        }
        public void ProjectBindingOperation_GenerateNewProjectRuleSetPath_NoAvailableFileNames_AppendsGuid()
        {
            // Setup
            const string            fileName        = "fileTaken";
            const string            ruleSetRootPath = @"X:\";
            ProjectBindingOperation testSubject     = this.CreateTestSubject();

            string[] existingFiles = Enumerable.Range(0, 10).Select(i => $@"X:\{fileName}-{i}.ruleset").ToArray();
            this.sccFileSystem.RegisterFile($@"X:\{fileName}.ruleset");
            this.sccFileSystem.RegisterFiles(existingFiles);


            // Act
            string actual = testSubject.GenerateNewProjectRuleSetPath
                            (
                ruleSetRootPath,
                fileName
                            );

            // Verify
            string actualFileName = Path.GetFileNameWithoutExtension(actual);

            Assert.AreEqual(fileName.Length + 32 + 1, actualFileName.Length, "Expected to append GUID to desired file name, actual: " + actualFileName);
        }