Exemple #1
0
        public async Task WriteTextByRelativePathAsync_ReadWriteRoundtrip_ShouldReadBackEqual(string expectedFilePath)
        {
            var org = "ttd";
            var sourceRepository = "hvem-er-hvem";
            var developer        = "testUser";
            var targetRepository = Guid.NewGuid().ToString();

            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            var    repositoryDirectory       = await TestDataHelper.CopyRepositoryForTest(org, sourceRepository, developer, targetRepository);

            var gitRepository = new Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository(repositoriesRootDirectory, repositoryDirectory);

            var expectedContent = await gitRepository.ReadTextByRelativePathAsync(expectedFilePath);

            var filename = $"{Guid.NewGuid()}.json";

            try
            {
                await gitRepository.WriteTextByRelativePathAsync(filename, expectedContent);

                var actualContent = await gitRepository.ReadTextByRelativePathAsync(filename);

                Assert.Equal(expectedContent, actualContent);
            }
            finally
            {
                TestDataHelper.DeleteDirectory(repositoryDirectory);
            }
        }
Exemple #2
0
        public async Task WriteTextByRelativePathAsync_PathDontExist_ShouldThrowException()
        {
            Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository gitRepository = GetTestRepository("ttd", "hvem-er-hvem", "testUser");

            var relativeFileUrl = "test_this/does/not/exits/deleteme.txt";

            Assert.False(gitRepository.FileExistsByRelativePath(relativeFileUrl));
            await Assert.ThrowsAsync <DirectoryNotFoundException>(async() => await gitRepository.WriteTextByRelativePathAsync(relativeFileUrl, "this file should not be here", false));
        }
Exemple #3
0
        public async Task WriteTextByRelativePathAsync_PathDontExist_ShouldCreateDirectory()
        {
            Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository gitRepository = GetTestRepository("ttd", "hvem-er-hvem", "testUser");

            var relativeFileUrl = "test_directory/should/be/created/deleteme.txt";

            Assert.False(gitRepository.FileExistsByRelativePath(relativeFileUrl));

            await gitRepository.WriteTextByRelativePathAsync(relativeFileUrl, "this file should be here", true);

            Assert.True(gitRepository.FileExistsByRelativePath(relativeFileUrl));

            TestDataHelper.DeleteDirectory(Path.Join(gitRepository.RepositoryDirectory, "test_directory"));
        }
Exemple #4
0
        public async Task WriteTextByRelativePathAsync_ValidText_ShouldReadBackEqual(string expectedContent)
        {
            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            string repositoryDirectory       = TestDataHelper.GetTestDataRepositoryDirectory("ttd", "hvem-er-hvem", "testUser");
            var    gitRepository             = new Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository(repositoriesRootDirectory, repositoryDirectory);

            var filename = $"{Guid.NewGuid()}.json";

            try
            {
                await gitRepository.WriteTextByRelativePathAsync(filename, expectedContent);

                var actualContent = await gitRepository.ReadTextByRelativePathAsync(filename);

                Assert.Equal(expectedContent, actualContent);
            }
            finally
            {
                gitRepository.DeleteFileByRelativePath(filename);
            }
        }
Exemple #5
0
        public async Task WriteTextByRelativePathAsync_PathDontExist_ShouldCreateDirectory()
        {
            var repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            var repositoryDirectory       = TestDataHelper.CreateEmptyRepositoryForTest("ttd", Guid.NewGuid().ToString(), "testUser");
            var gitRepository             = new Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository(repositoriesRootDirectory, repositoryDirectory);

            var relativeFileUrl = "test_directory/should/be/created/deleteme.txt";

            Assert.False(gitRepository.FileExistsByRelativePath(relativeFileUrl));

            try
            {
                await gitRepository.WriteTextByRelativePathAsync(relativeFileUrl, "this file should be here", true);

                Assert.True(gitRepository.FileExistsByRelativePath(relativeFileUrl));
            }
            finally
            {
                TestDataHelper.DeleteDirectory(repositoryDirectory);
            }
        }
Exemple #6
0
        public async Task WriteTextByRelativePathAsync_RelativePathOutsideParent_ShouldThrowArgumentException()
        {
            Altinn.Studio.Designer.Infrastructure.GitRepository.GitRepository gitRepository = GetTestRepository("ttd", "hvem-er-hvem", "testUser");

            await Assert.ThrowsAsync <ArgumentException>(async() => await gitRepository.WriteTextByRelativePathAsync(@"..\should.not.exist", "some content"));
        }