Ejemplo n.º 1
0
        public void DynamicMapper_SimpleObject_RequestInternalProperties_ShouldFail(
            [Values(typeof(DynamicObjectMapperIL <TestObject.SimpleObject>), typeof(DynamicObjectMapper <TestObject.SimpleObject>))] Type mapper)
        {
            var constructor    = mapper.GetConstructor(Type.EmptyTypes);
            var mapperInstance = constructor.Invoke(null) as IDynamicObjectMapper <TestObject.SimpleObject>;
            var mappedObject   = TestObject.CreateTestObject <TestObject.SimpleObject>();

            Should.Throw <ArgumentOutOfRangeException>(() => mapperInstance.Map(mappedObject, new [] { "internalProperty" }));
        }
Ejemplo n.º 2
0
        public void DynamicMapper_NoPropertiesRequested_ReturnsEmptyObject(
            [Values(typeof(DynamicObjectMapperIL <TestObject.ComplexObject>), typeof(DynamicObjectMapper <TestObject.ComplexObject>))] Type mapper)
        {
            var constructor    = mapper.GetConstructor(Type.EmptyTypes);
            var mapperInstance = constructor.Invoke(null) as IDynamicObjectMapper <TestObject.ComplexObject>;
            var mappedObject   = TestObject.CreateTestObject <TestObject.ComplexObject>();
            var result         = mapperInstance.Map(mappedObject);

            result.Keys.Count.ShouldBe(0);
        }
Ejemplo n.º 3
0
        public void DynamicMapper_SimpleObject_RequestDottedProperty_ReturnsProperty(
            [Values(typeof(DynamicObjectMapperIL <TestObject.ComplexObject>), typeof(DynamicObjectMapper <TestObject.ComplexObject>))] Type mapper)
        {
            var          constructor           = mapper.GetConstructor(Type.EmptyTypes);
            var          mapperInstance        = constructor.Invoke(null) as IDynamicObjectMapper <TestObject.ComplexObject>;
            const string RequestedPropertyName = "OtherObjectProperty.StringProperty";
            const string ExpectedPropertyValue = "Test";
            var          mappedObject          = TestObject.CreateTestObject <TestObject.ComplexObject>(c =>
                                                                                                        c.OtherObjectProperty = new TestObject.SimpleObject()
            {
                StringProperty = ExpectedPropertyValue
            });
            var result = mapperInstance.Map(mappedObject, RequestedPropertyName.AlternateCasing());

            result.Keys.Count.ShouldBe(1);
            this.EnsurePropertyIsReturned((object)result, RequestedPropertyName, ExpectedPropertyValue);
        }
Ejemplo n.º 4
0
        public void DynamicMapper_SimpleObject_RequestAllPropertiesDifferentCasing_ReturnsAllProperties(
            [Values(typeof(DynamicObjectMapperIL <TestObject.ComplexObject>), typeof(DynamicObjectMapper <TestObject.ComplexObject>))] Type mapper)
        {
            var constructor           = mapper.GetConstructor(Type.EmptyTypes);
            var mapperInstance        = constructor.Invoke(null) as IDynamicObjectMapper <TestObject.ComplexObject>;
            var mappedObject          = TestObject.CreateTestObject <TestObject.ComplexObject>();
            var publicPropertiesNames =
                typeof(TestObject.ComplexObject)
                .GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance)
                .Select(p => p.Name.AlternateCasing()).ToArray();
            var result      = mapperInstance.Map(mappedObject, publicPropertiesNames);
            var combinedSet = result.Keys.Union(publicPropertiesNames, StringComparer.InvariantCultureIgnoreCase).ToArray();

            // Unioning the result set with the requested set shouldn't result in extra elements
            combinedSet.Length.ShouldBe(publicPropertiesNames.Length);

            // We shouldn't have any elements in the requested set missing from the results
            combinedSet.Except(result.Keys, StringComparer.InvariantCultureIgnoreCase).Count().ShouldBe(0);
        }