示例#1
0
        public void Proxy_services_must_be_available()
        {
            var withoutProxies = new ServiceCollection()
                                 .AddEntityFrameworkInMemoryDatabase()
                                 .BuildServiceProvider();

            using (var context = new NeweyContext(withoutProxies, nameof(Proxy_services_must_be_available), false))
            {
                context.Add(new March82GGtp());
                context.SaveChanges();
            }

            using (var context = new NeweyContext(withoutProxies, nameof(Proxy_services_must_be_available), false))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType());
            }

            using (var context = new NeweyContext(nameof(Proxy_services_must_be_available)))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType().BaseType);
            }

            using (var context = new NeweyContext(withoutProxies, nameof(Proxy_services_must_be_available)))
            {
                Assert.Equal(
                    ProxiesStrings.ProxyServicesMissing,
                    Assert.Throws <InvalidOperationException>(
                        () => context.Model).Message);
            }
        }
示例#2
0
 public void CreateProxy_uses_parameterless_constructor()
 {
     using (var context = new NeweyContext())
     {
         Assert.Same(typeof(March82GGtp), context.CreateProxy <March82GGtp>().GetType().BaseType);
     }
 }
示例#3
0
        public void Proxies_only_created_if_Use_called()
        {
            using (var context = new NeweyContext(nameof(Proxies_only_created_if_Use_called), false, false))
            {
                context.Add(new March82GGtp());
                context.SaveChanges();
            }

            using (var context = new NeweyContext(nameof(Proxies_only_created_if_Use_called), false, false))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType());
            }

            using (var context = new NeweyContext(nameof(Proxies_only_created_if_Use_called), true, false))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType().BaseType);
            }

            using (var context = new NeweyContext(nameof(Proxies_only_created_if_Use_called), false, true))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType().BaseType);
            }

            using (var context = new NeweyContext(nameof(Proxies_only_created_if_Use_called), true, true))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType().BaseType);
            }
        }
示例#4
0
 public void CreateProxy_throws_if_constructor_args_do_not_match()
 {
     using (var context = new NeweyContext())
     {
         Assert.Throws <InvalidProxyConstructorArgumentsException>(() => context.CreateProxy <March881>(77, 88));
     }
 }
示例#5
0
 public void CreateProxy_throws_if_wrong_number_of_constructor_args()
 {
     using (var context = new NeweyContext())
     {
         Assert.Throws <InvalidProxyConstructorArgumentsException>(() => context.CreateProxy <March881>(77, 88, 99));
     }
 }
示例#6
0
        public void CreateProxy_works_for_shared_type_entity_types()
        {
            using var context = new NeweyContext();

            Assert.Same(typeof(SharedTypeEntityType), context.Set <SharedTypeEntityType>("STET1").CreateProxy().GetType().BaseType);
            Assert.Same(typeof(SharedTypeEntityType), context.Set <SharedTypeEntityType>("STET1").CreateProxy(_ => { }).GetType().BaseType);
        }
示例#7
0
    public void CreateProxy_works_for_record_with_base_type_entity_types()
    {
        using var context = new NeweyContext();

        Assert.Same(typeof(March86C), context.Set <March86C>().CreateProxy().GetType().BaseType);
        Assert.Same(typeof(March86C), context.Set <March86C>().CreateProxy(_ => { }).GetType().BaseType);
    }
示例#8
0
        public void CreateProxy_works_for_owned_but_not_weak_entity_types()
        {
            using var context = new NeweyContext();

            Assert.Same(typeof(IsOwnedButNotWeak), context.CreateProxy <IsOwnedButNotWeak>().GetType().BaseType);
            Assert.Same(typeof(IsOwnedButNotWeak), context.CreateProxy <IsOwnedButNotWeak>(_ => { }).GetType().BaseType);
            Assert.Same(typeof(IsOwnedButNotWeak), context.CreateProxy(typeof(IsOwnedButNotWeak)).GetType().BaseType);
        }
示例#9
0
        public void CreateProxy_uses_parameterized_constructor()
        {
            using var context = new NeweyContext();
            var proxy = context.CreateProxy <March881>(77, "Leyton House");

            Assert.Same(typeof(March881), proxy.GetType().BaseType);
            Assert.Equal(77, proxy.Id);
            Assert.Equal("Leyton House", proxy.Sponsor);
        }
示例#10
0
        public void CreateProxy_uses_parameterized_constructor_taking_context()
        {
            using var context = new NeweyContext();
            var proxy = context.CreateProxy <WilliamsFw14>(context, 6, "Canon");

            Assert.Same(typeof(WilliamsFw14), proxy.GetType().BaseType);
            Assert.Same(context, proxy.Context);
            Assert.Equal(6, proxy.Id);
            Assert.Equal("Canon", proxy.Sponsor);
        }
示例#11
0
        public void Materialization_uses_parameterless_constructor()
        {
            using (var context = new NeweyContext(nameof(Materialization_uses_parameterless_constructor)))
            {
                context.Add(new March82GGtp());
                context.SaveChanges();
            }

            using (var context = new NeweyContext(nameof(Materialization_uses_parameterless_constructor)))
            {
                Assert.Same(typeof(March82GGtp), context.Set <March82GGtp>().Single().GetType().BaseType);
            }
        }
示例#12
0
        public void CreateProxy_throws_for_shared_type_entity_types_when_entity_type_name_not_known()
        {
            using var context = new NeweyContext();

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundShared(nameof(SharedTypeEntityType)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy <SharedTypeEntityType>()).Message);

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundShared(nameof(SharedTypeEntityType)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy <SharedTypeEntityType>(_ => { })).Message);

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundShared(nameof(SharedTypeEntityType)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy(typeof(SharedTypeEntityType))).Message);
        }
        [ConditionalFact] // Issue #22407
        public void CreateProxy_throws_for_weak_entity_types()
        {
            using var context = new NeweyContext();

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundWeak(nameof(IsWeak)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy <IsWeak>()).Message);

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundWeak(nameof(IsWeak)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy <IsWeak>(_ => { })).Message);

            Assert.Equal(
                ProxiesStrings.EntityTypeNotFoundWeak(nameof(IsWeak)),
                Assert.Throws <InvalidOperationException>(() => context.CreateProxy(typeof(IsWeak))).Message);
        }
示例#14
0
        public void Materialization_uses_parameterized_constructor()
        {
            using (var context = new NeweyContext(nameof(Materialization_uses_parameterized_constructor)))
            {
                context.Add(new March881(77, "Leyton House"));
                context.SaveChanges();
            }

            using (var context = new NeweyContext(nameof(Materialization_uses_parameterized_constructor)))
            {
                var proxy = context.Set <March881>().Single();

                Assert.Same(typeof(March881), proxy.GetType().BaseType);
                Assert.Equal(77, proxy.Id);
                Assert.Equal("Leyton House", proxy.Sponsor);
            }
        }
示例#15
0
        public void Materialization_uses_parameterized_constructor_taking_context()
        {
            using (var context = new NeweyContext(nameof(Materialization_uses_parameterized_constructor_taking_context)))
            {
                context.Add(new WilliamsFw14(context, 6, "Canon"));
                context.SaveChanges();
            }

            using (var context = new NeweyContext(nameof(Materialization_uses_parameterized_constructor_taking_context)))
            {
                var proxy = context.Set <WilliamsFw14>().Single();

                Assert.Same(typeof(WilliamsFw14), proxy.GetType().BaseType);
                Assert.Same(context, proxy.Context);
                Assert.Equal(6, proxy.Id);
                Assert.Equal("Canon", proxy.Sponsor);
            }
        }