public async Task UpdatePaymentTypeAsync_Throws_NotFoundException() { //Arrange var id = 201; _fixture.MockPaymentTypeService.Setup(x => x.GetPaymentTypeAsync(It.IsAny <Expression <Func <PaymentType, bool> > >())) .Returns <Expression <Func <PaymentType, bool> > >(expression => Task.FromResult(_fixture.PaymentTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockPaymentTypeService.Setup(x => x.UpdatePaymentTypeAsync(It.IsAny <PaymentType>())); var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdatePaymentTypeAsync(id, _fixture.EditPaymentTypeDto)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Payment type not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }
public async Task UpdatePaymentTypeAsync_Returns_Updated_GetPaymentTypeDto() { //Arrange var id = 2; _fixture.MockPaymentTypeService.Setup(x => x.GetPaymentTypeAsync(It.IsAny <Expression <Func <PaymentType, bool> > >())) .Returns <Expression <Func <PaymentType, bool> > >(expression => Task.FromResult(_fixture.PaymentTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockPaymentTypeService.Setup(x => x.UpdatePaymentTypeAsync(It.IsAny <PaymentType>())); var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object); //Act var result = await repository.UpdatePaymentTypeAsync(id, _fixture.EditPaymentTypeDto); //Assert result.Should().BeOfType(typeof(GetPaymentTypeDto)); result.Id.Should().Be(id); result.Name.Should().Be(_fixture.EditPaymentTypeDto.Name); result.CreditPeriod.Should().Be(_fixture.EditPaymentTypeDto.CreditPeriod); }
public async Task UpdatePaymentTypeAsync_Throws_ConflictException() { //Arrange var id = 2; _fixture.MockPaymentTypeService.Setup(x => x.GetPaymentTypeAsync(It.IsAny <Expression <Func <PaymentType, bool> > >())) .Returns <Expression <Func <PaymentType, bool> > >(expression => Task.FromResult(_fixture.PaymentTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockPaymentTypeService.Setup(x => x.UpdatePaymentTypeAsync(It.IsAny <PaymentType>())); var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdatePaymentTypeAsync(id, new EditPaymentTypeDto { Name = "Cash", CreditPeriod = 0 })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Payment type Cash is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }