Example #1
0
        public void ExtractVariableWorks(object value, object defaultValue, SupportedTypes supportedType, Units unit, object max = null, object min = null)
        {
            var variable = new Variable
            {
                Name    = "Test",
                Value   = value?.ToString(),
                Default = defaultValue?.ToString(),
                Max     = max?.ToString(),
                Min     = min?.ToString(),
                Type    = supportedType.GetStringValue(),
                Units   = unit.GetStringValue()
            };

            var errorCache = new ErrorCacheMock();
            var info       = VariableInfo.Extract(variable, "myPackage", errorCache);

            errorCache.ShouldHaveNoErrors();

            info.Ref.VariableName.Should().Be("Test");
            info.Ref.PackageId.Should().Be("myPackage");

            info.HasErrors.Should().BeFalse();
            info.Value.ShouldBeEquivalentTo(value);
            info.Default.ShouldBeEquivalentTo(defaultValue);
            info.Min.ShouldBeEquivalentTo(min);
            info.Max.ShouldBeEquivalentTo(max);
            info.SupportedType.Should().Be(supportedType);
            info.Units.Should().Be(unit);
        }
Example #2
0
        private static void AddVariable(NestedScope scope, string name, object value, SupportedTypes type = SupportedTypes.Integer)
        {
            var variable = new Variable
            {
                PackageId = scope.Name,
                Name      = name,
                Value     = value.ToString(),
                Type      = type.GetStringValue(),
                Units     = Units.None.GetStringValue()
            };

            scope.Store(variable);
        }