示例#1
0
        public async Task GetTransactionTypeAsync_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)));

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

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

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Transaction type not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }
示例#2
0
        public async Task GetTransactionTypeAsync_Returns_GetTransactionTypeDto()
        {
            //Arrange
            var id = 1;

            _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)));

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

            //Act
            var result = await repository.GetTransactionTypeAsync(id);

            //Assert
            result.Should().BeOfType(typeof(GetTransactionTypeDto));
            result.Id.Should().Be(id);
            result.Type.Should().Be("Food");
        }