Example #1
0
        public async Task SettleDamageShouldDoNothingWithNonExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb7")
                          .Options;
            var dbContext = new ApplicationDbContext(options);
            var damage1   = new Damage {
                Id = 1, EstimatedCost = 100, IsSettled = true
            };
            var damage2 = new Damage {
                Id = 2, EstimatedCost = 0, IsSettled = false
            };

            dbContext.Damages.Add(damage1);
            dbContext.Damages.Add(damage2);
            await dbContext.SaveChangesAsync();

            var repository    = new EfDeletableEntityRepository <Damage>(dbContext);
            var service       = new DamageService(repository);
            int nonExistingId = 3;
            await service.SettleDamage(nonExistingId, 200);

            Assert.Equal(2, repository.All().Count());
            var damage1FromDb = await repository.GetByIdAsync(damage1.Id);

            var damage2FromDb = await repository.GetByIdAsync(damage2.Id);

            Assert.Equal <Damage>(damage1, damage1FromDb);
            Assert.Equal <Damage>(damage2, damage2FromDb);
        }
        public async Task ChangeStatusToSettledShouldDoNothingOnNonExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb3")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Claims.Add(new InsuranceClaim {
                Id = 1, Status = ClaimStatus.Open
            });
            dbContext.Claims.Add(new InsuranceClaim {
                Id = 2, Status = ClaimStatus.Pending
            });
            dbContext.Claims.Add(new InsuranceClaim {
                Id = 3, Status = ClaimStatus.Settled
            });
            await dbContext.SaveChangesAsync();

            var repository    = new EfDeletableEntityRepository <InsuranceClaim>(dbContext);
            var service       = new ClaimService(repository);
            int nonExistingId = 4;
            await service.ChangeStatusToSettled(nonExistingId);

            Assert.True((await repository.GetByIdAsync(1)).Status == ClaimStatus.Open);
            Assert.True((await repository.GetByIdAsync(2)).Status == ClaimStatus.Pending);
            Assert.True((await repository.GetByIdAsync(3)).Status == ClaimStatus.Settled);
        }
Example #3
0
        public async Task AddDamageShouldAddTheCorrectObject()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb2")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Damage>(dbContext);
            var service    = new DamageService(repository);
            var newDamage  = new Damage {
                Id = 1, PartName = "Door"
            };
            await service.AddDamage(newDamage);

            var damageFromDb = await repository.GetByIdAsync(newDamage.Id);

            Assert.Equal <Damage>(newDamage, damageFromDb);
        }
        public async Task CreateShouldAddTheCorrectObject()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb6")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <InsuranceClaim>(dbContext);
            var service    = new ClaimService(repository);
            var newClaim   = new InsuranceClaim {
                Id = 1, Description = "test"
            };
            await service.Create(newClaim);

            var claimFromDb = await repository.GetByIdAsync(newClaim.Id);

            Assert.Equal <InsuranceClaim>(newClaim, claimFromDb);
        }
Example #5
0
        public async Task CreateShouldAddTheCorrectObject()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb2")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentService(repository);
            var newComment = new Comment {
                Id = 1, Text = "test"
            };
            await service.Create(newComment);

            var commentFromDb = await repository.GetByIdAsync(newComment.Id);

            Assert.Equal <Comment>(newComment, commentFromDb);
        }
Example #6
0
        public async Task SettleDamageShouldModifyEntityWithExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb8")
                          .Options;
            var dbContext = new ApplicationDbContext(options);
            var damage    = new Damage {
                Id = 1, EstimatedCost = 0, IsSettled = false
            };

            dbContext.Damages.Add(damage);
            await dbContext.SaveChangesAsync();

            var     repository    = new EfDeletableEntityRepository <Damage>(dbContext);
            var     service       = new DamageService(repository);
            int     existingId    = 1;
            decimal estimatedCost = 200;
            await service.SettleDamage(existingId, estimatedCost);

            var damageFromDb = await repository.GetByIdAsync(damage.Id);

            Assert.Equal(estimatedCost, damageFromDb.EstimatedCost);
            Assert.True(damageFromDb.IsSettled);
        }