コード例 #1
0
        public async void ShouldThrowException_WhenTitleIsInvalid(string title)
        {
            // Arrange
            var command = new CreateBookCommand
            {
                Title = title
            };

            // Act
            var exception = (ValidationException)await Record.ExceptionAsync(async() =>
            {
                var result = await _fixture.SendAsync(command);
            });

            // 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("Cannot create a book without a title");
        }
コード例 #2
0
        public async void ShouldReturnPriorityLevels()
        {
            // Arrange
            var query = new GetTodosQuery();

            // Act
            var result = await _fixture.SendAsync(query);

            // Assert
            result.PriorityLevels.ShouldNotBeEmpty();
        }
コード例 #3
0
        public async void ShouldReturnAllBooksFromTheRepository()
        {
            // Arrange
            var bookToCreate = new Book
            {
                Title  = "The wind in the willows",
                ISBN10 = "1515151515"
            };

            var createdId = await _fixture.AddAsync(bookToCreate);

            var query = new GetBooksQuery();

            // Act
            var result = await _fixture.SendAsync(query);

            // Assert
            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);

            var createdBook = result.Single(x => x.Id == createdId);

            createdBook.ShouldNotBeNull();
            createdBook.ISBN10.ShouldBe("1515151515");
            createdBook.Title.ShouldBe("The wind in the willows");
        }
コード例 #4
0
        public async void ShouldThrowException_WhenTryingToDeleteListThatDoesNotExist()
        {
            // Arrange
            var command = new DeleteTodoListCommand {
                Id = 99
            };

            // Act
            var exception = await Record.ExceptionAsync(async() =>
            {
                await _fixture.SendAsync(command);
            });

            // Assert
            exception.ShouldBeOfType <NotFoundException>();
            exception.Message.ShouldContain("Entity \"TodoList\" (99) was not found.");
        }
コード例 #5
0
        public async void ShouldThrowException_WhenMinimumFiledsAreNotFilledIn()
        {
            // Arrange
            var command = new CreateTodoListCommand();

            // Act
            var exception = (ValidationException)await Record.ExceptionAsync(async() =>
            {
                await _fixture.SendAsync(command);
            });

            // 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("Title is required.");
        }
コード例 #6
0
        public async void ShouldThrowNotFoundException_WhenIdDoesNotExistInDatabase()
        {
            // Arrange
            var command = new UpdateTodoListCommand
            {
                Id    = 99,
                Title = "New Title 31/10/2020"
            };

            // Act
            var exception = await Record.ExceptionAsync(async() =>
            {
                await _fixture.SendAsync(command);
            });

            // Assert
            exception.ShouldBeOfType <NotFoundException>();
            exception.Message.ShouldContain("Entity \"TodoList\" (99) was not found.");
        }