Пример #1
0
        public async Task CreateTransactionTypeAsync_Returns_New_GetTransactionTypeDto()
        {
            //Arrange
            _fixture.MockTransactionTypeService.Setup(x => x.AddTransactionTypeAsync(It.IsAny <TransactionType>()))
            .ReturnsAsync(_fixture.CreatedNewTransactionType);

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

            //Act
            var result = await repository.CreateTransactionTypeAsync(_fixture.CreateTransactionTypeDto);

            //Assert
            result.Should().BeOfType(typeof(GetTransactionTypeDto));
            result.Id.Should().Be(6);
            result.Type.Should().Be(_fixture.CreateTransactionTypeDto.Type);
        }
Пример #2
0
        public async Task CreateTransactionTypeAsync_Throws_ConflictException()
        {
            //Arrange
            _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.CreateTransactionTypeAsync(new CreateTransactionTypeDto {
                Type = "Food"
            }));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict);
            exception.ErrorMessage.Should().Be("Transaction type \"Food\" is already available.");
            exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString());
        }