public void ArchiveEntryDictionary_Should_Be_Agnostic_To_Directory_Delimiter() { var fileSystem = new MockFileSystem(); fileSystem.CreateArchive("tosca.zip", new[] { new FileContent(@"location/file.yaml", "YAML") }); var archiveEntriesDictionary = new ZipArchive(fileSystem.File.Open("tosca.zip", FileMode.Open)).GetArchiveEntriesDictionary(); Action action = () => { var zipArchiveEntry = archiveEntriesDictionary[@"location\file.yaml"]; zipArchiveEntry.Should().NotBeNull(); }; action.ShouldNotThrow(); }
public void aaa() { var mockFileSystem = new MockFileSystem(); DependencyResolver.Current.Replace <IFileSystem>(mockFileSystem); mockFileSystem.AddFile(Path.Combine(Environment.CurrentDirectory, "standard.yaml"), new MockFileData(@" tosca_definitions_version: tosca_simple_yaml_1_0")); var archiveContent = new[] { new FileContent("TOSCA.meta", @" TOSCA-Meta-File-Version: 1.0 CSAR-Version: 1.1 Created-By: OASIS TOSCA TC Entry-Definitions: definition.yaml "), new FileContent("definition.yaml", @" tosca_definitions_version: tosca_simple_yaml_1_0 imports: - standard: standard.yaml node_types: vendor.switch.NXOS: description: Description of NXOS switch derived_from: tosca.nodes.Root properties: device_owner: type: string ") }; mockFileSystem.CreateArchive("tosca.zip", archiveContent); // Act var toscaCloudServiceArchive = ToscaCloudServiceArchive.Load("tosca.zip", Environment.CurrentDirectory); // Assert toscaCloudServiceArchive.NodeTypes.Should().ContainSingle(a => a.Key == "vendor.switch.NXOS"); }
public void AddToscaServiceTemplate_Should_Throw_ArtifactNotFoundException_When_File_Missing_In_Archive() { // Act var fileSystem = new MockFileSystem(); fileSystem.CreateArchive("tosca.zip", new FileContent[0]); var toscaNodeType = new ToscaNodeType(); toscaNodeType.Artifacts.Add("icon", new ToscaArtifact { File = "device.png", Type = "image" }); var toscaServiceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; toscaServiceTemplate.NodeTypes.Add("device", toscaNodeType); var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { EntryDefinitions = "tosca.yaml", CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), ToscaMetaFileVersion = new Version(1, 1) }); // Act toscaCloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", toscaServiceTemplate); List <ValidationResult> validationResults; toscaCloudServiceArchive.TryValidate(out validationResults); // Assert validationResults.Select(a => a.ErrorMessage).ToArray() .ShouldAllBeEquivalentTo(new[] { "Artifact 'device.png' not found in Cloud Service Archive." }); //action.ShouldThrow<ToscaArtifactNotFoundException>() // .WithMessage("Artifact 'device.png' not found in Cloud Service Archive."); }
public void Archive_With_Two_Templates_One_Of_Them_Resides_In_Alternative_Path_Loaded() { // Arrange var toscaMetaContent = @" TOSCA-Meta-File-Version: 1.0 CSAR-Version: 1.1 Created-By: OASIS TOSCA TC Entry-Definitions: definitions\tosca_elk.yaml"; var toscaSimpleProfileContent = @" tosca_definitions_version: tosca_simple_yaml_1_0 imports: - base: base.yaml node_types: example.TransactionSubsystem: derived_from: tosca.base properties: num_cpus: type: integer"; var fileContents = new List <FileContent> { new FileContent("TOSCA.meta", toscaMetaContent), new FileContent(@"definitions\tosca_elk.yaml", toscaSimpleProfileContent) }; fileSystem.CreateArchive("tosca.zip", fileContents); fileSystem.AddFile( @"c:\alternative\base.yaml", new MockFileData( @"tosca_definitions_version: tosca_simple_yaml_1_0 node_types: tosca.base: properties: storage: type: string")); // Act var toscaCloudServiceArchive = toscaCloudServiceArchiveLoader.Load("tosca.zip", @"c:\alternative\"); // Assert toscaCloudServiceArchive.ToscaServiceTemplates.Should().HaveCount(2); toscaCloudServiceArchive.NodeTypes.Should().HaveCount(5); toscaCloudServiceArchive.NodeTypes.Should().ContainSingle(_ => _.Key == "tosca.base"); toscaCloudServiceArchive.NodeTypes.Should().ContainSingle(_ => _.Key == "example.TransactionSubsystem"); toscaCloudServiceArchive.NodeTypes.Should().ContainSingle(_ => _.Key == "tosca.nodes.Root"); var toscaNodeTypes = toscaCloudServiceArchive.ToscaServiceTemplates[@"definitions\tosca_elk.yaml"].NodeTypes; toscaNodeTypes.Should().HaveCount(1); toscaNodeTypes["example.TransactionSubsystem"].Properties["num_cpus"].Type.Should().Be("integer"); }