コード例 #1
0
        public async Task DeletePaymentTypeAsync_Returns_NoResult()
        {
            //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.DeletePaymentTypeAsync(It.IsAny <PaymentType>()));

            var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object);

            //Act
            await repository.DeletePaymentTypeAsync(id);

            // Assert
            _fixture.MockPaymentTypeService.Verify(x => x.DeletePaymentTypeAsync(It.IsAny <PaymentType>()), Times.Once);
        }
コード例 #2
0
        public async Task DeletePaymentTypeAsync_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.DeletePaymentTypeAsync(It.IsAny <PaymentType>()));

            var repository = new PaymentTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockPaymentTypeService.Object);

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.DeletePaymentTypeAsync(id));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Payment type not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }