Web Application Development Tutorial - Part 4: Integration Tests

    • Entity Framework Core as the ORM provider.

    This tutorial is organized as the following parts;

    This tutorial has multiple versions based on your UI and Database preferences. We’ve prepared two combinations of the source code to be downloaded:

    Video Tutorial

    This part is also recorded as a video tutorial and .

    This part covers the server side tests. There are several test projects in the solution:

    Each project is used to test the related project. Test projects use the following libraries for testing:

    • Xunit as the main test framework.
    • as the assertion library.
    • NSubstitute as the mocking library.

    If you had created a data seed contributor as described in the , the same data will be available in your tests. So, you can skip this section. If you haven’t created the seed contributor, you can use the BookStoreTestDataSeedContributor to seed the same data to be used in the tests below.

    Add a new test class, named BookAppService_Tests in the namespace (folder) of the Acme.BookStore.Application.Tests project:

    • Should_Get_List_Of_Books test simply uses method to get and check the list of books.
    • We can safely check the book “1984” by its name, because we know that this books is available in the database since we’ve added it in the seed data.

    Add a new test that tries to create an invalid book and fails:

    The final test class should be as shown below:

    Open the Test Explorer Window (use Test -> Windows -> Test Explorer menu if it is not visible) and Run All tests:

    See the of this tutorial.