Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        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);
        }
Exemple #7
0
 public async Task <Owner> UpdateAsync(OwnerUpdateModel owner)
 {
     return(await this.OwnerDAL.UpdateAsync(owner));
 }