public void Can_obtain_context()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Same(context, context.Entry(entity).Context);
                Assert.Same(context, context.Entry((object)entity).Context);
            }
        }
        public void Can_obtain_entity_instance()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                Assert.Same(entity, context.Entry(entity).Entity);
                Assert.Same(entity, context.Entry((object)entity).Entity);
            }
        }
        public void Can_obtain_underlying_state_entry()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;
                var entry = ((IAccessor<IStateManager>)context.ChangeTracker).Service.GetOrCreateEntry(entity);

                Assert.Same(entry, ((IAccessor<InternalEntityEntry>)context.Entry(entity)).Service);
                Assert.Same(entry, ((IAccessor<InternalEntityEntry>)context.Entry((object)entity)).Service);
            }
        }
        public void Can_get_metadata()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;
                var entityType = context.Model.GetEntityType(typeof(Chunky));

                Assert.Same(entityType, context.Entry(entity).Metadata);
                Assert.Same(entityType, context.Entry((object)entity).Metadata);
            }
        }
        public void Can_obtain_underlying_state_entry()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;
                var entry = context.ChangeTracker.GetService().GetOrCreateEntry(entity);

                Assert.Same(entry, context.Entry(entity).GetService());
                Assert.Same(entry, context.Entry((object)entity).GetService());
            }
        }
        public void Can_get_collection_entry_by_name_using_Navigation()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Cherry()).Entity;

                var entry = context.Entry(entity).Navigation("Monkeys");
                Assert.Equal("Monkeys", entry.Metadata.Name);
                Assert.IsType <CollectionEntry>(entry);

                entry = context.Entry((object)entity).Navigation("Monkeys");
                Assert.Equal("Monkeys", entry.Metadata.Name);
                Assert.IsType <CollectionEntry>(entry);
            }
        }
Beispiel #7
0
    public void Can_get_skip_collection_entry_by_IPropertyBase_using_Member()
    {
        using var context = new FreezerContext();
        var entity       = context.Add(new Cherry()).Entity;
        var propertyBase = (IPropertyBase)context.Entry(entity).Metadata.FindSkipNavigation("Chunkies") !;

        var entry = context.Entry(entity).Member(propertyBase);

        Assert.Same(propertyBase, entry.Metadata);
        Assert.IsType <CollectionEntry>(entry);

        entry = context.Entry((object)entity).Member(propertyBase);
        Assert.Same(propertyBase, entry.Metadata);
        Assert.IsType <CollectionEntry>(entry);
    }
        public void Can_get_property_entry_by_name_using_Member()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                var entry = context.Entry(entity).Member("Monkey");
                Assert.Equal("Monkey", entry.Metadata.Name);
                Assert.IsType <PropertyEntry>(entry);

                entry = context.Entry((object)entity).Member("Monkey");
                Assert.Equal("Monkey", entry.Metadata.Name);
                Assert.IsType <PropertyEntry>(entry);
            }
        }
        public void Can_get_reference_entry_by_name_using_Navigation()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                var entry = context.Entry(entity).Navigation("Garcia");
                Assert.Equal("Garcia", entry.Metadata.Name);
                Assert.IsType <ReferenceEntry>(entry);

                entry = context.Entry((object)entity).Navigation("Garcia");
                Assert.Equal("Garcia", entry.Metadata.Name);
                Assert.IsType <ReferenceEntry>(entry);
            }
        }
Beispiel #10
0
    public void Throws_when_wrong_property_name_is_used_while_getting_property_entry_by_name()
    {
        using var context = new FreezerContext();
        var entity = context.Add(new Chunky()).Entity;

        Assert.Equal(
            CoreStrings.PropertyNotFound("Chimp", entity.GetType().Name),
            Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Property("Chimp").Metadata.Name).Message);
        Assert.Equal(
            CoreStrings.PropertyNotFound("Chimp", entity.GetType().Name),
            Assert.Throws <InvalidOperationException>(() => context.Entry((object)entity).Property("Chimp").Metadata.Name).Message);
        Assert.Equal(
            CoreStrings.PropertyNotFound("Chimp", entity.GetType().Name),
            Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Property <int>("Chimp").Metadata.Name).Message);
    }
