public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension)
    {
        var fileSystem = new TestFileSystem();
        var workingDir = Path.GetTempPath();
        var assemblyInfoFile = new HashSet<string>
        {
            "AssemblyInfo." + fileExtension,
            Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension)
        };
        var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
        var arguments = new Arguments
        {
            EnsureAssemblyInfo = true,
            UpdateAssemblyInfo = true,
            UpdateAssemblyInfoFileName = assemblyInfoFile
        };

        using (new AssemblyInfoFileUpdate(arguments, workingDir, variables, fileSystem))
        {
            foreach (var item in assemblyInfoFile)
            {
                var fullPath = Path.Combine(workingDir, item);
                fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
            }
        }
    }
Ejemplo n.º 2
0
        public void CreateDirectoryWithNull()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            fileSystem.StageDirectory(a_path: null);
        }
Ejemplo n.º 3
0
        public void ConstructTestDirectoryWithNullPath()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            new TestDirectory(a_fileSystem: fileSystem, a_path: null);
        }
Ejemplo n.º 4
0
        public void CanSetNextVersion()
        {
            var testFileSystem = new TestFileSystem();
            var testConsole = new TestConsole("3", "2.0.0", "0");
            ConfigurationProvider.Init("c:\\proj", testFileSystem, testConsole);

            testFileSystem.ReadAllText("c:\\proj\\GitVersionConfig.yaml").ShouldMatchApproved();
        }
Ejemplo n.º 5
0
        public void CreateDirectoryWithBadPath()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var path = @"X:\This is bad a directory path?";

            // Execute
            fileSystem.StageDirectory(path);
        }
Ejemplo n.º 6
0
        public void CopyInWithNullDirectory()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var directory = fileSystem.StageDirectory(@"\directory");

            // Execute
            DirectoryHelpers.CopyIn(directory, a_directory: null);
        }
Ejemplo n.º 7
0
        public void CreateDirectoryMoreThanOnce()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var path = @"X:\This is bad a directory path";

            // Execute
            fileSystem.StageDirectory(path);
            fileSystem.StageDirectory(path);
        }
Ejemplo n.º 8
0
        public void CopyInWithNotExistingDirectory()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var directory = fileSystem.StageDirectory(@"\directory");
            var other = new TestDirectory(fileSystem, @"\other");

            // Execute
            DirectoryHelpers.CopyIn(directory, other);
        }
Ejemplo n.º 9
0
        public void CopyInOnNotExistingDirectory()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var directory = new TestDirectory(@"\directory");
            var file = fileSystem.StageFile(@"\file1.dat");

            // Execute
            directory.CopyIn(file);
        }
Ejemplo n.º 10
0
        public void CallExistsWithNonexistingFile()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var file = new TestFile(fileSystem, "\\file\\does\\not\\exist.dat");

            // Execute
            var result = file.Exists;

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 11
0
        public void ConstructTestDirectory()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            var directory = new TestDirectory(fileSystem, "\\");

            // Assert
            Assert.AreEqual("\\", directory.Path);
            Assert.AreSame(fileSystem, directory.FileSystem);
        }
Ejemplo n.º 12
0
        public void ConstructTestFile()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            var file = new TestFile(fileSystem, "\\file.dat");

            // Assert
            Assert.AreEqual("\\file.dat", file.Path);
            Assert.AreSame(fileSystem, file.FileSystem);
        }
Ejemplo n.º 13
0
        public void CreateDirectory()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var path = @"X:\This is a directory path\";

            // Execute
            fileSystem.StageDirectory(path);

            // Assert
            Assert.IsTrue(fileSystem.DirectoryExists(path));
        }
    public void ShouldCreateCSharpAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo()
    {
        var fileSystem = new TestFileSystem();
        const string workingDir = "C:\\Testing";
        ISet<string> assemblyInfoFile = new HashSet<string> { @"src\Project\Properties\VersionAssemblyInfo.cs" };
        var fullPath = Path.Combine(workingDir, assemblyInfoFile.First());

        var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
        using (new AssemblyInfoFileUpdate(new Arguments { EnsureAssemblyInfo = true, UpdateAssemblyInfo = true, UpdateAssemblyInfoFileName = assemblyInfoFile }, workingDir, variables, fileSystem))
        {
            fileSystem.ReadAllText(fullPath).ShouldMatchApproved();
        }
    }
