예제 #1
0
        public async Task CreateSchemaFromXsd_DatamodelsRepo_ShouldStoreModel()
        {
            // Arrange
            var org = "ttd";
            var sourceRepository = "empty-datamodels";
            var developer        = "testUser";
            var targetRepository = Guid.NewGuid().ToString();

            await TestDataHelper.CopyRepositoryForTest(org, sourceRepository, developer, targetRepository);

            try
            {
                var altinnGitRepositoryFactory         = new AltinnGitRepositoryFactory(TestDataHelper.GetTestDataRepositoriesRootDirectory());
                ISchemaModelService schemaModelService = new SchemaModelService(altinnGitRepositoryFactory, TestDataHelper.LogFactory, TestDataHelper.ServiceRepositorySettings);
                var xsdStream = TestDataHelper.LoadDataFromEmbeddedResource("Designer.Tests._TestData.Model.Xsd.Kursdomene_HvemErHvem_M_2021-04-08_5742_34627_SERES.xsd");
                xsdStream.Seek(0, System.IO.SeekOrigin.Begin);
                var schemaName        = "Kursdomene_HvemErHvem_M_2021-04-08_5742_34627_SERES";
                var fileName          = $"{schemaName}.xsd";
                var relativeDirectory = "App/models";
                var relativeFilePath  = $"{relativeDirectory}/{fileName}";

                // Act
                await schemaModelService.CreateSchemaFromXsd(org, targetRepository, developer, relativeFilePath, xsdStream);

                // Assert
                var altinnAppGitRepository = altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, targetRepository, developer);
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.schema.json").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.original.xsd").Should().BeTrue();
            }
            finally
            {
                TestDataHelper.DeleteAppRepository(org, targetRepository, developer);
            }
        }
예제 #2
0
        public async Task CreateSchemaFromXsdWithTexts_AppRepo_ShouldCreateTextResourceFiles()
        {
            // Arrange
            var org = "ttd";
            var sourceRepository = "empty-app";
            var developer        = "testUser";
            var targetRepository = Guid.NewGuid().ToString();

            await TestDataHelper.CopyRepositoryForTest(org, sourceRepository, developer, targetRepository);

            try
            {
                var altinnGitRepositoryFactory         = new AltinnGitRepositoryFactory(TestDataHelper.GetTestDataRepositoriesRootDirectory());
                ISchemaModelService schemaModelService = new SchemaModelService(altinnGitRepositoryFactory, TestDataHelper.LogFactory, TestDataHelper.ServiceRepositorySettings);
                var xsdStream = TestDataHelper.LoadDataFromEmbeddedResource("Designer.Tests._TestData.Model.Xsd.Skjema-1603-12392.xsd");
                xsdStream.Seek(0, System.IO.SeekOrigin.Begin);
                var schemaName        = "Skjema-1603-12392";
                var fileName          = $"{schemaName}.xsd";
                var relativeDirectory = "App/models";
                var relativeFilePath  = $"{relativeDirectory}/{fileName}";

                // Act
                await schemaModelService.CreateSchemaFromXsd(org, targetRepository, developer, relativeFilePath, xsdStream);

                // Assert
                var altinnAppGitRepository = altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, targetRepository, developer);
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.metadata.json").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.schema.json").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.original.xsd").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.cs").Should().BeTrue();

                var textResource = await altinnAppGitRepository.GetTextResources("nb");

                textResource.Language.Should().Be("nb");
                textResource.Resources.Should().HaveCount(9);
                textResource.Resources.First(r => r.Id == "27688.KontaktpersonEPostdatadef27688.Label").Value.Should().Be("E-post");
            }
            finally
            {
                TestDataHelper.DeleteAppRepository(org, targetRepository, developer);
            }
        }
예제 #3
0
        public async Task DeleteSchema_AppRepo_ShouldDelete()
        {
            // Arrange
            var org = "ttd";
            var sourceRepository = "hvem-er-hvem";
            var developer        = "testUser";
            var targetRepository = Guid.NewGuid().ToString();

            await TestDataHelper.CopyRepositoryForTest(org, sourceRepository, developer, targetRepository);

            try
            {
                var altinnGitRepositoryFactory = new AltinnGitRepositoryFactory(TestDataHelper.GetTestDataRepositoriesRootDirectory());

                ISchemaModelService schemaModelService = new SchemaModelService(altinnGitRepositoryFactory, TestDataHelper.LogFactory, TestDataHelper.ServiceRepositorySettings);
                var schemaFiles = schemaModelService.GetSchemaFiles(org, targetRepository, developer);
                schemaFiles.Should().HaveCount(7);

                var altinnAppGitRepository = altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, targetRepository, developer);
                var applicationMetadata    = await altinnAppGitRepository.GetApplicationMetadata();

                applicationMetadata.DataTypes.Should().HaveCount(2);

                // Act
                var schemaToDelete = schemaFiles.First(s => s.FileName == "Kursdomene_HvemErHvem_M_2021-04-08_5742_34627_SERES.schema.json");
                await schemaModelService.DeleteSchema(org, targetRepository, developer, schemaToDelete.RepositoryRelativeUrl);

                // Assert
                schemaFiles = schemaModelService.GetSchemaFiles(org, targetRepository, developer);
                schemaFiles.Should().HaveCount(6);
                applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata();

                applicationMetadata.DataTypes.Should().HaveCount(1);
            }
            finally
            {
                TestDataHelper.DeleteAppRepository(org, targetRepository, developer);
            }
        }
예제 #4
0
        public async Task UploadSchemaFromXsd_OED_ModelsCreated()
        {
            // Arrange
            JsonSchemaKeywords.RegisterXsdKeywords();

            var org = "ttd";
            var sourceRepository = "empty-app";
            var developer        = "testUser";
            var targetRepository = Guid.NewGuid().ToString();

            await TestDataHelper.CopyRepositoryForTest(org, sourceRepository, developer, targetRepository);

            try
            {
                var altinnGitRepositoryFactory         = new AltinnGitRepositoryFactory(TestDataHelper.GetTestDataRepositoriesRootDirectory());
                ISchemaModelService schemaModelService = new SchemaModelService(altinnGitRepositoryFactory, TestDataHelper.LogFactory, TestDataHelper.ServiceRepositorySettings);
                var xsdStream         = TestDataHelper.LoadDataFromEmbeddedResource("Designer.Tests._TestData.Model.Xsd.OED.xsd");
                var schemaName        = "OED_M";
                var fileName          = $"{schemaName}.xsd";
                var relativeDirectory = "App/models";
                var relativeFilePath  = $"{relativeDirectory}/{fileName}";

                // Act
                var jsonSchema = await schemaModelService.BuildSchemaFromXsd(org, targetRepository, developer, fileName, xsdStream);

                // Assert
                var altinnAppGitRepository = altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, targetRepository, developer);
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.metadata.json").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.schema.json").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.xsd").Should().BeTrue();
                altinnAppGitRepository.FileExistsByRelativePath($"{relativeDirectory}/{schemaName}.cs").Should().BeTrue();
            }
            finally
            {
                TestDataHelper.DeleteAppRepository(org, targetRepository, developer);
            }
        }