public void ShouldThrowExceptionIfDestinationPropertyCannotBeWritten() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new ReadonlyDestinationPropertyTestData(); Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldThrowExceptionIfSourcePropertyCannotBeRead() { var testData = new UnreadableSourcePropertyTestData { ValueKey = 1 }; Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldThrowExceptionIfNoValueObtainerFoundForType() { ValueInjector.Clear(); var testData = new TestData { ValueKey = 1 }; Assert.Throws <NotSupportedException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldThrowExceptionIfValueObtainerReturnsNull() { ValueInjector.UseValueObtainer(new NullReturningObtainer()); var testData = new TestData { ValueKey = 1 }; Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldThrowExceptionIfKeyPropertyIsNull() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new TestData { ValueKey = null }; Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldInjectWholeSourceInstance() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new ReferenceObjectInjectionTestData { ValueKey = 1 }; ValueInjector.InjectValues(testData); Assert.NotNull(testData.RemoteTestData); }
public void ShouldNotInjectValuesIfChildEnumerableIsNull() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new EnumerableChildPropertyTestData { TestDatas = null }; ValueInjector.InjectValues(testData); Assert.Null(testData.TestDatas); }
public void ShouldHandleRecursiveTypes() { ValueInjectionMetadataBuilder.ConfigureReplacement <RecursiveTestData>(f => f.Of(v => v.RemoteValue).With <RemoteTestData>().Property(t => t.RemoteValue).FromKey(k => k.RemoteValueKey)); ValueInjector.UseValueObtainer(_remoteValueObtainer); var leftData = new RecursiveTestData(); var rightData = new RecursiveTestData(); leftData.TestData = rightData; rightData.TestData = leftData; ValueInjector.InjectValues(leftData); }
public void ShouldInjectInheritedProperties() { ValueInjectionMetadataBuilder.ConfigureReplacement <IHasRemoteTestData>(f => f.Of(p => p.RemoteTestData) .With <RemoteTestData>() .FromKey(td => td.ValueKey)); ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new InterfaceImplementingTestData { ValueKey = 1 }; ValueInjector.InjectValues(testData); Assert.NotNull(testData.RemoteTestData); }
public void ShouldNotCacheObtainedValuesForDifferentKeys() { var valueObtainer = new CountingValueObtainer(); ValueInjector.UseValueObtainer(valueObtainer); var testData1 = new TestData { ValueKey = 1 }; var testData2 = new TestData { ValueKey = 2 }; ValueInjector.InjectValues(testData1); ValueInjector.InjectValues(testData2); Assert.Equal(2, valueObtainer.ObtainerCallCounter); }
public EntitySliceConfiguration GetEntities(SliceEntityOutput output) { RestrictedArray <Entity> writeArray = new RestrictedArray <Entity>(mRegistry.Capacity); ValueInjector <Entity> injector = new ValueInjector <Entity>(mRegistry, writeArray); mLooseInjectors.Add(injector); //InjectExistingValue is impossible to use in this context. An entity would never be replaced, without being destroyed and then created //Set the write array to be accessed by the component output passed Type outputType = typeof(SliceEntityOutput); FieldInfo arrayField = outputType.GetField("mArray", BindingFlags.NonPublic | BindingFlags.Instance); arrayField.SetValue(output, writeArray); return(this); }
public void ShouldInjectRemoteValueEnumerable() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var injected = new List <TestData> { new TestData { ValueKey = 1 } }.ToValueInjection(); foreach (var element in injected) { Assert.NotNull(element); Assert.Equal(element.ValueKey.ToString(), element.Value); } }
public void ShouldHandleReferenceTypes() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var injected = new List <ReferenceTestData> { new ReferenceTestData { ReferencedData = new TestData { ValueKey = 1 } } }.ToValueInjection(); foreach (var element in injected) { Assert.NotNull(element); Assert.Equal(element.ReferencedData.ValueKey.ToString(), element.ReferencedData.Value); } }
public EntitySliceConfiguration Require <TComponent>(SliceRequirementOutput <TComponent> targetOutput) where TComponent : struct { Debug.Assert(targetOutput != null, "Target output cannot be null before calling this method!"); ComponentSet <TComponent> componentSet = mRegistry.GetComponentSet <TComponent>(); RestrictedArray <TComponent> writeArray = new RestrictedArray <TComponent>(mRegistry.Capacity); ValueInjector <TComponent> injector = new ValueInjector <TComponent>(componentSet, writeArray); componentSet.ValueModified += injector.InjectExistingValue; Tuple <IPublishingIndexSet, ValueInjectorBase> matchPair = new Tuple <IPublishingIndexSet, ValueInjectorBase>(componentSet, injector); mMatchedInjectorRequirements.Add(matchPair); //Set the write array to be accessed by the component output passed Type outputType = typeof(SliceRequirementOutput <TComponent>); FieldInfo arrayField = outputType.GetField("mArray", BindingFlags.NonPublic | BindingFlags.Instance); arrayField.SetValue(targetOutput, writeArray); return(this); }
public void ShouldInjectValuesInChildEnumerable() { ValueInjector.UseValueObtainer(_remoteValueObtainer); var testData = new EnumerableChildPropertyTestData { TestDatas = new List <TestData> { new TestData { ValueKey = 1 }, new TestData { ValueKey = 2 } } }; ValueInjector.InjectValues(testData); foreach (var element in testData.TestDatas) { Assert.NotNull(element.Value); Assert.Equal(element.ValueKey.ToString(), element.Value); } }
public void ShouldHandleNullValues() { ValueInjector.InjectValues(null); }
public void ShouldNotTouchPropertiesIfNoInjectionIntended() { var testData = new TestDataWithoutInjection(); ValueInjector.InjectValues(testData); }
public void Dispose() { ValueInjector.Clear(); }
public void ShouldThrowExceptionIfSourcePropertyNotFound() { var testData = new WrongSourcePropertyTestData(); Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData)); }
public void ShouldNotAccessGetterOfEnumerable() { var testData = new TestDataWithExceptionThrowingEnumerableGetter(); ValueInjector.InjectValues(testData); }
public void ShouldNotAccessGetterOfIrrelevantReferencePropertyType() { var testData = new TestDataWithExceptionThrowingGetter(); ValueInjector.InjectValues(testData); }
public void ShouldIgnoreEnumerableGenericTypesLikeString() { var stringEnumerable = new StringEnumerableChildPropertyTestData(); ValueInjector.InjectValues(stringEnumerable); }