Beispiel #1
0
            public void Non_generic_DbMemberEntry_for_reference_can_be_converted_to_generic_version()
            {
                var memberEntry = new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Member("Reference");

                var generic = memberEntry.Cast <FakeWithProps, FakeEntity>();

                Assert.IsType <DbReferenceEntry <FakeWithProps, FakeEntity> >(generic);
                Assert.Same(memberEntry.InternalMemberEntry, generic.InternalMemberEntry);
            }
            public void Non_generic_DbCollectionEntry_for_collection_can_be_converted_to_generic_version_of_base_property_type()
            {
                var memberEntry =
                    new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Collection("Collection");

                var generic = memberEntry.Cast <FakeWithProps, object>();

                Assert.IsType <DbCollectionEntry <FakeWithProps, object> >(generic);
                Assert.Same(memberEntry.InternalMemberEntry, generic.InternalMemberEntry);
            }
Beispiel #3
0
            public void Non_generic_DbMemberEntry_for_reference_cannot_be_converted_to_generic_version_of_derived_property_type()
            {
                var memberEntry = new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Member("Reference");

                Assert.Equal(
                    Strings.DbMember_BadTypeForCast(
                        typeof(DbMemberEntry).Name, typeof(FakeWithProps).Name, typeof(FakeDerivedEntity).Name, typeof(FakeWithProps).Name,
                        typeof(FakeEntity).Name),
                    Assert.Throws <InvalidCastException>(() => memberEntry.Cast <FakeWithProps, FakeDerivedEntity>()).Message);
            }
            public void Non_generic_DbPropertyEntry_for_property_can_be_converted_to_generic_version_of_base_entity_type()
            {
                var memberEntry =
                    new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Property("ValueTypeProp");

                var generic = memberEntry.Cast <object, int>();

                Assert.IsType <DbPropertyEntry <object, int> >(generic);
                Assert.Same(memberEntry.InternalMemberEntry, generic.InternalMemberEntry);
            }
            public void Non_generic_DbMemberEntry_for_collection_cannot_be_converted_to_generic_version_of_base_property_type()
            {
                var memberEntry = new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Member(
                    "Collection");

                // This cast fails because an ICollection<FakeEntity> is not an IColletion<object>.
                Assert.Equal(
                    Strings.DbMember_BadTypeForCast(
                        typeof(DbMemberEntry).Name, typeof(FakeWithProps).Name, typeof(ICollection <object>).Name, typeof(FakeWithProps).Name,
                        typeof(ICollection <FakeEntity>).Name),
                    Assert.Throws <InvalidCastException>(() => memberEntry.Cast <FakeWithProps, ICollection <object> >()).Message);
            }
            public void Non_generic_DbPropertyEntry_for_property_cannot_be_converted_to_generic_version_of_bad_property_type()
            {
                var memberEntry =
                    new DbEntityEntry <FakeWithProps>(FakeWithProps.CreateMockInternalEntityEntry().Object).Property("ValueTypeProp");

                Assert.Equal(
                    Strings.DbMember_BadTypeForCast(
                        typeof(DbPropertyEntry).Name, typeof(FakeWithProps).Name, typeof(short).Name, typeof(FakeWithProps).Name,
                        typeof(int).Name), Assert.Throws <InvalidCastException>(() => memberEntry.Cast <FakeWithProps, short>()).Message);
            }