Skip to content

Commit

Permalink
Fixed integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanYarotsky committed Dec 24, 2023
1 parent f5a3ce3 commit db0731f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
32 changes: 31 additions & 1 deletion api/API.Integration.Tests/WebAppTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
using System.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Data.SqlClient;

namespace API.Integration.Tests;

[TestClass]
public class WebAppTests
{
private static readonly string _connectionString = new SqlConnectionStringBuilder
{
UserID = "SA",
Password = "<YourStrong@Passw0rd>",
TrustServerCertificate = true,
InitialCatalog = "Test",
ConnectTimeout = 3,
CommandTimeout = 3,
}.ToString();

private HttpClient _c;

Check warning on line 24 in api/API.Integration.Tests/WebAppTests.cs

View workflow job for this annotation

GitHub Actions / build-n-test

Non-nullable field '_c' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 24 in api/API.Integration.Tests/WebAppTests.cs

View workflow job for this annotation

GitHub Actions / build-n-test

Non-nullable field '_c' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

[TestInitialize]
public void Initialize()
{
var a = new WebApplicationFactory<Program>();
var configurationValues = new Dictionary<string, string?>
{
{ "ConnectionStrings:PlanningDb", _connectionString },
{ "AllowedCorsOrigins", "http://localhost:88" },
};

var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(configurationValues)
.Build();

var a = new WebApplicationFactory<Program>()
.WithWebHostBuilder(host =>
{
host.UseConfiguration(configuration);
});

_c = a.CreateClient();
}

Expand Down
2 changes: 2 additions & 0 deletions api/DB.Tests/UpgradeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using Dapper;
using DbUp;
using Microsoft.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -25,6 +26,7 @@ private static SqlConnection NewConnection()
[TestInitialize]
public async Task EnsureEmptyDatabase()
{
EnsureDatabase.For.SqlDatabase(_connectionString);
await using var conn = NewConnection();
var tableNames = await conn.QueryAsync<string>(@"
SELECT name
Expand Down
8 changes: 4 additions & 4 deletions api/api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Integration.Tests", "AP
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DB.Tests", "DB.Tests\DB.Tests.csproj", "{EDAAF562-175F-4553-BE01-9DCF0CDEC68E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain.Tests", "Domain.Tests\Domain.Tests.csproj", "{F12F51C1-84A6-4350-B05A-CC772AA49C3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Unit.Tests", "API.Unit.Tests\API.Unit.Tests.csproj", "{A428A631-46CA-4028-9930-9AF5E5C9B65E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1A395BD2-2B48-4447-B4EB-B6A3C9BC1FA2}"
ProjectSection(SolutionItems) = preProject
docker-compose.db.yml = docker-compose.db.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain.Tests", "Domain.Tests\Domain.Tests.csproj", "{F12F51C1-84A6-4350-B05A-CC772AA49C3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Unit.Tests", "API.Unit.Tests\API.Unit.Tests.csproj", "{A428A631-46CA-4028-9930-9AF5E5C9B65E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit db0731f

Please sign in to comment.