public void DefaultValueProvider_GetAsValue(object value)
        {
            DefaultValueProvider <G> sut = new DefaultValueProvider <G>();
            IValue <G> result            = sut.GetAsValue(value);

            switch (value)
            {
            case double _:
                Assert.IsAssignableFrom <IValue <G, double> >(result);
                break;

            case int _:
                Assert.IsAssignableFrom <IValue <G, int> >(result);
                break;

            case long _:
                Assert.IsAssignableFrom <IValue <G, long> >(result);
                break;

            case string _:
                Assert.IsAssignableFrom <IValue <G, string> >(result);
                break;

            case null:
                Assert.IsAssignableFrom <INullValue <G> >(result);
                break;
            }
        }
Exemple #2
0
        public void DefaultActionValue_Add(object otherVal, bool throwsException)
        {
            G groupState = Mock.Of <G>();
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultActionValue <G> sut      = new DefaultActionValue <G>(groupState, 10);
            IValuable <G>          newValue = null;
            Action action = () =>
            {
                newValue = sut.Add(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case null:
                    Assert.Equal(sut, newValue);
                    break;
                }
            }
        }
Exemple #3
0
        public void DefaultBooleanValue_Add(bool value, object otherVal, bool throwsException)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultBooleanValue <G> sut = new DefaultBooleanValue <G>(value);
            IValue <G> newValue         = null;
            Action     action           = () =>
            {
                newValue = (IValue <G>)sut.Add(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case string stringVal:
                    Assert.Equal(value.ToString().ToLower() + stringVal, newValue.GetData());
                    break;

                case null:
                    Assert.Equal(sut, newValue);
                    break;
                }
            }
        }
Exemple #4
0
        public void DefaultBooleanValue_IsNotEqualTo(bool value, object otherVal, bool throwsException)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultBooleanValue <G> sut = new DefaultBooleanValue <G>(value);
            IValue <G> newValue         = null;
            Action     action           = () =>
            {
                newValue = (IValue <G>)sut.IsNotEqualTo(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case bool boolVal:
                    Assert.Equal(value != boolVal, newValue.GetData());
                    break;
                }
            }
        }
Exemple #5
0
        public void DefaultActionValue_IsNotEqualTo(object otherVal)
        {
            G groupState = Mock.Of <G>();
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultActionValue <G> sut    = new DefaultActionValue <G>(groupState, 10);
            IValue <G, bool>       result = (IValue <G, bool>)sut.IsNotEqualTo(valueProvider.GetAsValue(otherVal), valueProvider);

            Assert.True(result.Data);
        }
        public void DefaultStringValue_Add(object otherVal, bool throwsException)
        {
            string value = "hello";
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultStringValue <G> sut      = new DefaultStringValue <G>(value);
            IValue <G>             newValue = null;
            Action action = () =>
            {
                newValue = (IValue <G>)sut.Add(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case double doubleVal:
                    Assert.Equal(value + doubleVal, newValue.GetData());
                    break;

                case int intVal:
                    Assert.Equal(value + intVal, newValue.GetData());
                    break;

                case long longVal:
                    Assert.Equal(value + longVal, newValue.GetData());
                    break;

                case string strVal:
                    Assert.Equal(value + strVal, newValue.GetData());
                    break;
                }
            }
        }
        public void DefaultStringValue_IsNotEqualTo(object otherVal, bool throwsException)
        {
            string value = "hello";
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultStringValue <G> sut      = new DefaultStringValue <G>(value);
            IValue <G>             newValue = null;
            Action action = () =>
            {
                newValue = (IValue <G>)sut.IsNotEqualTo(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case string strVal:
                    Assert.Equal(value != strVal, newValue.GetData());
                    break;

                default:
                    Assert.True((bool)newValue.GetData());
                    break;
                }
            }
        }
        public void DefaultStringValue_Minus(object otherVal, bool throwsException)
        {
            string value = "hello20true";
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultStringValue <G> sut      = new DefaultStringValue <G>(value);
            IValue <G>             newValue = null;
            Action action = () =>
            {
                newValue = (IValue <G>)sut.Minus(valueProvider.GetAsValue(otherVal), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case null:
                    Assert.Equal(sut, newValue);
                    break;

                default:
                    Assert.Equal(value.Replace(otherVal.ToString(), ""), newValue.GetData());
                    break;
                }
            }
        }
        public void DefaultValueProvider_GetAsValue_WithObject_Throws()
        {
            object data = new object();

            DefaultValueProvider <G> sut = new DefaultValueProvider <G>();
            EngineRuntimeException   ex  = Assert.Throws <EngineRuntimeException>(() => sut.GetAsValue(data));

            Assert.Equal("No implementation for externals", ex.Message);
        }