public void DefaultStringValue_Add_NonMapCollection() { string value = "hello"; 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); DefaultStringValue <G> sut = new DefaultStringValue <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)); }
public void DefaultGroupValue_Get_NotExisting() { string pointerName = "grouppointername"; DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); DeclaredValuePointer <G> groupPointer = new DeclaredValuePointer <G>("group", valueProvider.Null) { Identifier = pointerName }; List <DeclaredValuePointer <G> > groupPointers = new List <DeclaredValuePointer <G> >() { new DeclaredValuePointer <G>("group"), groupPointer, new DeclaredValuePointer <G>("group") }; Dictionary <string, int> pointerMap = new Dictionary <string, int> { { pointerName, 1 } }; G groupState = Mock.Of <G>(m => m.GroupPointers == groupPointers && m.PointerMap == pointerMap); DefaultStringValue <G> key = new DefaultStringValue <G>("otherpointer"); DefaultGroupValue <G> sut = new DefaultGroupValue <G>(groupState); EngineRuntimeException ex = Assert.Throws <EngineRuntimeException>(() => { sut.Get(key, true, valueProvider); }); Assert.Equal("Cannot create group pointer using accessor", ex.Message); }
public void DefaultStringValue_Add_MapCollection() { string value = "hello"; 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); DefaultStringValue <G> sut = new DefaultStringValue <G>(value); Assert.Throws <EngineRuntimeException>(() => { sut.Add(collectionValue, valueProvider); }); }
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 DefaultGroupValue_Get_Existing() { string pointerName = "grouppointername"; DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); DeclaredValuePointer <G> groupPointer = new DeclaredValuePointer <G>("group", valueProvider.Null) { Identifier = pointerName }; List <DeclaredValuePointer <G> > groupPointers = new List <DeclaredValuePointer <G> >() { new DeclaredValuePointer <G>("group"), groupPointer, new DeclaredValuePointer <G>("group") }; Dictionary <string, int> pointerMap = new Dictionary <string, int> { { pointerName, 1 } }; G groupState = Mock.Of <G>(m => m.GroupPointers == groupPointers && m.PointerMap == pointerMap); DefaultStringValue <G> key = new DefaultStringValue <G>(pointerName); DefaultGroupValue <G> sut = new DefaultGroupValue <G>(groupState); ValuePointer <G> result = sut.Get(key, false, valueProvider) as ValuePointer <G>; Assert.Equal(groupPointer, result); }
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; } } }