Exemplo n.º 1
0
        public void TestUpdateOnEntityNotTrackedOk()
        {
            //SETUP
            var unique  = Guid.NewGuid().ToString();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }
            using (var context = new EfCoreContext(options))
            {
                var utData  = context.SetupSingleDtoAndEntities <BookTitle>();
                var service = new CrudServices(context, utData.ConfigAndMapper);
                var logs    = context.SetupLogging();

                //ATTEMPT
                var author = new Author {
                    AuthorId = 1, Name = "New Name", Email = unique
                };
                service.UpdateAndSave(author);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                service.Message.ShouldEqual("Successfully updated the Author");
            }
            using (var context = new EfCoreContext(options))
            {
                context.Authors.Find(1).Email.ShouldEqual(unique);
            }
        }
Exemplo n.º 2
0
        public void TestUpdateOnEntityKeyNotSetOk()
        {
            //SETUP
            var unique  = Guid.NewGuid().ToString();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }
            using (var context = new EfCoreContext(options))
            {
                var utData  = context.SetupSingleDtoAndEntities <BookTitle>();
                var service = new CrudServices(context, utData.ConfigAndMapper);
                var logs    = context.SetupLogging();

                //ATTEMPT
                var author = new Author {
                    Name = "New Name", Email = unique
                };
                var ex = Assert.Throws <InvalidOperationException>(() => service.UpdateAndSave(author));

                //VERIFY
                ex.Message.ShouldStartWith("The primary key was not set on the entity class Author.");
            }
        }
Exemplo n.º 3
0
        public async Task TestUpdateOnEntityNotTrackedOk()
        {
            //SETUP
            var unique  = Guid.NewGuid().ToString();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();
            }
            using (var context = new EfCoreContext(options))
            {
                var utData  = context.SetupEntitiesDirect();
                var service = new CrudServicesAsync(context, utData.ConfigAndMapper);
                var logs    = context.SetupLogging();

                //ATTEMPT
                var author = new Author {
                    AuthorId = 1, Name = "New Name", Email = unique
                };
                await service.UpdateAndSaveAsync(author);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
            }
            using (var context = new EfCoreContext(options))
            {
                context.Authors.Find(1).Email.ShouldEqual(unique);
            }
        }