public void It_Should_Be_Possible_To_Save_And_Load_Cloud_Service_Archive_With_Artifacts() { var toscaMetadata = new ToscaMetadata { CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 0) }; var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata); cloudServiceArchive.AddArtifact("readme.txt", "readme content".ToByteArray(Encoding.ASCII)); var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; var nodeType = new ToscaNodeType(); nodeType.Artifacts.Add("readme", new ToscaArtifact { Type = "tosca.artifacts.File", File = "readme.txt" }); serviceTemplate.NodeTypes.Add("some_node", nodeType); cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate); List <ValidationResult> results; cloudServiceArchive.TryValidate(out results) .Should() .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage))); using (var memoryStream = new MemoryStream()) { cloudServiceArchive.Save(memoryStream); var serviceArchive = ToscaCloudServiceArchive.Load(memoryStream); // Assert serviceArchive.CreatedBy.Should().Be("Anonymous"); serviceArchive.GetArtifactBytes("readme.txt") .Should() .BeEquivalentTo("readme content".ToByteArray(Encoding.ASCII)); } }
public void GetArtifactBytes_Should_Return_Empty_Array_When_File_Is_Empty() { // Arrange var toscaMetadata = new ToscaMetadata { CreatedBy = "Devil", CsarVersion = new Version(1, 1), ToscaMetaFileVersion = new Version(1, 0), EntryDefinitions = "tosca.yaml" }; var toscaCloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata); // Act toscaCloudServiceArchive.AddArtifact("some_icon.png", "IMAGE".ToByteArray(Encoding.ASCII)); // Assert toscaCloudServiceArchive.GetArtifactBytes("some_icon.png") .Should() .BeEquivalentTo(new byte[] { 73, 77, 65, 71, 69 }); }