예제 #1
0
        public async Task GivenStaffIsNotDeleted_WhenUpdateStaffAsync_ThenStaffUpdated()
        {
            // Arrange
            var staff = new Staff()
            {
                ID         = Guid.NewGuid(),
                Email      = "*****@*****.**",
                Surname    = "Test",
                GivenNames = "Person"
            };

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                ctx.Add(staff);
                await ctx.SaveChangesAsync();
            }

            var updatedStaff = staff.Adapt <Staff>();

            updatedStaff.Surname = "Updated";

            // Act
            var result = await _repo.UpdateStaffAsync(updatedStaff);

            //Assert
            result.Should().BeEquivalentTo(updatedStaff);
            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var staffInDb = await ctx.Staff.FirstOrDefaultAsync();

                staffInDb.Should().BeEquivalentTo(updatedStaff);
            }
        }
예제 #2
0
        public async Task GivenStaffIsDeleted_WhenUpdateStaffAsync_ThenThrowException()
        {
            // Arrange
            var staff = new Staff()
            {
                ID         = Guid.NewGuid(),
                Email      = "*****@*****.**",
                Surname    = "Test",
                GivenNames = "Person",
                IsDeleted  = true
            };

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                ctx.Add(staff);
                await ctx.SaveChangesAsync();
            }

            var updatedStaff = staff.Adapt <Staff>();

            updatedStaff.Surname = "Updated";

            // Act + Assert
            await Assert.ThrowsAsync <UnableToUpdateDeletedRecordsException>(() => _repo.UpdateStaffAsync(updatedStaff));
        }