Ejemplo n.º 15
0
        public void CallExistsOnExistingFile()
        {
            // Setup
            var path = "\\file\\does\\exist.dat";
            var fileSystem = new TestFileSystem();
            fileSystem.StageFile(path, new TestFileInstance());
            var file = new TestFile(fileSystem, path);

            // Execute
            var result = file.Exists;

            // Assert
            Assert.IsTrue(result);
        }
    public void ShouldCreateCSharpAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo()
    {
        var fileSystem = new TestFileSystem();
        const string workingDir = "C:\\Testing";
        ISet<string> assemblyInfoFile = new HashSet<string> { "AssemblyInfo.cs", @"src\Project\Properties\VersionAssemblyInfo.cs" };

        var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
        using (new AssemblyInfoFileUpdate(new Arguments { EnsureAssemblyInfo = true, UpdateAssemblyInfo = true, UpdateAssemblyInfoFileName = assemblyInfoFile }, workingDir, variables, fileSystem))
        {
            foreach (var item in assemblyInfoFile)
            {
                var fullPath = Path.Combine(workingDir, item);
                // ReSharper disable once AccessToForEachVariableInClosure
                fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.WithDescriminator(item.Replace("\\", string.Empty).Replace(".", string.Empty)));
            }
        }
    }
Ejemplo n.º 17
0
        public void CreateFile()
        {
            // Setup
            var created = DateTime.UtcNow;
            var lastModified = DateTime.UtcNow;
            var fileSystem = new TestFileSystem();

            // Execute
            fileSystem.StageFile(@"X:\Directory\File.dat", new TestFileInstance { Size = 14067, CreatedTimeUtc = created, LastModifiedTimeUtc = lastModified });

            // Assert
            Assert.IsTrue(fileSystem.FileExists(@"X:\Directory\File.dat"));
            var stats = fileSystem.GetFileInstance(@"X:\Directory\File.dat");
            Assert.AreEqual(14067, stats.Size);
            Assert.AreEqual(created, stats.CreatedTimeUtc);
            Assert.AreEqual(lastModified, stats.LastModifiedTimeUtc);
        }
Ejemplo n.º 18
0
        public void CopyIn()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var directory = fileSystem.StageDirectory(@"D:\directory");
            var other = fileSystem.StageDirectory(@"D:\other");

            // Executea
            var result = DirectoryHelpers.CopyIn(directory, other);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Exists);
            Assert.AreEqual(@"D:\directory\other", result.Path);
            Assert.IsTrue(fileSystem.DirectoryExists(@"D:\directory\other"));
            Assert.IsInstanceOfType(result, typeof(TestDirectory));
            Assert.AreSame(fileSystem, (result as TestDirectory)?.FileSystem);
        }
Ejemplo n.º 19
0
        public void CopyIn()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            var directory = fileSystem.StageDirectory(@"D:\directory");
            var file = fileSystem.StageFile(@"D:\file1.dat");

            // Execute
            var result = directory.CopyIn(file);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Exists);
            Assert.AreEqual(@"D:\directory\file1.dat", result.Path);
            Assert.IsTrue(fileSystem.FileExists(@"D:\directory\file1.dat"));
            Assert.IsInstanceOfType(result, typeof(TestFile));
            Assert.AreSame(fileSystem, (result as TestFile)?.FileSystem);
        }
Ejemplo n.º 20
0
		public void ToRelativePath(string expected, string input)
		{
			var fileSystem = new TestFileSystem();
			Assert.AreEqual(expected, fileSystem.ToRelativePath(input));
		}
Ejemplo n.º 21
0
        public void CanDetectWhereAndWhenToInsertConstructorAndPageContentWhenConstructorDoesNotExist()
        {
            var defaultConstructor = "Sub New()"
                                     + Environment.NewLine + "    InitializeComponent()"
                                     + Environment.NewLine + "End Sub";

            var pageContent = "Public ReadOnly Property ViewModel As $viewmodelclass$"
                              + Environment.NewLine + "    Get"
                              + Environment.NewLine + "        Return New $viewmodelclass$"
                              + Environment.NewLine + "    End Get"
                              + Environment.NewLine + "End Property";

            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix            = "Page";
            profile.ViewGeneration.ViewModelFileSuffix       = "ViewModel";
            profile.Datacontext.CodeBehindConstructorContent = "DataContext = ViewModel";
            profile.Datacontext.DefaultCodeBehindConstructor = defaultConstructor;
            profile.Datacontext.CodeBehindPageContent        = pageContent;

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"Public NotInheritable Class TestPage
    Inherits Page

End Class",
            };

            var synTree = VisualBasicSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.vb",
                ActiveDocumentText     = fs.FileText,
                SyntaxTree             = synTree,
                DocumentIsCSharp       = false,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var documentRoot = synTree.GetRoot();

            var result = sut.GetCodeBehindContentToAdd("TestPage", "TestViewModel", "TestVmNamespace", documentRoot);

            var expectedContent0 = ""
                                   + Environment.NewLine + "Sub New()"
                                   + Environment.NewLine + "    InitializeComponent()"
                                   + Environment.NewLine + ""
                                   + Environment.NewLine + "DataContext = ViewModel"
                                   + Environment.NewLine + "End Sub"
                                   + Environment.NewLine + "";

            Assert.IsTrue(result[0].anythingToAdd);
            Assert.AreEqual(2, result[0].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent0, result[0].contentToAdd);

            var expectedContent1 = ""
                                   + Environment.NewLine + ""
                                   + Environment.NewLine + "Public ReadOnly Property ViewModel As TestViewModel"
                                   + Environment.NewLine + "    Get"
                                   + Environment.NewLine + "        Return New TestViewModel"
                                   + Environment.NewLine + "    End Get"
                                   + Environment.NewLine + "End Property";

            Assert.IsTrue(result[1].anythingToAdd);
            Assert.AreEqual(7, result[1].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent1, result[1].contentToAdd);
        }
