public void IsDerivedFrom_Returns_True_When_Derived_From_Another_Capability_Type()
        {
            // Arrange
            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };
            var baseCapabilityType = new ToscaCapabilityType();

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

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            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);

            List <ValidationResult> validationResults;

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

            // Act
            // Assert
            derivedCapabilityType.IsDerivedFrom("base").Should().BeTrue();
        }
        public void GetAllProperties_Description_Should_Not_Be_Overriden_When_Another_Capability_Type_Overrides_It()
        {
            // Arrange
            var simpleCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            simpleCapabilityType.Properties.Add("list", new ToscaProperty()
            {
                Type = "list", Default = new object[] {}
            });

            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            derivedCapabilityType.Properties.Add("description", new ToscaProperty
            {
                Type    = "string",
                Default = "derived description"
            });
            var baseCapabilityType = new ToscaCapabilityType();

            baseCapabilityType.Properties.Add("description", new ToscaProperty
            {
                Type    = "string",
                Default = "base description"
            });

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

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            serviceTemplate.CapabilityTypes.Add("simple", simpleCapabilityType);
            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);

            List <ValidationResult> validationResults;

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

            // Act
            var descriptionProperty = derivedCapabilityType.GetAllProperties()["description"];

            descriptionProperty = simpleCapabilityType.GetAllProperties()["description"];

            // Assert
            descriptionProperty.Default.Should().Be("base description");
        }
        public void GetAllProperties_Of_Root_Capability_Type_Is_Empty()
        {
            // Arrange
            var capabilityType = new ToscaCapabilityType();

            // Act
            var allProperties = capabilityType.GetAllProperties();

            // Assert
            allProperties.Should().BeEmpty();
        }
        public void GetAllProperties_Override_Base_Properties()
        {
            // Arrange
            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            derivedCapabilityType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Required    = false,
                Default     = "10MBps",
                Description = "derived description"
            });
            var baseCapabilityType = new ToscaCapabilityType();

            baseCapabilityType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Required    = true,
                Default     = "",
                Description = "base description"
            });

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

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            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);

            List <ValidationResult> validationResults;

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

            // Act
            // Assert
            var speedProperty = derivedCapabilityType.GetAllProperties()["speed"];

            speedProperty.Type.Should().Be("string");
            speedProperty.Required.Should().BeFalse();
            speedProperty.Default.Should().Be("10MBps");
            speedProperty.Description.Should().Be("derived description");
        }
        public void CapabilityTypeNotFoundException_Should_Be_Thrown_When_DerivedFrom_Capability_Does_Not_Exist()
        {
            var toscaCapabilityType = new ToscaCapabilityType();

            toscaCapabilityType.SetCloudServiceArchive(new ToscaCloudServiceArchive(new ToscaMetadata()));
            toscaCapabilityType.DerivedFrom = "base";

            // Act
            ToscaCapabilityType baseCapabilityType;
            Action action = () => baseCapabilityType = toscaCapabilityType.GetDerivedFromEntity();

            // Assert
            action.ShouldThrow <ToscaCapabilityTypeNotFoundException>().WithMessage("Capability type 'base' not found");
        }
        public void Base_Property_Of_Capability_Type_Is_Capability_Of_Derived_From()
        {
            // Arrange
            var serviceTemplate     = new ToscaServiceTemplate();
            var basicCapabilityType = new ToscaCapabilityType();

            basicCapabilityType.Properties.Add("username", new ToscaProperty {
                Type = "string"
            });
            serviceTemplate.CapabilityTypes.Add("basic", basicCapabilityType);
            serviceTemplate.CapabilityTypes.Add("connectable", new ToscaCapabilityType
            {
                DerivedFrom = "basic"
            });

            // Act
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata());

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

            // Assert
            cloudServiceArchive.CapabilityTypes["connectable"].GetDerivedFromEntity().Properties.Should().ContainKey("username");
        }
        public void GetAllProperties_Of_Capability_Type_Deriving_From_A_None_Existing_Capability_Type_Should_Throw_An_Exception()
        {
            // Arrange
            var capabilityType = new ToscaCapabilityType {
                DerivedFrom = "NOT_EXIST"
            };

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

            serviceTemplate.CapabilityTypes.Add("my_cap_type", capabilityType);
            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);

            // Act
            Action action = () => capabilityType.GetAllProperties();

            // Assert
            action.ShouldThrow <ToscaCapabilityTypeNotFoundException>().WithMessage("Capability type 'NOT_EXIST' not found");
        }
        public void ValidSourceTypes_Should_Be_Empty_Upon_Initialization()
        {
            var toscaCapabilityType = new ToscaCapabilityType();

            toscaCapabilityType.ValidSourceTypes.Should().BeEmpty();
        }
        public void Properties_Should_Be_Empty_Upon_Initialization()
        {
            var toscaCapabilityType = new ToscaCapabilityType();

            toscaCapabilityType.Properties.Should().BeEmpty();
        }
        public void Attributes_Should_Be_Empty_Upon_Initialization()
        {
            var toscaCapabilityType = new ToscaCapabilityType();

            toscaCapabilityType.Attributes.Should().BeEmpty();
        }