Skip to content

StefRuseva88/integration-tests-asp.net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ASP.NET WEB API Integration with SQL Server

C# .NET MS SQL Server Docker NUnit

This is a test project for the Back-End Technologies January 2024 Course @ SoftUni


Project Overview

This project demonstrates how to test the integration of an ASP.Net WEB API with a SQL Server database. It covers various aspects of integration testing using Entity Framework and NUnit.

Tools and Technologies

  • SQL Server: Used for database management and integration.
  • REST API: For creating and testing RESTful services.
  • Entity Framework: ORM used for managing database interactions.
  • NUnit Tests: Framework for writing unit and integration tests for .NET.
  • ASP.Net: For building and testing web applications.

Project Overview

The project under test is called "Homies", an ASP.NET application. The key components include:

  1. Homies.program.cs: This file initializes and runs the application.

    • Areas: Groups different functional segments of the application for modularity.
    • Controllers: Manages HTTP requests and responses, coordinating data flow between models and views.
    • Data: Contains the data access layer, including the database context and migrations.
    • Models: Defines the application's data structures and business logic.
    • Views: Contains the UI elements, including HTML templates and Razor views.
  2. Homies.Tests: This directory includes integration tests to verify that various components function correctly together.

    • EventControllerTests.cs: Contains tests for the Controller to verify correct request handling.
    • EventServiceTests.cs: Tests the Service, ensuring business logic and data processing work as expected.

Requirements

  • Visual Studio with ASP.NET
  • Microsoft SQL Server Management Studio (SSMS)
  • Docker (optional, for using a Docker container instead of a local SQL Server instance)
  • Local SQL Server instance

Docker Integration

You can also run the SQL Server using a Docker image, which simplifies the setup and ensures consistency across different environments. To set up SQL Server with Docker, follow these steps:

  1. Pull the SQL Server Docker image:

    docker pull mcr.microsoft.com/mssql/server
  2. Run the Docker container:

    docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Your_password123' -p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server
  3. Connect to the SQL Server:

    • Use the connection string: Server=localhost,1433;Database=YourDatabase;User Id=sa;Password=Your_password123;
    • Replace YourDatabase with the name of your database.

For more information on using Docker with SQL Server, you can refer to the official Docker documentation and the SQL Server on Docker guide.

Updating the Database

Apply Migrations In the Package Manager Console within Visual Studio, run Update-Database to apply migrations to your database.

Verifying Database Creation

Locate the Database In your SQL client, expand the 'Databases' folder. You should see a list of all databases on the server. Look for the database name specified in your ASP.NET project's connection string. If the Update-Database command executed successfully, your database should be listed there.

User Registration

Use the user authentication features provided by ASP.NET Identity to register a new user and log in to the application.

Verify Account Creation in Database

Refresh the database view, navigate to the users table (often named AspNetUsers), and verify that your new user account is listed.

Proceed with CRUD Operations

Once logged in, perform CRUD operations as an authenticated user, reflecting a more realistic use-case scenario.

Contact

For any questions or suggestions, please open an issue in the repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Happy Testing! 🚀

Releases

No releases published

Packages

No packages published