public async Task <MyWebApp.Domain.Owner> InsertAsync(OwnerUpdateModel owner) { var result = await this.Context.AddAsync(this.Mapper.Map <Owner>(owner)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <MyWebApp.Domain.Doctor>(result.Entity)); }
public async Task <MyWebApp.Domain.Owner> UpdateAsync(OwnerUpdateModel owner) { var existing = await this.Get(owner); var result = this.Mapper.Map(owner, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <MyWebApp.Domain.Owner>(result)); }
public async Task <Owner> CreateOwner(OwnerUpdateModel ownerUpdateModel) { if (ownerUpdateModel == null) { throw new ArgumentNullException(nameof(ownerUpdateModel)); } var entityEntry = await Context.Owners.AddAsync(Mapper.Map <Entities.CarOwner>(ownerUpdateModel)); await Context.SaveChangesAsync(); return(Mapper.Map <Owner>(entityEntry.Entity)); }
public async Task CreateOwner_OwnerNotExists_CreatesOwner() { var ownerUpdateModel = new OwnerUpdateModel(); var addedOwner = new Owner(); var ownerDataAccessContainer = new Mock <IOwnerDataAccess>(); ownerDataAccessContainer.Setup(t => t.GetOwner(ownerUpdateModel)).ReturnsAsync((Owner)null); ownerDataAccessContainer.Setup(t => t.CreateOwner(ownerUpdateModel)).ReturnsAsync(addedOwner); var ownerCreateService = new CreateOwnerService(ownerDataAccessContainer.Object); var result = await ownerCreateService.CreateOwner(ownerUpdateModel); Assert.AreNotEqual(null, result); }
public void CreateOwner_OwnerExists_ThrowsException() { var ownerUpdateModel = new OwnerUpdateModel(); var existingOwner = new Owner(); var ownerDataAccessContainer = new Mock <IOwnerDataAccess>(); ownerDataAccessContainer.Setup(t => t.CreateOwner(ownerUpdateModel)).ReturnsAsync(existingOwner); ownerDataAccessContainer.Setup(t => t.GetOwner(ownerUpdateModel)).ReturnsAsync(existingOwner); var ownerCreateService = new CreateOwnerService(ownerDataAccessContainer.Object); Assert.ThrowsAsync <ArgumentException>(async() => await ownerCreateService.CreateOwner(ownerUpdateModel)); }
public async Task CreateAsync_OwnerValidationSucceed_CreatesOwner() { // Arrange var owner = new OwnerUpdateModel(); var expected = new Owner(); var ownerDAL = new Mock <IOwnerDAL>(); ownerDAL.Setup(x => x.InsertAsync(doctor)).ReturnsAsync(expected); var ownerService = new OwnerService(doctorDAL.Object); // Act var result = await ownerService.CreateAsync(owner); // Assert result.Should().Be(expected); }
public async Task <Owner> UpdateAsync(OwnerUpdateModel owner) { return(await this.OwnerDAL.UpdateAsync(owner)); }