コード例 #1
0
ファイル: BuyerDAL.cs プロジェクト: V0lT999/CarsWebApp
        public async Task <Domain.Buyer> InsertAsync(BuyerUpdateModel buyer)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <Buyer>(buyer));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Domain.Buyer>(result.Entity));
        }
コード例 #2
0
ファイル: BuyerDAL.cs プロジェクト: V0lT999/CarsWebApp
        public async Task <Domain.Buyer> UpdateAsync(BuyerUpdateModel buyer)
        {
            var existing = await this.Get(buyer);

            var result = this.Mapper.Map(buyer, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Domain.Buyer>(result));
        }
コード例 #3
0
        public async Task CreateAsync_PatientValidationSucceed_CreatesPatient()
        {
            // Arrange
            var patient  = new BuyerUpdateModel();
            var expected = new Buyer();

            var streetService = new Mock <ICityService>();

            streetService.Setup(x => x.ValidateAsync(patient));

            var patientDAL = new Mock <IBuyerDAL>();

            patientDAL.Setup(x => x.InsertAsync(patient)).ReturnsAsync(expected);

            var patientService = new BuyerService(patientDAL.Object, streetService.Object);

            // Act
            var result = await patientService.CreateAsync(patient);

            // Assert
            result.Should().Be(expected);
        }
コード例 #4
0
        public async Task CreateAsync_PatientValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var patient  = new BuyerUpdateModel();
            var expected = fixture.Create <string>();

            var streetService = new Mock <ICityService>();

            streetService
            .Setup(x => x.ValidateAsync(patient))
            .Throws(new InvalidOperationException(expected));

            var patientDAL = new Mock <IBuyerDAL>();

            var patientService = new BuyerService(patientDAL.Object, streetService.Object);

            var action = new Func <Task>(() => patientService.CreateAsync(patient));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            patientDAL.Verify(x => x.InsertAsync(patient), Times.Never);
        }
コード例 #5
0
        public async Task <Buyer> UpdateAsync(BuyerUpdateModel buyer)
        {
            await this.CityService.ValidateAsync(buyer);

            return(await this.BuyerDAL.UpdateAsync(buyer));
        }
コード例 #6
0
 public Task <Buyer> UpdateAsync(BuyerUpdateModel buyer)
 {
     return(BuyerDataAccess.UpdateAsync(buyer));
 }
コード例 #7
0
 public Task <Buyer> CreateAsync(BuyerUpdateModel buyer)
 {
     return(BuyerDataAccess.InsertAsync(buyer));
 }