示例#1
0
        public async Task DeleteTransactionTypeAsync_Returns_NoResult()
        {
            //Arrange
            var id = 2;

            _fixture.MockTransactionTypeService.Setup(x => x.GetTransactionTypeAsync(It.IsAny <Expression <Func <TransactionType, bool> > >()))
            .Returns <Expression <Func <TransactionType, bool> > >(expression => Task.FromResult(_fixture.TransactionTypes.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockTransactionTypeService.Setup(x => x.DeleteTransactionTypeAsync(It.IsAny <TransactionType>()));

            var repository = new TransactionTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockTransactionTypeService.Object);

            //Act
            await repository.DeleteTransactionTypeAsync(id);

            // Assert
            _fixture.MockTransactionTypeService.Verify(x => x.DeleteTransactionTypeAsync(It.IsAny <TransactionType>()), Times.Once);
        }
示例#2
0
        public async Task DeleteTransactionTypeAsync_Throws_NotFoundException()
        {
            //Arrange
            var id = 201;

            _fixture.MockTransactionTypeService.Setup(x => x.GetTransactionTypeAsync(It.IsAny <Expression <Func <TransactionType, bool> > >()))
            .Returns <Expression <Func <TransactionType, bool> > >(expression => Task.FromResult(_fixture.TransactionTypes.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockTransactionTypeService.Setup(x => x.DeleteTransactionTypeAsync(It.IsAny <TransactionType>()));

            var repository = new TransactionTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockTransactionTypeService.Object);

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

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