예제 #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 async Task AddAsync_AddsAsExpected()
        {
            using (var connection = new DbConnection())
            {
                var dbContextBuilder = new StubDbContextBuilder(connection.DbOptions);

                using (var context = dbContextBuilder.Build())
                {
                    var sut = new StubCrudRepository(context);
                    await sut.AddAsync(new StubDbModel(), CancellationToken.None);

                    await sut.SaveAsync(CancellationToken.None);
                }

                using (var context = dbContextBuilder.Build())
                {
                    context.StubDbModels.Should().NotBeEmpty();
                }
            }
        }
예제 #3
0
 public void GetById_NoEntries_ReturnsNull()
 {
     using (var connection = new DbConnection())
     {
         var dbContextBuilder = new StubDbContextBuilder(connection.DbOptions);
         using (var context = dbContextBuilder.Build())
         {
             var sut = new StubCrudRepository(context);
             sut.GetById(42).Should().BeNull();
         }
     }
 }
예제 #4
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();
                }
            }
        }
예제 #5
0
        public void GetById_GetsElementAsExpected()
        {
            using (var connection = new DbConnection())
            {
                var dbContextBuilder = new StubDbContextBuilder(connection.DbOptions)
                                       .With(new StubDbModel {
                    Id = 42
                });

                using (var context = dbContextBuilder.Build())
                {
                    var sut = new StubCrudRepository(context);
                    sut.GetById(42).Should().NotBeNull();
                }
            }
        }