Beispiel #11
0
        public void Can_get_all_collection_entries()
        {
            using (var context = new FreezerContext())
            {
                Assert.Empty(context.Attach(new Chunky()).Collections.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string> {
                    "Monkeys"
                },
                    context.Attach(new Cherry()).Collections.Select(e => e.Metadata.Name).ToList());

                Assert.Empty(context.Attach(new Half()).Collections.Select(e => e.Metadata.Name).ToList());
            }
        }
Beispiel #12
0
        public void IsModified_can_set_fk_to_modified_principal_with_Added_or_Deleted_dependents(
            EntityState principalState,
            EntityState dependentState)
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky1 = new Chunky { Id = 1, Garcia = cherry };
            var chunky2 = new Chunky { Id = 2, Garcia = cherry };

            cherry.Monkeys = new List<Chunky> { chunky1, chunky2 };

            context.Entry(cherry).State = principalState;
            context.Entry(chunky1).State = dependentState;
            context.Entry(chunky2).State = dependentState;

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.True(collection.IsModified);

            collection.IsModified = false;

            Assert.True(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);

            collection.IsModified = true;

            Assert.True(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
            Assert.Equal(dependentState, context.Entry(chunky1).State);
            Assert.Equal(dependentState, context.Entry(chunky2).State);

            if (dependentState == EntityState.Deleted)
            {
                context.Entry(chunky1).State = EntityState.Detached;
                context.Entry(chunky2).State = EntityState.Detached;
            }
            else
            {
                context.Entry(chunky1).State = EntityState.Unchanged;
                context.Entry(chunky2).State = EntityState.Unchanged;
            }

            Assert.False(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
        }
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry = context.Add(entity).GetInfrastructure();

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry = ((IAccessor<InternalEntityEntry>)context.Add(entity)).Service;

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
Beispiel #15
0
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry  = context.Add(entity).GetService();

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
        public void Throws_when_accessing_refernce_as_collection()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Equal(CoreStrings.CollectionIsReference("Garcia", entity.GetType().Name,
                                                               nameof(EntityEntry.Collection), nameof(EntityEntry.Reference)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Collection("Garcia").Metadata.Name).Message);
                Assert.Equal(CoreStrings.CollectionIsReference("Garcia", entity.GetType().Name,
                                                               nameof(EntityEntry.Collection), nameof(EntityEntry.Reference)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry((object)entity).Collection("Garcia").Metadata.Name).Message);
                Assert.Equal(CoreStrings.CollectionIsReference("Garcia", entity.GetType().Name,
                                                               nameof(EntityEntry.Collection), nameof(EntityEntry.Reference)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Collection <Cherry>("Garcia").Metadata.Name).Message);
            }
        }
Beispiel #17
0
    public void Throws_when_accessing_property_as_navigation()
    {
        using var context = new FreezerContext();
        var entity = context.Add(new Chunky()).Entity;

        Assert.Equal(
            CoreStrings.NavigationIsProperty(
                "Monkey", entity.GetType().Name,
                nameof(EntityEntry.Reference), nameof(EntityEntry.Collection), nameof(EntityEntry.Property)),
            Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Navigation("Monkey").Metadata.Name).Message);
        Assert.Equal(
            CoreStrings.NavigationIsProperty(
                "Monkey", entity.GetType().Name,
                nameof(EntityEntry.Reference), nameof(EntityEntry.Collection), nameof(EntityEntry.Property)),
            Assert.Throws <InvalidOperationException>(() => context.Entry((object)entity).Navigation("Monkey").Metadata.Name)
            .Message);
    }
