Skip to content

Commit

Permalink
Added restful work related to conventions and so forth
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Jul 3, 2020
1 parent 9ed8b38 commit 2e53cfb
Show file tree
Hide file tree
Showing 91 changed files with 2,312 additions and 772 deletions.
37 changes: 23 additions & 14 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="Roslynator.Analyzers" Version="2.3.0"/>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="GitVersion.Tool" Version="5.3.6"/>
<PackageVersion Include="GitVersion.Tool" Version="5.3.7"/>
<PackageVersion Include="JetBrains.ReSharper.CommandLineTools" Version="2020.1.3"/>
<PackageVersion Include="Nuke.Common" Version="0.25.0-alpha0292"/>
<PackageVersion Include="ReportGenerator" Version="4.6.1"/>
Expand All @@ -23,20 +23,22 @@
<PackageVersion Include="App.Metrics.AppNetCore" Version="4.1.0"/>
<PackageVersion Include="App.Metrics.AspNetCore" Version="4.1.0"/>
<PackageVersion Include="App.Metrics.Extensions.HealthChecks" Version="4.1.0"/>
<PackageVersion Include="AutoMapper" Version="9.0.0"/>
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0"/>
<PackageVersion Include="FluentValidation" Version="8.6.2"/>
<PackageVersion Include="FluentValidation.AspNetCore" Version="8.6.2"/>
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="8.6.2"/>
<PackageVersion Include="Hellang.Middleware.ProblemDetails" Version="5.1.0" />
<PackageVersion Include="Humanizer.Core" Version="2.8.26"/>
<PackageVersion Include="MediatR" Version="8.0.1"/>
<PackageVersion Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0"/>
<PackageVersion Include="MediatR" Version="8.0.2"/>
<PackageVersion Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.1"/>
<PackageVersion Include="MicroElements.Swashbuckle.FluentValidation" Version="3.2.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0"/>
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="3.1.0"/>
<PackageVersion Include="Microsoft.Extensions.Logging" Version="3.1.0"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0"/>
<PackageVersion Include="Microsoft.Extensions.Options" Version="3.1.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="3.1.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="3.1.5"/>
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="3.1.5"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="3.1.5"/>
<PackageVersion Include="Microsoft.Extensions.Options" Version="3.1.5"/>
<PackageVersion Include="Microsoft.Reactive.Testing" Version="4.4.1"/>
<PackageVersion Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageVersion Include="NodaTime" Version="3.0.0"/>
Expand All @@ -47,14 +49,21 @@
<PackageVersion Include="Rocket.Surgery.Conventions" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Conventions.Abstractions" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Conventions.Attributes" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.DependencyInjection.Extensions" Version="2.3.1"/>
<PackageVersion Include="Rocket.Surgery.Extensions" Version="2.3.1"/>
<PackageVersion Include="Rocket.Surgery.Conventions.AutoMapper" Version="8.0.0-beta.2" />
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration.Json" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration.Yaml" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Extensions.Serilog" Version="11.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.DependencyInjection.Extensions" Version="2.5.0"/>
<PackageVersion Include="Rocket.Surgery.Extensions" Version="2.5.0"/>
<PackageVersion Include="Rocket.Surgery.Hosting" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.Hosting.Abstractions" Version="10.0.0-beta.2"/>
<PackageVersion Include="Rocket.Surgery.System" Version="2.3.1"/>
<PackageVersion Include="Rocket.Surgery.System" Version="2.5.0"/>
<PackageVersion Include="Scrutor" Version="3.2.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="5.5.1"/>
<PackageVersion Include="Swashbuckle.AspNetCore.ReDoc" Version="5.5.1"/>
<PackageVersion Include="Swashbuckle.AspNetCore.Filters" Version="5.1.2"/>
<PackageVersion Include="SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime" Version="1.3.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1"/>
<PackageVersion Include="System.Interactive" Version="4.1.1"/>
<PackageVersion Include="System.Interactive.Async" Version="4.1.1"/>
Expand All @@ -71,7 +80,7 @@
<PackageVersion Include="FluentAssertions" Version="5.10.3"/>
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.11.4"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.6.1"/>
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="5.1.1"/>
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="5.2.0"/>
<PackageVersion Include="xunit" Version="2.4.1"/>
<PackageVersion Include="xunit.analyzers" Version="0.10.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.2"/>
Expand Down
45 changes: 45 additions & 0 deletions LaunchPad.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extensions.Tests", "test\Ex
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D65A8130-6A58-4693-A96C-8C1DFA3CA355}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.LaunchPad.Hosting", "src\Hosting\Rocket.Surgery.LaunchPad.Hosting.csproj", "{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Core", "sample\Sample.Core\Sample.Core.csproj", "{FD33372B-4D2E-4F22-A866-6E01C2451FA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.LaunchPad.EntityFramework", "src\EntityFramework\Rocket.Surgery.LaunchPad.EntityFramework.csproj", "{2A39A833-558C-4054-8CEB-9293AEA38E18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -233,6 +239,42 @@ Global
{75C55F46-7422-4E00-B41B-0DB5593B4641}.Release|x64.Build.0 = Release|Any CPU
{75C55F46-7422-4E00-B41B-0DB5593B4641}.Release|x86.ActiveCfg = Release|Any CPU
{75C55F46-7422-4E00-B41B-0DB5593B4641}.Release|x86.Build.0 = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|x64.ActiveCfg = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|x64.Build.0 = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|x86.ActiveCfg = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Debug|x86.Build.0 = Debug|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|Any CPU.Build.0 = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|x64.ActiveCfg = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|x64.Build.0 = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|x86.ActiveCfg = Release|Any CPU
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F}.Release|x86.Build.0 = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|x64.ActiveCfg = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|x64.Build.0 = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|x86.ActiveCfg = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Debug|x86.Build.0 = Debug|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|Any CPU.Build.0 = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|x64.ActiveCfg = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|x64.Build.0 = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|x86.ActiveCfg = Release|Any CPU
{FD33372B-4D2E-4F22-A866-6E01C2451FA4}.Release|x86.Build.0 = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|x64.ActiveCfg = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|x64.Build.0 = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Debug|x86.Build.0 = Debug|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|Any CPU.Build.0 = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|x64.ActiveCfg = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|x64.Build.0 = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|x86.ActiveCfg = Release|Any CPU
{2A39A833-558C-4054-8CEB-9293AEA38E18}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -256,5 +298,8 @@ Global
{A8F0A232-3C70-4C9F-B35F-18B33D60D989} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1}
{75C55F46-7422-4E00-B41B-0DB5593B4641} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1}
{166F1873-4CAE-4F54-88B6-5FE79678846B} = {D65A8130-6A58-4693-A96C-8C1DFA3CA355}
{8BBD24E1-DE43-414A-A0F3-5B8CC125D97F} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{FD33372B-4D2E-4F22-A866-6E01C2451FA4} = {5D11C19B-E8E4-4CE3-9C8A-1D368578EBCB}
{2A39A833-558C-4054-8CEB-9293AEA38E18} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion nukeeper.settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"age": "0",
"exclude": "^(Microsoft.AspNetCore.*|Microsoft.Extensions.*)"
"exclude": ""
}
12 changes: 12 additions & 0 deletions sample/Sample.Command/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Sample.Command
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
1 change: 1 addition & 0 deletions sample/Sample.Command/Sample.Command.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Commands\Rocket.Surgery.LaunchPad.Commands.csproj" />
</ItemGroup>
</Project>
78 changes: 78 additions & 0 deletions sample/Sample.Core/DataGenerationConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Bogus.Extensions;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.DependencyInjection;
using Sample.Core;
using Sample.Core.Domain;

