Skip to content

Commit

Permalink
Rafactored test classes and config
Browse files Browse the repository at this point in the history
Removed duplicate ExceptionHandlingMiddleware
Upgraded Marten
  • Loading branch information
oskardudycz committed Jul 20, 2021
1 parent b8b901c commit 87205ba
Show file tree
Hide file tree
Showing 47 changed files with 61 additions and 355 deletions.
2 changes: 1 addition & 1 deletion CQRS.Tests/CQRS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
Expand Down
7 changes: 4 additions & 3 deletions Core.Marten/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Marten.Events.Daemon.Resiliency;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Weasel.Core;
using Weasel.Postgresql;

namespace Core.Marten
Expand Down Expand Up @@ -41,10 +42,10 @@ public static IServiceCollection AddMarten(this IServiceCollection services, ICo
})
.InitializeStore();

if (martenConfig.ShouldRecreateDatabase)
documentStore.Advanced.Clean.CompletelyRemoveAll();
if (martenConfig.ShouldRecreateDatabase)
documentStore.Advanced.Clean.CompletelyRemoveAll();

documentStore.Schema.ApplyAllConfiguredChangesToDatabase();
documentStore.Schema.ApplyAllConfiguredChangesToDatabase();

return services;
}
Expand Down
2 changes: 1 addition & 1 deletion Core.Marten/Core.Marten.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="3.2.0" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion Core.Tests/Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="SharpTestsEx" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
Expand Down
2 changes: 1 addition & 1 deletion Marten.Integration.Tests/Marten.Integration.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
Expand Down
2 changes: 1 addition & 1 deletion MediatR.Tests/MediatR.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions Sample/AsyncProjections/SmartHome.Api/SmartHome.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core.WebApi\Core.WebApi.csproj" />
<ProjectReference Include="..\SmartHome.Temperature\SmartHome.Temperature.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Sample/AsyncProjections/SmartHome.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Core;
using Core.WebApi.Middlewares.ExceptionHandling;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Converters;
using SmartHome.Api.Exceptions;
using SmartHome.Temperature;

namespace SmartHome.Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public RequestPaymentsTestsTests(RequestPaymentsTestsFixture fixture)

[Fact]
[Trait("Category", "Acceptance")]
public async Task CreateCommand_ShouldReturn_CreatedStatus_With_PaymentId()
public async Task RequestPayment_ShouldReturn_CreatedStatus_With_PaymentId()
{
var commandResponse = fixture.CommandResponse;
commandResponse.EnsureSuccessStatusCode();
Expand All @@ -52,7 +52,7 @@ public async Task CreateCommand_ShouldReturn_CreatedStatus_With_PaymentId()

[Fact]
[Trait("Category", "Acceptance")]
public async Task CreateCommand_ShouldPublish_PaymentInitializedEvent()
public async Task RequestPayment_ShouldPublish_PaymentInitializedEvent()
{
var createdId = await fixture.CommandResponse.GetResultFromJson<Guid>();

Expand All @@ -68,7 +68,7 @@ public async Task CreateCommand_ShouldPublish_PaymentInitializedEvent()

// [Fact]
// [Trait("Category", "Acceptance")]
// public async Task CreateCommand_ShouldCreate_Payment()
// public async Task RequestPayment_ShouldCreate_Payment()
// {
// var createdId = await fixture.CommandResponse.GetResultFromJSON<Guid>();
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace Shipments.Api.Tests.Packages
{
public class SendPackageFixture: ApiFixture<Startup>
{
protected override string ApiUrl { get; } = "/api/Shipments";
protected override string ApiUrl => "/api/Shipments";

public readonly Guid OrderId = Guid.NewGuid();

public readonly DateTime TimeBeforeSending = DateTime.UtcNow;

public readonly List<ProductItem> ProductItems = new List<ProductItem>
public readonly List<ProductItem> ProductItems = new()
{
new ProductItem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
"System": "Information",
"Microsoft": "Information"
}
},
"ConnectionStrings": {
"ClientsDatabase": "PORT = 5432; HOST = localhost; TIMEOUT = 15; POOLING = True; MINPOOLSIZE = 1; MAXPOOLSIZE = 100; COMMANDTIMEOUT = 20; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'"
}
}
10 changes: 7 additions & 3 deletions Sample/ECommerce/Shipments/Shipments/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ public static IServiceCollection AddShipmentsModule(this IServiceCollection serv
private static IServiceCollection AddEntityFramework(this IServiceCollection services, IConfiguration config)
{
return services.AddDbContext<ShipmentsDbContext>(
options => options.UseNpgsql(config.GetConnectionString("ShipmentsDatabase")));
options => options.UseNpgsql("name=ConnectionStrings:ShipmentsDatabase"));
}

public static void ConfigureShipmentsModule(this IServiceProvider serviceProvider)
{
// Kids, don't try this at production
serviceProvider.GetRequiredService<ShipmentsDbContext>().Database.Migrate();
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";

if (environment == "Development")
{
serviceProvider.GetRequiredService<ShipmentsDbContext>().Database.Migrate();
}
}
}
}
10 changes: 9 additions & 1 deletion Sample/ECommerce/Shipments/Shipments/Shipments.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Core\Core.csproj" />
</ItemGroup>
Expand All @@ -17,9 +21,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Shipments.Storage;

namespace EventSourcing.Sample.Clients.Storage
namespace Shipments.Storage
{
internal class ClientsDbContextFactory: IDesignTimeDbContextFactory<ShipmentsDbContext>
internal class ShipmentsDbContextFactory: IDesignTimeDbContextFactory<ShipmentsDbContext>
{
public ClientsDbContextFactory()
public ShipmentsDbContextFactory()
{
}

Expand All @@ -27,9 +26,9 @@ public ShipmentsDbContext CreateDbContext(string[] args)
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: false)
//.AddEnvironmentVariables()
.AddEnvironmentVariables()
.Build()
.GetConnectionString("ClientsDatabase");
.GetConnectionString("ShipmentsDatabase");

optionsBuilder.UseNpgsql(connectionString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.7" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
Expand All @@ -37,10 +37,4 @@
<ProjectReference Include="..\MeetingsManagement.Api\MeetingsManagement.Api.csproj" />
<ProjectReference Include="..\MeetingsManagement\MeetingsManagement.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="JsonNet.PrivateSettersContractResolvers" Version="1.0.0" />
<PackageReference Include="Marten" Version="4.0.0-rc.2" />
<PackageReference Include="Marten" Version="4.0.0-rc.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
Expand Down
Loading

0 comments on commit 87205ba

Please sign in to comment.