Beispiel #1
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;
                }
            }
        }
Beispiel #2
0
        public void DefaultBooleanValue_Add_NonMapCollection(bool value)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > collectionValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> collectionValue = new DefaultArrayMapValue <G>(collectionValues, valueProvider);

            DefaultBooleanValue <G>    sut    = new DefaultBooleanValue <G>(value);
            DefaultCollectionValue <G> result = (DefaultCollectionValue <G>)sut.Add(collectionValue, valueProvider);

            List <KeyValuePair <IValuable <G>, ValuePointer <G> > > entries = result.GetEntries();

            Assert.Equal(Enumerable.Range(0, 4), entries.Select(kv => kv.Key).Cast <IValue>().Select(v => Convert.ToInt32(v.GetData())));
            Assert.Equal(new IValuable <G>[] { sut }.Concat(collectionValues.Values.Select(v => v.Value)), entries.Select(kv => kv.Value).Select(vp => vp.Value));
            Assert.False(result.IsMap);
            Assert.Equal(Enumerable.Range(0, 4), entries.Select(e => e.Value).Cast <EntryValuePointer <G> >().Select(v => v.Index));
        }
Beispiel #3
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;
                }
            }
        }
Beispiel #4
0
        public void DefaultBooleanValue_Not(bool value)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultBooleanValue <G> sut    = new DefaultBooleanValue <G>(value);
            IValue <G, bool>        result = sut.Not(valueProvider) as IValue <G, bool>;

            Assert.Equal(!value, result.Data);
        }
Beispiel #5
0
        public void DefaultBooleanValue_Add_MapCollection(bool value)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > collectionValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(4), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
            };
            DefaultArrayMapValue <G> collectionValue = new DefaultArrayMapValue <G>(collectionValues, valueProvider);

            DefaultBooleanValue <G> sut = new DefaultBooleanValue <G>(value);

            Assert.Throws <EngineRuntimeException>(() =>
            {
                sut.Add(collectionValue, valueProvider);
            });
        }