示例#1
0
        public async Task return_converted_value_as_ttype()
        {
            var runtimeParamterAccessor = new StoreRuntimeParameterAccesorBuilder()
                                          .WithParameters(new Dictionary <string, ActivatorParameter>()
            {
                { "double", new ActivatorParameter()
                  {
                      Name = "double", Value = "22.2", ActivatorType = "", FeatureName = ""
                  } },
                { "int", new ActivatorParameter()
                  {
                      Name = "int", Value = "222", ActivatorType = "", FeatureName = ""
                  } },
                { "decimal", new ActivatorParameter()
                  {
                      Name = "decimal", Value = "22.2", ActivatorType = "", FeatureName = ""
                  } },
                { "string", new ActivatorParameter()
                  {
                      Name = "string", Value = "some", ActivatorType = "", FeatureName = ""
                  } },
                { "long", new ActivatorParameter()
                  {
                      Name = "long", Value = "2233332", ActivatorType = "", FeatureName = ""
                  } },
            }).Build();

            (await runtimeParamterAccessor.GetValueAsync <double>("", new ActivatorParameterDescriptor()
            {
                Name = "double"
            }))
            .Should().Be(22.2d);

            (await runtimeParamterAccessor.GetValueAsync <int>("", new ActivatorParameterDescriptor()
            {
                Name = "int"
            }))
            .Should().Be(222);

            (await runtimeParamterAccessor.GetValueAsync <decimal>("", new ActivatorParameterDescriptor()
            {
                Name = "decimal"
            }))
            .Should().Be(22.2M);

            (await runtimeParamterAccessor.GetValueAsync <string>("", new ActivatorParameterDescriptor()
            {
                Name = "string"
            }))
            .Should().Be("some");

            (await runtimeParamterAccessor.GetValueAsync <long>("", new ActivatorParameterDescriptor()
            {
                Name = "long"
            }))
            .Should().Be(2233332);
        }
示例#2
0
        public async Task get_default_configured_value_if_conversion_fail()
        {
            var runtimeParamterAccessor = new StoreRuntimeParameterAccesorBuilder()
                                          .Build();

            (await runtimeParamterAccessor.GetValueAsync <double>("", new ActivatorParameterDescriptor()
            {
                Name = "non_valid_double"
            }))
            .Should().Be(default(Double));
        }