Ejemplo n.º 22
0
        public void CreateFileOnRoot()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            fileSystem.StageFile(@"C:\File.dat", new TestFileInstance());

            // Assert
            Assert.IsTrue(fileSystem.FileExists(@"C:\File.dat"));
        }
Ejemplo n.º 23
0
        public void WriteFileWithNotExistingPath()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            using (var stream = fileSystem.OpenWrite(@"x:\directory2\file1.rgb"))
            {
                // Assert
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.CanWrite);
                Assert.AreEqual(0, stream.Position);
                var writer = new StreamWriter(stream);
                writer.Write("Yet more data.");
                writer.Flush();

            }

            using (var stream = fileSystem.OpenRead(@"x:\directory2\file1.rgb"))
            {
                var reader = new StreamReader(stream);
                var data = reader.ReadToEnd();
                Assert.AreEqual("Yet more data.", data);
            }
        }
Ejemplo n.º 24
0
        public void WriteFileWithNullPath()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            fileSystem.OpenWrite(a_path: null);
        }
Ejemplo n.º 25
0
        public void ToRelativePath(string expected, string input)
        {
            var fileSystem = new TestFileSystem();

            Assert.AreEqual(expected, fileSystem.ToRelativePath(input));
        }
Ejemplo n.º 26
0
        public void ReadFileWithPathWithoutData()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            fileSystem.StageFile(@"x:\directory2\file1.rgb", new TestFileInstance());

            // Execute
            using (var stream = fileSystem.OpenRead(@"x:\directory2\file1.rgb"))
            {

                // Assert
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.CanRead);
                Assert.AreEqual(0, stream.Position);
                Assert.AreEqual(0, stream.Length);
            }
        }
Ejemplo n.º 27
0
        public void ReadFile()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            fileSystem.StageFile(@"x:\directory2\file1.rgb", new TestFileInstance("This is my file's data.", Encoding.UTF8));

            // Execute
            using (var stream = fileSystem.OpenRead(@"x:\directory2\file1.rgb"))
            {

                // Assert
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.CanRead);
                Assert.AreEqual(0, stream.Position);
                var reader = new StreamReader(stream);
                var data = reader.ReadToEnd();
                Assert.AreEqual("This is my file's data.", data);
            }
        }
Ejemplo n.º 28
0
        public void ReadFileWithNotExistingPath()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            using (var stream = fileSystem.OpenRead(@"x:\directory2\file1.rgb"))
            {

                // Assert
                Assert.IsNotNull(stream);
                Assert.IsTrue(stream.CanRead);
                Assert.AreEqual(0, stream.Position);
                var reader = new StreamReader(stream);
                var data = reader.ReadToEnd();
                Assert.AreEqual("This is my file's data.", data);
            }
        }
Ejemplo n.º 29
0
        public void GetFilesWithNullSearchPattern()
        {
            // Setup
            var fileSystem = new TestFileSystem();

            // Execute
            fileSystem.GetFiles(@"X:\MYDIRECTORY", a_searchPattern: null);
        }
Ejemplo n.º 30
0
        public void GetFilesWithASearchPattern()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            fileSystem.StageFile(@"x:\mydirectory\file1.dat", new TestFileInstance());
            fileSystem.StageFile(@"x:\mydirectory\file2.css", new TestFileInstance());
            fileSystem.StageFile(@"x:\mydirectory\file3.dat", new TestFileInstance());
            fileSystem.StageFile(@"x:\mydirectory\otherdirectory\file4.dat", new TestFileInstance());

            // Execute
            var filePaths = fileSystem.GetFiles(@"X:\MYDIRECTORY", "*.dat");

            // Assert
            Assert.AreEqual(2, filePaths.Length);
        }
Ejemplo n.º 31
0
        public void GetFileStatsWithNullpath()
        {
            // Setup
            var fileSystem = new TestFileSystem();
            fileSystem.StageFile(@"X:\Directory\File.dat", new TestFileInstance());

            // Execute
            var stats = fileSystem.GetFileInstance(a_path: null);
        }
