Beispiel #1
0
        public async void ShouldThrowException_WhenCreatingListWithNonUniqueTitle()
        {
            // Arrange
            var createdListId = await _fixture.SendAsync(new CreateTodoListCommand
            {
                Title = "Shopping"
            });

            var createdEntity = await _fixture.FindAsync <TodoList>(createdListId);

            createdEntity.ShouldNotBeNull();

            // Act
            var exception = (ValidationException)await Record.ExceptionAsync(async() =>
            {
                var result = await _fixture.SendAsync(new CreateTodoListCommand
                {
                    Title = "Shopping"
                });
            });

            // Assert
            exception.ShouldBeOfType <ValidationException>();
            exception.Message.ShouldContain("One or more validation failures have occurred.");

            var errors = exception.Errors;

            errors.ShouldNotBeNull();

            errors.TryGetValue("Title", out string[] errorText);
            errorText.ShouldNotBeNull();
            errorText.Count().ShouldBe(1);
            errorText[0].ShouldBe("The specified title already exists.");
        }
        //[Fact]
        public async void ShouldReturnAllListsAndItems()
        {
            var createdId = await _fixture.AddAsync(new TodoList
            {
                Title = "Shopping 30/10/2020",
                Items =
                {
                    new TodoItem {
                        Title = "Apples"
                    },
                    new TodoItem {
                        Title = "Milk"
                    },
                    new TodoItem {
                        Title = "Bread"
                    },
                    new TodoItem {
                        Title = "Toilet paper"
                    },
                    new TodoItem {
                        Title = "Pasta"
                    },
                    new TodoItem {
                        Title = "Tissues"
                    },
                    new TodoItem {
                        Title = "Tuna"
                    }
                }
            });

            var confirmCreation = await _fixture.FindAsync <TodoList>(createdId);

            confirmCreation.ShouldNotBeNull();

            var query = new GetTodosQuery();

            var result = await _fixture.SendAsync(query);

            var createdList = result.Lists.Single(x => x.Title == "Shopping 30/10/2020");

            createdList.ShouldNotBeNull();
            createdList.Items.Count.ShouldBe(7);
        }
Beispiel #3
0
        public async void ShouldDeleteList_WhenItExistsInTheDatabase()
        {
            // Arrange
            var listId = await _fixture.SendAsync(new CreateTodoListCommand
            {
                Title = "List to Delete"
            });

            // Act
            await _fixture.SendAsync(new DeleteTodoListCommand
            {
                Id = listId
            });

            // Assert
            var list = await _fixture.FindAsync <TodoList>(listId);

            list.ShouldBeNull();
        }
Beispiel #4
0
        public async void ShouldUpdateTodoList_WhenValidListIsSentIn()
        {
            var userId = await _fixture.RunAsDefaultUserAsync();

            var listId = await _fixture.SendAsync(new CreateTodoListCommand
            {
                Title = "New List 17:25"
            });

            var command = new UpdateTodoListCommand
            {
                Id    = listId,
                Title = "Updated List Title 17:25"
            };

            await _fixture.SendAsync(command);

            var list = await _fixture.FindAsync <TodoList>(listId);

            list.Title.ShouldBe(command.Title);
            list.LastModified.ShouldNotBeNull();
        }