[assembly: Convention(typeof(DataGenerationConvention))]
[assembly: Convention(typeof(DataConvention))]

namespace Sample.Core
{
public class DataGenerationConvention : IServiceConvention
{

public void Register(IServiceConventionContext context)
{
context.Services.AddHostedService<HostedService>();
}

class HostedService : IHostedService
{
private readonly IServiceProvider _serviceProvider;

public HostedService(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

public async Task StartAsync(CancellationToken cancellationToken)
{
await _serviceProvider.WithScoped<RocketDbContext>().Invoke(
async dbContext =>
{
await dbContext.Database.EnsureCreatedAsync(cancellationToken).ConfigureAwait(false);
// await dbContext.Database.MigrateAsync(cancellationToken).ConfigureAwait(false);
}
).ConfigureAwait(false);
await _serviceProvider.WithScoped<RocketDbContext>().Invoke(
async dbContext =>
{
var rocketFaker = new RocketFaker();
var rockets = rocketFaker.GenerateBetween(10, 100);
var launchFaker = new LaunchRecordFaker(rockets);

var launches = launchFaker.GenerateBetween(100, 1000);

await dbContext.Rockets.AddRangeAsync(rockets, cancellationToken).ConfigureAwait(false);
await dbContext.LaunchRecords.AddRangeAsync(launches, cancellationToken).ConfigureAwait(false);
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
).ConfigureAwait(false);
}

public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

class DataConvention : IServiceConvention
{
public void Register(IServiceConventionContext context)
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
context.Services
.AddDbContext<RocketDbContext>(x => x
.EnableDetailedErrors()
.EnableSensitiveDataLogging()
.EnableServiceProviderCaching()
.UseSqlite(connection)
);
}
}
}
36 changes: 36 additions & 0 deletions sample/Sample.Core/Domain/LaunchRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using NodaTime;
using Rocket.Surgery.LaunchPad.EntityFramework;

namespace Sample.Core.Domain
{
public class LaunchRecord
{
public Guid Id { get; set; }

public string Partner { get; set; } = null!;
public string Payload { get; set; } = null!;
public long PayloadWeightKg { get; set; }
public DateTimeOffset? ActualLaunchDate { get; set; }
public DateTimeOffset ScheduledLaunchDate { get; set; }

public Guid RocketId { get; set; }
public ReadyRocket ReadyRocket { get; set; } = null!;

class Configure : ConfigureEntityType<LaunchRecord>
{
protected override void OnEntityCreating(DbContext context, ModelBuilder modelBuilder, EntityTypeBuilder<LaunchRecord> builder)
{
builder.HasKey(x => x.Id);
}
}
}
}
26 changes: 26 additions & 0 deletions sample/Sample.Core/Domain/ReadyRocket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rocket.Surgery.LaunchPad.EntityFramework;

namespace Sample.Core.Domain
{
public class ReadyRocket
{
public Guid Id { get; set; }
public string SerialNumber { get; set; } = null!;
public RocketType Type { get; set; }

public IEnumerable<LaunchRecord> LaunchRecords { get; set; }

class Configure : ConfigureEntityType<ReadyRocket>
{
protected override void OnEntityCreating(DbContext context, ModelBuilder modelBuilder, EntityTypeBuilder<ReadyRocket> builder)
{
builder.HasKey(x => x.Id);
builder.ToTable("Rockets");
}
}
}
}
19 changes: 19 additions & 0 deletions sample/Sample.Core/Domain/RocketDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Rocket.Surgery.LaunchPad.EntityFramework;

namespace Sample.Core.Domain
{
public class RocketDbContext : LpContext<RocketDbContext>
{
public RocketDbContext(
DbContextOptions<RocketDbContext> options,
[NotNull] [ItemNotNull] IEnumerable<IOnConfiguringDbContext> configurationHandlers,
[NotNull] [ItemNotNull] IEnumerable<IOnModelCreating> modelCreationHandlers
) : base(options, configurationHandlers, modelCreationHandlers) { }

public DbSet<ReadyRocket> Rockets { get; set; } = null!;
public DbSet<LaunchRecord> LaunchRecords { get; set; } = null!;
}
}
9 changes: 9 additions & 0 deletions sample/Sample.Core/Domain/RocketType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Sample.Core.Domain
{
public enum RocketType
{
Falcon9,
FalconHeavy,
AtlasV
}
}
23 changes: 23 additions & 0 deletions sample/Sample.Core/LaunchRecordFaker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;
using Bogus;
using Bogus.Extensions;
using Sample.Core.Domain;

namespace Sample.Core
{
class LaunchRecordFaker : Faker<LaunchRecord>
{
public LaunchRecordFaker(List<Sample.Core.Domain.ReadyRocket> rockets)
{
RuleFor(x => x.Id, x => x.Random.Guid());
RuleFor(x => x.Partner, x => x.Company.CompanyName());
RuleFor(x => x.ReadyRocket, x => x.PickRandom(rockets.AsEnumerable()));
RuleFor(x => x.RocketId, (f, v) => v.ReadyRocket.Id);
RuleFor(x => x.ActualLaunchDate, f => f.Date.PastOffset().OrNull(f, 0.2f));
RuleFor(x => x.ScheduledLaunchDate, (f, v) => f.Date.PastOffset(refDate: v.ActualLaunchDate));
RuleFor(x => x.PayloadWeightKg, f => f.Random.Number(100, 1000000));
RuleFor(x => x.Payload, f => f.Lorem.Paragraphs(3));
}
}
}
Loading

0 comments on commit 2e53cfb

Please sign in to comment.