Ejemplo n.º 32
0
 private static CoverallsRunResults DryRunCoverallsMultiModeWithInputFile(string inputFilePath, TestFileSystem testFileSystem)
 {
     return(CoverallsTestRunner.RunCoveralls(
                $"--multiple -i ncover={inputFilePath} --dryrun --repoToken MYTESTREPOTOKEN",
                testFileSystem));
 }
Ejemplo n.º 33
0
        public async Task CorrectOutputInSameFolder()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "Files";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Files";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = " public class TestViewModel { public string OnlyProperty { get; set;} }",
            };

            var synTree  = CSharpSyntaxTree.ParseText(fs.FileText);
            var semModel = CSharpCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.csproj"
                },
            };

            var sut = new CreateViewCommandLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            await sut.ExecuteAsync(@"C:\Test\App\Files\TestViewModel.cs");

            var expectedXaml = @"<Page
    x:Class=""App.Files.TestPage"">
    <Grid>
        <StackPanel>
            <TextBlock FB=""True"" Text=""OnlyProperty"" />
        </StackPanel>
    </Grid>
</Page>
";

            var expectedCodeBehind = @"using System;
using Windows.UI.Xaml.Controls;
using App.Files;

namespace App.Files
{
    public sealed partial class TestPage : Page
    {
        public TestViewModel ViewModel { get; set; }

        public TestPage()
        {
            this.InitializeComponent();
            this.ViewModel = new TestViewModel();
        }
    }
}
";

            Assert.IsTrue(sut.CreateView);
            Assert.AreEqual(@"C:\Test\App\Files\TestPage.xaml", sut.XamlFileName);
            Assert.AreEqual(@"C:\Test\App\Files\TestPage.xaml.cs", sut.CodeFileName);
            Assert.AreEqual(expectedXaml, sut.XamlFileContents);
            Assert.AreEqual(expectedCodeBehind, sut.CodeFileContents);
        }
Ejemplo n.º 34
0
 public TestStream(string path, TestFileSystem testFileSystem)
 {
     this.path = path;
     this.testFileSystem = testFileSystem;
 }
        public void CanDetectWhereAndWhenToInsertConstructorAndPageContentWhenConstructorDoesNotExist()
        {
            var defaultConstructor = "public $viewclass$()"
             + Environment.NewLine + "{"
             + Environment.NewLine + "    this.Initialize();"
             + Environment.NewLine + "}";

            var pageContent = "public $viewmodelclass$ ViewModel"
      + Environment.NewLine + "{"
      + Environment.NewLine + "    get"
      + Environment.NewLine + "    {"
      + Environment.NewLine + "        return new $viewmodelclass$();"
      + Environment.NewLine + "    }"
      + Environment.NewLine + "}";

            var profile = TestProfile.CreateEmpty();
            profile.ViewGeneration.XamlFileSuffix = "Page";
            profile.ViewGeneration.ViewModelFileSuffix = "ViewModel";
            profile.Datacontext.CodeBehindConstructorContent = "this.DataContext = this.ViewModel;";
            profile.Datacontext.DefaultCodeBehindConstructor = defaultConstructor;
            profile.Datacontext.CodeBehindPageContent = pageContent;

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"class TestPage
{
}",
            };

            var synTree = CSharpSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.cs",
                ActiveDocumentText = fs.FileText,
                SyntaxTree = synTree,
                DocumentIsCSharp = true,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var documentRoot = synTree.GetRoot();

            var result = sut.GetCodeBehindContentToAdd("TestPage", "TestViewModel", "TestVmNamespace", documentRoot);

            var expectedContent0 = ""
           + Environment.NewLine + "public TestPage()"
           + Environment.NewLine + "{"
           + Environment.NewLine + "    this.Initialize();"
           + Environment.NewLine + ""
           + Environment.NewLine + "this.DataContext = this.ViewModel;"
           + Environment.NewLine + "}"
           + Environment.NewLine + "";

            Assert.IsTrue(result[0].anythingToAdd);
            Assert.AreEqual(2, result[0].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent0, result[0].contentToAdd);

            var expectedContent1 = ""
           + Environment.NewLine + ""
           + Environment.NewLine + "public TestViewModel ViewModel"
           + Environment.NewLine + "{"
           + Environment.NewLine + "    get"
           + Environment.NewLine + "    {"
           + Environment.NewLine + "        return new TestViewModel();"
           + Environment.NewLine + "    }"
           + Environment.NewLine + "}";

            Assert.IsTrue(result[1].anythingToAdd);
            Assert.AreEqual(8, result[1].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent1, result[1].contentToAdd);
        }