Example #1
0
        public void GetAllRequirements_Shall_Not_Fail_When_Derived_And_Base_Node_Type_Have_Requirements_With_Same_Key()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

            switchNodeType.AddRequirement("internet", new ToscaRequirement {
                Capability = "wi-fi"
            });
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            nxosNodeType.AddRequirement("internet", new ToscaRequirement {
                Capability = "ssd"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType);
            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults).Should()
            .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var allRequirements = nxosNodeType.GetAllRequirements();

            // Assert
            allRequirements.Should().ContainSingle(r => r.Capability == "ssd");
            allRequirements.Should().ContainSingle(r => r.Capability == "wi-fi");
        }