Beispiel #18
0
        private static void AttachGraph(FreezerContext context, Cherry cherry1, Cherry cherry2, Chunky chunky1, Chunky chunky2)
        {
            cherry1.Chunkies = new List <Chunky> {
                chunky1, chunky2
            };
            cherry2.Chunkies = new List <Chunky>();

            if (context is ExplicitFreezerContext)
            {
                context.AddRange(cherry1, cherry2, chunky1, chunky2); // So that PKs get generated values
                context.ChangeTracker.Entries().ToList().ForEach(e => e.State = EntityState.Unchanged);
            }
            else
            {
                context.AttachRange(cherry1, cherry2, chunky1, chunky2);
            }
        }
Beispiel #19
0
        public void Can_get_and_set_current_value_property()
        {
            using var context = new FreezerContext();
            var entity = new Chunky();

            context.Add(entity);

            var property = context.Entry(entity).Member("GarciaId");

            Assert.Null(property.CurrentValue);

            property.CurrentValue = 77;
            Assert.Equal(77, property.CurrentValue);

            property.CurrentValue = null;
            Assert.Null(property.CurrentValue);
        }
Beispiel #20
0
        public async Task Can_get_and_change_state_async()
        {
            using (var context = new FreezerContext())
            {
                var entity     = new Chunky();
                var stateEntry = context.Add(entity).StateEntry;

                await context.Entry(entity).SetStateAsync(EntityState.Modified);

                Assert.Equal(EntityState.Modified, stateEntry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                await context.Entry((object)entity).SetStateAsync(EntityState.Unchanged);

                Assert.Equal(EntityState.Unchanged, stateEntry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
        public void Throws_when_accessing_collection_as_reference()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Cherry()).Entity;

                Assert.Equal(CoreStrings.ReferenceIsCollection("Monkeys", entity.GetType().Name,
                                                               nameof(EntityEntry.Reference), nameof(EntityEntry.Collection)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Reference("Monkeys").Metadata.Name).Message);
                Assert.Equal(CoreStrings.ReferenceIsCollection("Monkeys", entity.GetType().Name,
                                                               nameof(EntityEntry.Reference), nameof(EntityEntry.Collection)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry((object)entity).Reference("Monkeys").Metadata.Name).Message);
                Assert.Equal(CoreStrings.ReferenceIsCollection("Monkeys", entity.GetType().Name,
                                                               nameof(EntityEntry.Reference), nameof(EntityEntry.Collection)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Reference <Random>("Monkeys").Metadata.Name).Message);
                Assert.Equal(CoreStrings.ReferenceIsCollection("Monkeys", entity.GetType().Name,
                                                               nameof(EntityEntry.Reference), nameof(EntityEntry.Collection)),
                             Assert.Throws <InvalidOperationException>(() => context.Entry(entity).Reference(e => e.Monkeys).Metadata.Name).Message);
            }
        }
Beispiel #22
0
    public void Can_get_all_reference_entries()
    {
        using var context = new FreezerContext();
        Assert.Equal(
            new List <string> {
            "Garcia"
        },
            context.Attach(new Chunky()).References.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string> {
            "Baked"
        },
            context.Attach(new Cherry()).References.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string> {
            "Garcia"
        },
            context.Attach(new Half()).References.Select(e => e.Metadata.Name).ToList());
    }
Beispiel #23
0
    public void Can_get_all_navigation_entries()
    {
        using var context = new FreezerContext();
        Assert.Equal(
            new List <string> {
            "Garcia"
        },
            context.Attach(new Chunky()).Navigations.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string> {
            "Baked", "Monkeys"
        },
            context.Attach(new Cherry()).Navigations.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string> {
            "Garcia"
        },
            context.Attach(new Half()).Navigations.Select(e => e.Metadata.Name).ToList());
    }
Beispiel #24
0
        public void IsModified_tracks_state_of_FK_property_principal()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky1 = new Chunky { Id = 1, Garcia = cherry };
            var chunky2 = new Chunky { Id = 2, Garcia = cherry };
            cherry.Monkeys = new List<Chunky> { chunky1, chunky2 };
            context.AttachRange(cherry, chunky1, chunky2);

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.False(collection.IsModified);

            context.Entry(chunky1).State = EntityState.Modified;

            Assert.True(collection.IsModified);

            context.Entry(chunky1).State = EntityState.Unchanged;

            Assert.False(collection.IsModified);
        }
        public void IsModified_can_set_fk_to_modified_collection()
        {
            using (var context = new FreezerContext())
            {
                var cherry  = new Cherry();
                var chunky1 = new Chunky
                {
                    Garcia = cherry
                };
                var chunky2 = new Chunky
                {
                    Garcia = cherry
                };
                cherry.Monkeys = new List <Chunky>
                {
                    chunky1,
                    chunky2
                };
                context.AttachRange(cherry, chunky1, chunky2);

                var collection = context.Entry(cherry).Navigation("Monkeys");

                Assert.False(collection.IsModified);

                collection.IsModified = true;

                Assert.True(collection.IsModified);
                Assert.True(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
                Assert.True(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);

                collection.IsModified = false;

                Assert.False(collection.IsModified);
                Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
                Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
                Assert.Equal(EntityState.Unchanged, context.Entry(chunky1).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(chunky2).State);
            }
        }
Beispiel #26
0
        public void Can_get_and_set_current_value_generic_attched()
        {
            using (var context = new FreezerContext())
            {
                var cherry = new Cherry();
                var chunky = new Chunky();
                context.AttachRange(chunky, cherry);

                var collection = context.Entry(cherry).Collection(e => e.Monkeys);

                Assert.Null(collection.CurrentValue);

                collection.CurrentValue = new List <Chunky>
                {
                    chunky
                };

                Assert.Same(cherry, chunky.Garcia);
                Assert.Same(chunky, cherry.Monkeys.Single());
                Assert.Equal(cherry.Id, chunky.GarciaId);
                Assert.Same(chunky, collection.CurrentValue.Single());

                Assert.Equal(EntityState.Unchanged, context.Entry(cherry).State);
                Assert.Equal(EntityState.Modified, context.Entry(chunky).State);
                Assert.True(context.Entry(chunky).Property(e => e.GarciaId).IsModified);

                collection.CurrentValue = null;

                Assert.Null(chunky.Garcia);
                Assert.Null(cherry.Monkeys);
                Assert.Null(chunky.GarciaId);
                Assert.Null(collection.CurrentValue);

                Assert.Equal(EntityState.Unchanged, context.Entry(cherry).State);
                Assert.Equal(EntityState.Modified, context.Entry(chunky).State);
                Assert.True(context.Entry(chunky).Property(e => e.GarciaId).IsModified);
            }
        }
Beispiel #27
0
    public void Detached_entities_are_not_returned_from_the_change_tracker()
    {
        using var context = new FreezerContext();
        var entity = new Chunky {
            Id = 808
        };

        context.Attach(entity);

        Assert.Single(context.ChangeTracker.Entries());

        context.Entry(entity).State = EntityState.Detached;

        Assert.Empty(context.ChangeTracker.Entries());

        context.ChangeTracker.DetectChanges();

        Assert.Empty(context.ChangeTracker.Entries());

        context.Entry(entity);

        Assert.Empty(context.ChangeTracker.Entries());
    }
Beispiel #28
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // app.UseDefaultFiles();
            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            //Creo il database se non esiste
            using (var client = new FreezerContext())
            {
                client.Database.EnsureCreated();
            }

            app.UseHttpsRedirection();
            app.UseMvc();
        }
        public void Can_get_all_property_entries()
        {
            using (var context = new FreezerContext())
            {
                Assert.Equal(
                    new List <string> {
                    "Id", "GarciaId", "Monkey", "Nonkey"
                },
                    context.Attach(new Chunky()).Properties.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string> {
                    "Id", "Garcia"
                },
                    context.Attach(new Cherry()).Properties.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string> {
                    "Id", "Baked", "GarciaId"
                },
                    context.Attach(new Half()).Properties.Select(e => e.Metadata.Name).ToList());
            }
        }
