public void ExportWithIntCollectionPlusNullValueOfmappings_ShouldDiscoverAllmappings()
        {
            var data = MetadataMapper.Map <ClassWithIntCollectionWithNullValue>()["Data"] as object[];

            Assert.IsNotInstanceOf <int[]>(data);
            Assert.AreEqual(4, data.Length);
        }
        public void GetMappingView_IDictionaryAsTMappingViewTypeArgument_ShouldReturnMapping()
        {
            var Mapping = new PropertySet();

            var result = MetadataMapper.Map <IPropertySet>(Mapping);

            Assert.AreSame(Mapping, result);
        }
        public void TestMappingIntConversion()
        {
            var Mapping = new PropertySet();

            Mapping["Value"] = (Int64)45;

            MetadataMapper.Map <IHasInt32>(Mapping);
        }
        public void GetMappingView_IEnumerableAsTMappingViewTypeArgument_ShouldReturnMapping()
        {
            var Mapping = new PropertySet();

            var result = MetadataMapper.Map <IEnumerable <KeyValuePair <string, object> > >(Mapping);

            Assert.AreSame(Mapping, result);
        }
        public void ExportWithMultiplemappings_ExportTypes_WithNulls()
        {
            var view = MetadataMapper.Map <ItemWithTypeExports_WithNulls, ITypesmappingsView>();

            Assert.IsNotNull(view);

            Assert.IsNotNull(view.Type);
            Assert.AreEqual(3, view.Type.Length);
        }
        public void GetMappingView_IMappingViewWithTypeMismatchDefaultValue()
        {
            var exception = Assert.Throws <NotSupportedException>(() =>
            {
                MetadataMapper.Map <IMappingViewWithTypeMismatchDefaultValue>(new PropertySet());
            });

            Assert.IsInstanceOfType(typeof(TargetInvocationException), exception.InnerException);
        }
        public void ExportWithMultiplemappings_ExportStringsAsObjects_With_Null_ShouldDiscovermappingsAsStrings()
        {
            var view = MetadataMapper.Map <ExportWithMultiplemappings_ExportStringsAsObjects_WithNull, IObjectView_AsStrings>();

            Assert.IsNotNull(view);

            Assert.IsNotNull(view.Object);
            Assert.AreEqual(3, view.Object.Length);
        }
        public void ExportWithMultiplemappings_ExportIntsAsObjects_ShouldDiscovermappingsAsInts()
        {
            var view = MetadataMapper.Map <ExportWithMultiplemappings_ExportIntsAsObjects, IObjectView_AsInts>();

            Assert.IsNotNull(view);


            Assert.IsNotNull(view.Object);
            Assert.AreEqual(2, view.Object.Length);
        }
        public void GetMappingView_AbstractClassWithConstructor_ShouldThrowMemberAccessException()
        {
            var Mapping = new PropertySet();

            Mapping["Value"] = "value";

            Assert.Throws <MemberAccessException>(() =>
            {
                MetadataMapper.Map <AbstractClassWithConstructorMappingView>(Mapping);
            });
        }
        public void GetMappingView_AbstractClass_ShouldThrowMissingMethodException()
        {
            var Mapping = new PropertySet();

            Mapping["Value"] = "value";

            Assert.Throws <NotSupportedException>(() =>
            {
                MetadataMapper.Map <AbstractClassMappingView>(Mapping);
            });
        }
        public void SimplemappingsTestWithNullReferenceValue()
        {
            var view = MetadataMapper.Map <SimplemappingsExporterWithNullReferenceValue, ISimplemappingsView>();

            Assert.AreEqual(null, view.String);
            Assert.AreEqual(42, view.Int);
            Assert.AreEqual(42.0f, view.Float);
            Assert.AreEqual(SimpleEnum.First, view.Enum);
            Assert.AreEqual(typeof(string), view.Type);
            Assert.AreEqual(42, view.Object);
        }
        public void GetMappingView_PrivateInterfaceAsTMappingViewTypeArgument_ShouldhrowNotSupportedException()
        {
            var Mapping = new PropertySet();

            Mapping["CanActivate"] = true;

            Assert.Throws <NotSupportedException>(() =>
            {
                MetadataMapper.Map <IActivator>(Mapping);
            });
        }
        public void SimplemappingsTest()
        {
            var view = MetadataMapper.Map <SimplemappingsExporter, ISimplemappingsView>();

            Assert.AreEqual("42", view.String);
            Assert.AreEqual(42, view.Int);
            Assert.AreEqual(42.0f, view.Float);
            // Assert.AreEqual(null, view.Enum);
            Assert.AreEqual(typeof(string), view.Type);
            Assert.AreEqual(42, view.Object);
        }
        public void GetMappingView_InterfaceWithIndexer_ShouldThrowNotSupportedException()
        {
            var Mapping = new PropertySet();

            Mapping["Value"] = "value";

            Assert.Throws <NotSupportedException>(() =>
            {
                MetadataMapper.Map <IMappingViewWithIndexer>(Mapping);
            });
        }
        public void GetMappingView_InterfaceInheritance()
        {
            var Mapping = new PropertySet();

            Mapping["Value"]  = "value";
            Mapping["Value2"] = "value2";

            var view = MetadataMapper.Map <IMappingView3>(Mapping);

            Assert.AreEqual("value", view.Value);
            Assert.AreEqual("value2", view.Value2);
        }
        public void GetMappingView_CachesViewType()
        {
            var Mapping1 = new PropertySet();

            Mapping1["Value"] = "value1";
            var view1 = MetadataMapper.Map <IMappingView>(Mapping1);

            Assert.AreEqual("value1", view1.Value);

            var Mapping2 = new PropertySet();

            Mapping2["Value"] = "value2";
            var view2 = MetadataMapper.Map <IMappingView>(Mapping2);

            Assert.AreEqual("value2", view2.Value);

            Assert.AreEqual(view1.GetType(), view2.GetType());
        }
        public void ExportWithMultiplemappings_ExportStringsAndNulls_ThroughmappingsAttributes()
        {
            var view = MetadataMapper.Map <OrderedItemBeforesOnly, IOrdermappingsView>();

            Assert.IsNotNull(view);

            Assert.IsNotNull(view.Before);
            Assert.IsNotNull(view.After);

            Assert.AreEqual(2, view.Before.Length);
            Assert.AreEqual(2, view.After.Length);

            Assert.IsNotNull(view.Before[0]);
            Assert.IsNotNull(view.Before[1]);

            Assert.IsNull(view.After[0]);
            Assert.IsNull(view.After[1]);
        }
        public void GetMappingView_IMappingViewWithDefaultedInt()
        {
            var view = MetadataMapper.Map <IMappingViewWithDefaultedInt>(new PropertySet());

            Assert.AreEqual(120, view.MyInt);
        }
        public void GetMappingView_IMappingViewWithDefaultedInt64()
        {
            var view = MetadataMapper.Map <IMappingViewWithDefaultedInt64>(new PropertySet());

            Assert.AreEqual(Int64.MaxValue, view.MyInt64);
        }
        public void GetMappingView_IMappingViewWithDefaultedString()
        {
            var view = MetadataMapper.Map <IMappingViewWithDefaultedString>(new PropertySet());

            Assert.AreEqual("MyString", view.MyString);
        }
        public void ExportWithValidCollectionOfmappings_ShouldDiscoverAllmappings()
        {
            var data = MetadataMapper.Map <ClassWithLotsOfDifferentmappingsTypes>()["Data"] as object[];

            Assert.AreEqual(11, data.Length);
        }
        public void GetMappingView_DictionaryAsTMappingViewTypeArgument_ShouldNotThrow()
        {
            var Mapping = new PropertySet();

            MetadataMapper.Map <PropertySet>(Mapping);
        }
        public void GetMappingView_IMappingViewWithDefaultedBool()
        {
            var view = MetadataMapper.Map <IMappingViewWithDefaultedBool>(new PropertySet());

            Assert.AreEqual(true, view.MyBool);
        }