Exemple #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);
                }
            }
        }
Exemple #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();
                }
            }
        }
Exemple #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();
         }
     }
 }
Exemple #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();
                }
            }
        }
Exemple #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();
                }
            }
        }