Beispiel #1
0
        public void Delegate_getter_is_returned_for_IProperty_property()
        {
            var modelBuilder = new ModelBuilder(InMemoryConventionSetBuilder.Build());
            var idProperty   = modelBuilder.Entity <Customer>().Property(e => e.Id).Metadata;

            modelBuilder.FinalizeModel();

            Assert.Equal(
                7, new ClrPropertyGetterFactory().Create(idProperty).GetClrValue(
                    new Customer {
                Id = 7
            }));
        }
        private static IModel CreateModel()
        {
            var modelBuilder = new ModelBuilder(InMemoryConventionSetBuilder.Build());

            modelBuilder.Entity <Customer>(
                b =>
            {
                b.HasKey(c => c.Id);
                b.Property(c => c.Name);
            });

            return(modelBuilder.Model.FinalizeModel());
        }
Beispiel #3
0
        public void Delegate_getter_is_returned_for_index_property()
        {
            var modelBuilder = new ModelBuilder(InMemoryConventionSetBuilder.Build());

            modelBuilder.Entity <IndexedClass>().Property(e => e.Id);
            var propertyA = modelBuilder.Entity <IndexedClass>().Metadata.AddIndexerProperty("PropertyA", typeof(string));
            var propertyB = modelBuilder.Entity <IndexedClass>().Metadata.AddIndexerProperty("PropertyB", typeof(int));

            modelBuilder.FinalizeModel();

            Assert.Equal("ValueA", new ClrPropertyGetterFactory().Create(propertyA).GetClrValue(new IndexedClass {
                Id = 7
            }));
            Assert.Equal(123, new ClrPropertyGetterFactory().Create(propertyB).GetClrValue(new IndexedClass {
                Id = 7
            }));
        }
 protected virtual ConventionSet GetConventionSet()
 => InMemoryConventionSetBuilder.Build();
 public override ModelBuilder CreateModelBuilder() =>
 new ModelBuilder(InMemoryConventionSetBuilder.Build());
Beispiel #6
0
        public async Task Can_add_update_delete_end_to_end_using_partial_shadow_state()
        {
            IMutableModel model = new Model(InMemoryConventionSetBuilder.Build());

            var customerType = model.AddEntityType(typeof(Customer));

            customerType.AddProperty("Name", typeof(string));

            var optionsBuilder = new DbContextOptionsBuilder()
                                 .UseModel(model.FinalizeModel())
                                 .UseInMemoryDatabase(nameof(ShadowStateUpdateTest))
                                 .UseInternalServiceProvider(_fixture.ServiceProvider);

            var customer = new Customer
            {
                Id = 42
            };

            using (var context = new DbContext(optionsBuilder.Options))
            {
                context.Add(customer);

                context.Entry(customer).Property("Name").CurrentValue = "Daenerys";

                await context.SaveChangesAsync();

                context.Entry(customer).Property("Name").CurrentValue = "Changed!";
            }

            using (var context = new DbContext(optionsBuilder.Options))
            {
                var customerFromStore = context.Set <Customer>().Single();

                Assert.Equal(42, customerFromStore.Id);
                Assert.Equal(
                    "Daenerys",
                    (string)context.Entry(customerFromStore).Property("Name").CurrentValue);
            }

            using (var context = new DbContext(optionsBuilder.Options))
            {
                var customerEntry = context.Entry(customer).GetInfrastructure();
                customerEntry[customerType.FindProperty("Name")] = "Daenerys Targaryen";

                context.Update(customer);

                await context.SaveChangesAsync();
            }

            using (var context = new DbContext(optionsBuilder.Options))
            {
                var customerFromStore = context.Set <Customer>().Single();

                Assert.Equal(42, customerFromStore.Id);
                Assert.Equal(
                    "Daenerys Targaryen",
                    (string)context.Entry(customerFromStore).Property("Name").CurrentValue);
            }

            using (var context = new DbContext(optionsBuilder.Options))
            {
                context.Remove(customer);

                await context.SaveChangesAsync();
            }

            using (var context = new DbContext(optionsBuilder.Options))
            {
                Assert.Equal(0, context.Set <Customer>().Count());
            }
        }