public async Task GetPaymentTypeAsync_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))); var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.GetPaymentTypeAsync(id)); //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 GetPaymentTypeAsync_Returns_GetPaymentTypeDto() { //Arrange var id = 1; _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))); var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object); //Act var result = await repository.GetPaymentTypeAsync(id); //Assert result.Should().BeOfType(typeof(GetPaymentTypeDto)); result.Id.Should().Be(id); result.Name.Should().Be("Cash"); result.CreditPeriod.Should().Be(0); }