Exemplo n.º 1
0
        public void ShouldThrowExceptionIfDestinationPropertyCannotBeWritten()
        {
            ValueInjector.UseValueObtainer(_remoteValueObtainer);
            var testData = new ReadonlyDestinationPropertyTestData();

            Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 2
0
        public void ShouldThrowExceptionIfSourcePropertyCannotBeRead()
        {
            var testData = new UnreadableSourcePropertyTestData {
                ValueKey = 1
            };

            Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 3
0
        public void ShouldThrowExceptionIfNoValueObtainerFoundForType()
        {
            ValueInjector.Clear();
            var testData = new TestData {
                ValueKey = 1
            };

            Assert.Throws <NotSupportedException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 4
0
        public void ShouldThrowExceptionIfValueObtainerReturnsNull()
        {
            ValueInjector.UseValueObtainer(new NullReturningObtainer());

            var testData = new TestData {
                ValueKey = 1
            };

            Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 5
0
        public void ShouldThrowExceptionIfKeyPropertyIsNull()
        {
            ValueInjector.UseValueObtainer(_remoteValueObtainer);
            var testData = new TestData
            {
                ValueKey = null
            };

            Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 6
0
        public void ShouldInjectWholeSourceInstance()
        {
            ValueInjector.UseValueObtainer(_remoteValueObtainer);
            var testData = new ReferenceObjectInjectionTestData {
                ValueKey = 1
            };

            ValueInjector.InjectValues(testData);

            Assert.NotNull(testData.RemoteTestData);
        }
Exemplo n.º 7
0
        public void ShouldNotInjectValuesIfChildEnumerableIsNull()
        {
            ValueInjector.UseValueObtainer(_remoteValueObtainer);
            var testData = new EnumerableChildPropertyTestData
            {
                TestDatas = null
            };

            ValueInjector.InjectValues(testData);

            Assert.Null(testData.TestDatas);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
            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);
            }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
            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);
            }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
 public void ShouldHandleNullValues()
 {
     ValueInjector.InjectValues(null);
 }
Exemplo n.º 17
0
        public void ShouldNotTouchPropertiesIfNoInjectionIntended()
        {
            var testData = new TestDataWithoutInjection();

            ValueInjector.InjectValues(testData);
        }
Exemplo n.º 18
0
 public void Dispose()
 {
     ValueInjector.Clear();
 }
Exemplo n.º 19
0
        public void ShouldThrowExceptionIfSourcePropertyNotFound()
        {
            var testData = new WrongSourcePropertyTestData();

            Assert.Throws <InvalidOperationException>(() => ValueInjector.InjectValues(testData));
        }
Exemplo n.º 20
0
        public void ShouldNotAccessGetterOfEnumerable()
        {
            var testData = new TestDataWithExceptionThrowingEnumerableGetter();

            ValueInjector.InjectValues(testData);
        }
Exemplo n.º 21
0
        public void ShouldNotAccessGetterOfIrrelevantReferencePropertyType()
        {
            var testData = new TestDataWithExceptionThrowingGetter();

            ValueInjector.InjectValues(testData);
        }
Exemplo n.º 22
0
        public void ShouldIgnoreEnumerableGenericTypesLikeString()
        {
            var stringEnumerable = new StringEnumerableChildPropertyTestData();

            ValueInjector.InjectValues(stringEnumerable);
        }