Beispiel #30
0
    public void Can_get_all_modified_properties()
    {
        using var context = new FreezerContext();
        var entity = context.Attach(new Chunky()).Entity;

        var modified = context.Entry(entity).Properties
                       .Where(e => e.IsModified).Select(e => e.Metadata.Name).ToList();

        Assert.Empty(modified);

        entity.Nonkey   = "Blue";
        entity.GarciaId = 77;

        context.ChangeTracker.DetectChanges();

        modified = context.Entry(entity).Properties
                   .Where(e => e.IsModified).Select(e => e.Metadata.Name).ToList();

        Assert.Equal(
            new List <string> {
            "GarciaId", "Nonkey"
        }, modified);
    }
Beispiel #31
0
        public void IsModified_tracks_state_of_FK_property_principal()
        {
            using var context = new FreezerContext();
            var half   = new Half();
            var chunky = new Chunky {
                Baked = half
            };

            half.Monkey = chunky;
            context.AttachRange(chunky, half);

            var reference = context.Entry(chunky).Reference(e => e.Baked);

            Assert.False(reference.IsModified);

            context.Entry(half).State = EntityState.Modified;

            Assert.True(reference.IsModified);

            context.Entry(half).State = EntityState.Unchanged;

            Assert.False(reference.IsModified);
        }
