예제 #1
0
        public async Task CreateAsync_Should_Throw_Exception_If_List_Does_Not_Exist_Anymore()
        {
            // Arrange
            var createTodoItemModel = Builder <CreateTodoItemModel> .CreateNew().Build();

            _todoListRepository.GetAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).ReturnsNull();

            // Act
            Func <Task> callCreateAsync = async() => await _sut.CreateAsync(createTodoItemModel);

            // Assert
            callCreateAsync.Should().Throw <NotFoundException>().WithMessage("List does not exist anymore");
            await _todoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());
        }
    public async Task CreateAsync_Should_Add_New_Entity_To_Database()
    {
        // Arrange
        var createTodoItemModel = Builder <CreateTodoItemModel> .CreateNew().Build();

        var todoList = Builder <TodoList> .CreateNew().Build();

        var todoItem = Builder <TodoItem> .CreateNew().With(ti => ti.Id = Guid.NewGuid()).Build();

        TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList);
        TodoItemRepository.AddAsync(Arg.Any <TodoItem>()).Returns(todoItem);

        // Act
        var result = await _sut.CreateAsync(createTodoItemModel);

        // Assert
        result.Id.Should().Be(todoItem.Id);
        await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());

        await TodoItemRepository.Received().AddAsync(Arg.Any <TodoItem>());
    }