Example #1
0
        public async Task <BarbershopWebApp.Domain.Consumer> InsertAsync(ConsumerUpdateModel consumer)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <Consumer>(consumer));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <BarbershopWebApp.Domain.Consumer>(result.Entity));
        }
Example #2
0
        public async Task <BarbershopWebApp.Domain.Consumer> UpdateAsync(ConsumerUpdateModel consumer)
        {
            var existing = await this.Get(consumer);

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

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <BarbershopWebApp.Domain.Consumer>(result));
        }
        public async Task CreateAsync_consumerValidationSucceed_Createsconsumer()
        {
            // Arrange
            var consumer = new ConsumerUpdateModel();
            var expected = new Consumer();

            var loyaltyService = new Mock <ILoyaltyService>();

            loyaltyService.Setup(x => x.ValidateAsync(consumer));

            var consumerDAL = new Mock <IConsumerDAL>();

            consumerDAL.Setup(x => x.InsertAsync(consumer)).ReturnsAsync(expected);

            var consumerService = new ConsumerService(consumerDAL.Object, loyaltyService.Object);

            // Act
            var result = await consumerService.CreateAsync(consumer);

            // Assert
            result.Should().Be(expected);
        }
        public async Task CreateAsync_consumerValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var consumer = new ConsumerUpdateModel();
            var expected = fixture.Create <string>();

            var loyaltyService = new Mock <ILoyaltyService>();

            loyaltyService
            .Setup(x => x.ValidateAsync(consumer))
            .Throws(new InvalidOperationException(expected));

            var consumerDAL = new Mock <IConsumerDAL>();

            var consumerService = new ConsumerService(consumerDAL.Object, loyaltyService.Object);

            var action = new Func <Task>(() => consumerService.CreateAsync(consumer));

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

            consumerDAL.Verify(x => x.InsertAsync(consumer), Times.Never);
        }
Example #5
0
        public async Task <Consumer> UpdateAsync(ConsumerUpdateModel consumer)
        {
            await this.LoyaltyService.ValidateAsync(consumer);

            return(await this.ConsumerDAL.UpdateAsync(consumer));
        }