Beispiel #32
0
        public void Can_get_and_set_current_value_not_tracked_generic()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky = new Chunky();

            var reference = context.Entry(chunky).Reference(e => e.Garcia);

            Assert.Null(reference.CurrentValue);

            reference.CurrentValue = cherry;

            Assert.Same(cherry, chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Same(cherry, reference.CurrentValue);

            reference.CurrentValue = null;

            Assert.Null(chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Null(reference.CurrentValue);
        }
Beispiel #33
0
        public void Can_get_and_set_current_value_generic_not_tracked()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky = new Chunky();

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.Null(collection.CurrentValue);

            collection.CurrentValue = new List<Chunky> { chunky };

            Assert.Null(chunky.Garcia);
            Assert.Same(chunky, cherry.Monkeys.Single());
            Assert.Null(chunky.GarciaId);
            Assert.Same(chunky, collection.CurrentValue.Single());

            collection.CurrentValue = null;

            Assert.Null(chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Null(collection.CurrentValue);
        }
Beispiel #34
0
        public void Can_get_and_set_current_value_start_tracking_generic()
        {
            using (var context = new FreezerContext())
            {
                var cherry = new Cherry();
                var chunky = new Chunky();
                context.Add(cherry);

                var collection = context.Entry(cherry).Collection(e => e.Monkeys);

                Assert.Null(collection.CurrentValue);

                collection.CurrentValue = new List <Chunky>
                {
                    chunky
                };

                Assert.Same(cherry, chunky.Garcia);
                Assert.Same(chunky, cherry.Monkeys.Single());
                Assert.Equal(cherry.Id, chunky.GarciaId);
                Assert.Same(chunky, collection.CurrentValue.Single());

                Assert.Equal(EntityState.Added, context.Entry(cherry).State);
                Assert.Equal(EntityState.Added, context.Entry(chunky).State);

                collection.CurrentValue = null;

                Assert.Null(chunky.Garcia);
                Assert.Null(cherry.Monkeys);
                Assert.Null(chunky.GarciaId);
                Assert.Null(collection.CurrentValue);

                Assert.Equal(EntityState.Added, context.Entry(cherry).State);
                Assert.Equal(EntityState.Added, context.Entry(chunky).State);
            }
        }
Beispiel #35
0
        public CreateBaseController()
        {
            _db = new FreezerContext();
            if (_db.Freezers.Count() == 0)
            {
                var newFreezer = new Freezer()
                {
                    Name = "Cucina Up"
                };
                _db.Freezers.Add(newFreezer);
                _db.SaveChanges();
                var newId = newFreezer.Id;
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto1", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto2", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto3", FreezerId = newId
                });
                _db.SaveChanges();

                newFreezer = new Freezer()
                {
                    Name = "Cucina Pt"
                };
                _db.Freezers.Add(newFreezer);
                _db.SaveChanges();
                newId = newFreezer.Id;
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto1", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto2", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto3", FreezerId = newId
                });
                _db.SaveChanges();

                newFreezer = new Freezer()
                {
                    Name = "Cantina"
                };
                _db.Freezers.Add(newFreezer);
                _db.SaveChanges();
                newId = newFreezer.Id;
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto1", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto2", FreezerId = newId
                });
                _db.Drawers.Add(new Drawer()
                {
                    Name = "Cassetto3", FreezerId = newId
                });
                _db.SaveChanges();
            }

            _db.Types.Add(new FoodType()
            {
                Name = "Pesce"
            });
            _db.Types.Add(new FoodType()
            {
                Name = "Carne"
            });
            _db.Types.Add(new FoodType()
            {
                Name = "Legumi"
            });
            _db.Types.Add(new FoodType()
            {
                Name = "Verdura"
            });
            _db.Types.Add(new FoodType()
            {
                Name = "Erbe aromatiche e spezie"
            });
            _db.Types.Add(new FoodType()
            {
                Name = "Altro"
            });

            _db.Portions.Add(new FoodPortion()
            {
                Name = "X1"
            });
            _db.Portions.Add(new FoodPortion()
            {
                Name = "X2"
            });
            _db.Portions.Add(new FoodPortion()
            {
                Name = "X3"
            });
            _db.Portions.Add(new FoodPortion()
            {
                Name = "None"
            });
            _db.SaveChanges();
        }
        public void Can_get_property_entry_by_name()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Equal("Monkey", context.Entry(entity).Property("Monkey").Metadata.Name);
                Assert.Equal("Monkey", context.Entry((object)entity).Property("Monkey").Metadata.Name);
            }
        }
        public void Throws_when_wrong_generic_type_is_used_while_getting_property_entry_by_name()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Equal(Strings.WrongGenericPropertyType("Monkey", entity.GetType(), typeof(int).Name, typeof(string).Name),
                    Assert.Throws<ArgumentException>(() => context.Entry(entity).Property<string>("Monkey")).Message);
            }
        }
        public void Can_get_generic_property_entry_by_lambda()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Equal("Monkey", context.Entry(entity).Property(e => e.Monkey).Metadata.Name);
            }
        }
        public void Throws_when_wrong_property_name_is_used_while_getting_property_entry_by_name()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Add(new Chunky()).Entity;

                Assert.Equal(Strings.PropertyNotFound("Chimp", entity.GetType()),
                    Assert.Throws<ModelItemNotFoundException>(() => context.Entry(entity).Property("Chimp").Metadata.Name).Message);
                Assert.Equal(Strings.PropertyNotFound("Chimp", entity.GetType()),
                    Assert.Throws<ModelItemNotFoundException>(() => context.Entry((object)entity).Property("Chimp").Metadata.Name).Message);
                Assert.Equal(Strings.PropertyNotFound("Chimp", entity.GetType()),
                    Assert.Throws<ModelItemNotFoundException>(() => context.Entry(entity).Property<int>("Chimp").Metadata.Name).Message);
            }
        }
        private void ChangeStateOnEntry(EntityState initialState, EntityState expectedState)
        {
            using (var context = new FreezerContext())
            {
                var entry = context.Add(new Chunky());

                entry.State = initialState;
                entry.State = expectedState;

                Assert.Equal(expectedState, entry.State);
            }
        }
Beispiel #41
0
 public FreezerListRepository()
 {
     _db = new FreezerContext();
 }
Beispiel #42
0
 public PortionsListRepository()
 {
     _db = new FreezerContext();
 }