Skip to content

Commit

Permalink
tests opened, postgresql connected
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHodicBringauto committed Mar 22, 2023
1 parent 9c646de commit 3cff959
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 3 deletions.
3 changes: 3 additions & 0 deletions BE/Artin.BringAuto.DAL/Artin.BringAuto.DAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="5.0.16" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion BE/Artin.BringAuto.Mappings/Artin.BringAuto.Mappings.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="Npgsql" Version="5.0.16" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions BE/Artin.BringAuto/Artin.BringAuto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="5.0.16" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
Expand Down
1 change: 1 addition & 0 deletions BE/Artin.BringAuto/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddDbContext<DAL.BringAutoDbContext>(opt =>
{
opt.UseSqlServer(Configuration.GetValue<string>("ConnectionStrings:BringAuto"));
//opt.UseNpgsql(Configuration.GetValue<string>("ConnectionStrings:BringAuto"));
opt.EnableSensitiveDataLogging();
}, ServiceLifetime.Transient);
services.AddAutoMapper(typeof(Artin.BringAuto.Mappings.CarMap).Assembly);
Expand Down
10 changes: 8 additions & 2 deletions BE/BringAuto.Industrial.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
# Visual Studio Version 17
VisualStudioVersion = 17.5.33414.496
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artin.BringAuto", "Artin.BringAuto\Artin.BringAuto.csproj", "{73C1C8A1-8F0C-496B-9BDE-B6DC4907F2F1}"
EndProject
Expand All @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artin.BringAuto.MQTTClient"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artin.BringAuto.MQTT.Api", "Artin.BringAuto.MQTT\Artin.BringAuto.MQTT.Api.csproj", "{0A1F2D30-7270-42D2-8D53-DFC226F46621}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artin.BringAuto.Test", "Test\Artin.BringAuto.Test.csproj", "{76DA92F9-2CD9-454A-9C38-C88355A5043D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{0A1F2D30-7270-42D2-8D53-DFC226F46621}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A1F2D30-7270-42D2-8D53-DFC226F46621}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A1F2D30-7270-42D2-8D53-DFC226F46621}.Release|Any CPU.Build.0 = Release|Any CPU
{76DA92F9-2CD9-454A-9C38-C88355A5043D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76DA92F9-2CD9-454A-9C38-C88355A5043D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76DA92F9-2CD9-454A-9C38-C88355A5043D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76DA92F9-2CD9-454A-9C38-C88355A5043D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
28 changes: 28 additions & 0 deletions BE/Test/Artin.BringAuto.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Artin.BringAuto\Artin.BringAuto.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions BE/Test/Cars/Integrations/Cars/CarRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Artin.BringAuto.DAL.Models;
using Artin.BringAuto.Test.Cars.Integrations.Fixtures;
using BringAuto.Server.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Artin.BringAuto.Test.Cars.Integrations.Cars
{
public class CarControllerTest : IClassFixture<CarFixture>
{
private readonly CarFixture _fixture;
private readonly DbSet<Car> _entities;
private const string _modelRoute = "api/v1/cars";

public CarControllerTest(CarFixture fixture)
{
_fixture = fixture;
_entities = _fixture.DbContext.Set<Car>();
}

[Fact]
public void IsKnownCar_Not_Undertest_Test()
{

}
}
}
13 changes: 13 additions & 0 deletions BE/Test/Cars/Integrations/Fixtures/CarFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Artin.BringAuto.Test.Cars.Integrations.Fixtures
{
public class CarFixture : TestFixture
{

}
}
91 changes: 91 additions & 0 deletions BE/Test/TestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Artin.BringAuto.DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Artin.BringAuto.Test
{
public class TestFixture : IDisposable
{
public const string USERNAME = "j.hodic@fingood.cz";
public const string PASSWORD = "Abc123456789";
private readonly IServiceProvider _services;

public HttpClient HttpClient { get; set; }
public BringAutoDbContext DbContext { get; private set; }
/*
public TestFixture()
{
var hostBuilder = new HostBuilder()
.ConfigureWebHost(webHost =>
{
// Add TestServer
webHost.UseTestServer()
.UseStartup<Startup>()
.UseEnvironment(Environments.Development)
.UseConfiguration(new ConfigurationBuilder()
.AddJsonFile("appsettings.Development.json")
.Build()
);
// configure the services after the startup has been called.
webHost.ConfigureTestServices(services =>
{
// register the test one specifically
services.SwapSqLiteDbContext<BringAutoDbContext>();
SetServices(services);
});
});
var host = hostBuilder.Start();
_services = host.Services;
HttpClient = host.GetTestClient();
DbContext = GetService<IDbContextResolver>().GetContext() as BringAutoDbContext;
// Init DB
CreateDatabase();
}
public void ReloadContext()
{
DbContext = new BringAutoDbContext(GetService<DbContextOptions<BringAutoDbContext>>());
}
*/
public virtual void CreateDatabase()
=> DbContext.Database.EnsureCreated();

public IServiceProvider GetServices() => _services;
public T GetService<T>() => (T)_services.GetService(typeof(T));

protected virtual void SetServices(IServiceCollection serviceCollection) { }

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (HttpClient != null)
{
HttpClient.Dispose();
HttpClient = null;
}
}
}
}

}
11 changes: 11 additions & 0 deletions BE/Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Artin.Bringauto.Test
{
public class UnitTest1
{
[Fact]
public void Test1()
{

}
}
}
1 change: 1 addition & 0 deletions BE/Test/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;

0 comments on commit 3cff959

Please sign in to comment.