Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }