コード例 #1
0
        public void Update_DataIsChanged_UpdatesTheSameModel()
        {
            var model = new StubDbModel {
                Id = 42, Data = 0
            };

            using (var connection = new DbConnection())
            {
                var dbContextBuilder = new StubDbContextBuilder(connection.DbOptions)
                                       .With(model);

                model.Data = 1;
                using (var context = dbContextBuilder.Build())
                {
                    var sut = new StubCrudRepository(context);
                    sut.Update(model);
                    sut.Save();
                }

                using (var context = dbContextBuilder.Build())
                {
                    context.StubDbModels.Find(model.Id).Data.Should().Be(1);
                }
            }
        }
コード例 #2
0
        public void Remove_RemovesAsExpected()
        {
            var model = new StubDbModel();

            using (var connection = new DbConnection())
            {
                var dbContextBuilder = new StubDbContextBuilder(connection.DbOptions)
                                       .With(model);

                using (var context = dbContextBuilder.Build())
                {
                    var sut = new StubCrudRepository(context);
                    sut.Remove(model);
                    sut.Save();
                }

                using (var context = dbContextBuilder.Build())
                {
                    context.StubDbModels.Should().BeEmpty();
                }
            }
        }