Skip to content

Commit

Permalink
Movinc Spec projects next to the actual projects they're specifying; …
Browse files Browse the repository at this point in the history
…high cohesion
  • Loading branch information
einari committed Jul 18, 2024
1 parent 5e93d9f commit d5f5c1d
Show file tree
Hide file tree
Showing 92 changed files with 230 additions and 160 deletions.
74 changes: 74 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,77 @@ csharp_style_prefer_range_operator = false:none
dotnet_diagnostic.IDE0055.severity = none
# prefere brace indentation when creating objects etc
csharp_indent_braces = false

[**/*.Specs/**/*.cs]
# Resharper specific
resharper_inconsistent_naming_highlighting = none
resharper_check_namespace_highlighting = none
resharper_unused_member_local_highlighting = none
dotnet_diagnostic.CA1001.severity = none
dotnet_diagnostic.CA1008.severity = none
dotnet_diagnostic.CA1024.severity = none
dotnet_diagnostic.CA1034.severity = none
dotnet_diagnostic.CA1051.severity = none
dotnet_diagnostic.CA1305.severity = none
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.CA1813.severity = none
dotnet_diagnostic.CA1852.severity = none
dotnet_diagnostic.CA1861.severity = none
dotnet_diagnostic.CA2000.severity = none
dotnet_diagnostic.CA2201.severity = none
dotnet_diagnostic.CA2211.severity = none
dotnet_diagnostic.CA2252.severity = none
dotnet_diagnostic.CS8600.severity = none
dotnet_diagnostic.CS8601.severity = none
dotnet_diagnostic.CS8602.severity = none
dotnet_diagnostic.CS8604.severity = none
dotnet_diagnostic.CS8632.severity = none
dotnet_diagnostic.CS8618.severity = none
dotnet_diagnostic.CS8765.severity = none
dotnet_diagnostic.CS8981.severity = none
dotnet_diagnostic.CS9113.severity = none
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.IDE0044.severity = none
dotnet_diagnostic.IDE0051.severity = none
dotnet_diagnostic.IDE0052.severity = none
dotnet_diagnostic.IDE0060.severity = none
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1116.severity = none
dotnet_diagnostic.SA1122.severity = none
dotnet_diagnostic.SA1134.severity = none
dotnet_diagnostic.SA1201.severity = none
dotnet_diagnostic.SA1202.severity = none
dotnet_diagnostic.SA1203.severity = none
dotnet_diagnostic.SA1204.severity = none
dotnet_diagnostic.SA1214.severity = none
dotnet_diagnostic.SA1303.severity = none
dotnet_diagnostic.SA1304.severity = none
dotnet_diagnostic.SA1306.severity = none
dotnet_diagnostic.SA1307.severity = none
dotnet_diagnostic.SA1311.severity = none
dotnet_diagnostic.SA1312.severity = none
dotnet_diagnostic.SA1313.severity = none
dotnet_diagnostic.SA1402.severity = none
dotnet_diagnostic.SA1500.severity = none
dotnet_diagnostic.SA1502.severity = none
dotnet_diagnostic.SA1507.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.RCS1018.severity = none
dotnet_diagnostic.RCS1036.severity = none
dotnet_diagnostic.RCS1090.severity = none
dotnet_diagnostic.RCS1163.severity = none
dotnet_diagnostic.RCS1169.severity = none
dotnet_diagnostic.RCS1202.severity = none
dotnet_diagnostic.RCS1213.severity = none
dotnet_diagnostic.RCS1225.severity = none
dotnet_diagnostic.RCS1241.severity = none
dotnet_diagnostic.MA0016.severity = none
dotnet_diagnostic.MA0036.severity = none
dotnet_diagnostic.MA0041.severity = none
dotnet_diagnostic.MA0044.severity = none
dotnet_diagnostic.MA0048.severity = none
dotnet_diagnostic.MA0069.severity = none
dotnet_diagnostic.MA0096.severity = none
dotnet_diagnostic.MA0097.severity = none
dotnet_diagnostic.MA0132.severity = none
11 changes: 3 additions & 8 deletions ApplicationModel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNET", "DotNET", "{856932
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Source\DotNET\Applications\Applications.csproj", "{AA6A18EA-D0F5-41C7-AF7D-1BD124022C71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Specifications", "Specifications", "{597AD628-3D8C-411C-899D-7A03AF4E6E2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Specifications\Applications\Applications.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications.Specs", "Source\DotNET\Applications.Specs\Applications.Specs.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog", "Source\DotNET\Serilog\Serilog.csproj", "{B2BF4443-5421-4275-A6A4-83C3E1C140B5}"
EndProject
Expand All @@ -27,9 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyGenerator", "Source\Do
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Source\DotNET\Orleans\Orleans.csproj", "{972CE865-9F7F-45D7-900C-5D81151D8105}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Specifications\Orleans\Orleans.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans.Specs", "Source\DotNET\Orleans.Specs\Orleans.Specs.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Specifications\MongoDB\MongoDB.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Specs", "Source\DotNET\MongoDB.Specs\MongoDB.Specs.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Source\DotNET\MongoDB\MongoDB.csproj", "{55CA3EF1-6CF9-4226-A3C3-89B0A654A268}"
EndProject
Expand Down Expand Up @@ -132,14 +130,11 @@ Global
GlobalSection(NestedProjects) = preSolution
{856932F6-D1D1-41CC-808B-A3741518DACC} = {CB36289F-614E-4733-B81A-74AC5658E5CB}
{AA6A18EA-D0F5-41C7-AF7D-1BD124022C71} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{B692D48E-BD85-4F12-ADE3-15F3D3A1F710} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{B2BF4443-5421-4275-A6A4-83C3E1C140B5} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{FC67C7C1-EBC1-430E-9229-BF694CC67820} = {CB36289F-614E-4733-B81A-74AC5658E5CB}
{A495F734-D1D2-453B-97BA-90FD1F95A66B} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{D25312B1-B1F7-44EA-8FBF-1910DEC9C1FA} = {A495F734-D1D2-453B-97BA-90FD1F95A66B}
{972CE865-9F7F-45D7-900C-5D81151D8105} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{A9723526-B6DA-40E6-A80A-5F566892DF45} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{55CA3EF1-6CF9-4226-A3C3-89B0A654A268} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{BE230ADD-9372-479D-9912-CB1AF36ADD0A} = {A495F734-D1D2-453B-97BA-90FD1F95A66B}
{A699BADC-5E16-4AA0-B275-3FF5B9F6BA38} = {856932F6-D1D1-41CC-808B-A3741518DACC}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageVersion Include="moq" Version="4.20.70" />
<PackageVersion Include="Microsoft.NET.Test.SDK" Version="17.10.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Samples/eCommerce/Basic/API/Products/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace API.Products;
/// Represents the catalog API.
/// </summary>
/// <param name="grainFactory"><see cref="IGrainFactory"/> for working with grains.</param>
/// <param name="catalogQueries"><see cref="ICatalogQueries"/> for working with the catalog.</param>
/// <param name="collection"><see cref="IMongoCollection{TDocument}"/> for working with products.</param>
[Route("/api/products/catalog")]
public class Catalog(IGrainFactory grainFactory, ICatalogQueries catalogQueries, IMongoCollection<Product> collection) : ControllerBase
{
Expand Down
4 changes: 3 additions & 1 deletion Samples/eCommerce/Basic/API/Products/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class Inventory : ControllerBase
/// <param name="command">The command payload.</param>
/// <returns>Awaitable task.</returns>
[HttpPost("set-stock/{sku}")]
public Task SetStockForProduct([FromRoute] SKU sku, [FromBody] SetStockForProduct command)
public Task SetStockForProduct(
[FromRoute] SKU sku,
[FromBody] SetStockForProduct command)
{
Console.WriteLine($"Setting stock for product {sku} to {command.Quantity}");
return Task.CompletedTask;
Expand Down
1 change: 0 additions & 1 deletion Samples/eCommerce/Basic/Web/Feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useIdentity } from '@cratis/applications.react/identity';
export const Feature = withViewModel(FeatureViewModel, ({ viewModel }) => {

const identity = useIdentity();

return (
<div>
<h2>Hello {`${identity.name}`} your cart id is {`${viewModel.cart.id}`} </h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../Source/DotNET/Applications/Applications.csproj"/>
<ProjectReference Include="../Applications/Applications.csproj"/>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Source/DotNET/Applications/Assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Cratis.Applications.MongoDB")]
33 changes: 31 additions & 2 deletions Source/DotNET/Applications/Internals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,42 @@ namespace Cratis.Applications;
/// </summary>
internal static class Internals
{
static IServiceProvider? _serviceProvider;
static ITypes? _types;

/// <summary>
/// Internal: The service provider.
/// </summary>
internal static IServiceProvider? ServiceProvider;
/// <exception cref="ServiceProviderNotConfigured">Thrown if the service provider has not been configured.</exception>
internal static IServiceProvider ServiceProvider
{
get
{
if (_serviceProvider == null)
{
throw new ServiceProviderNotConfigured();
}

return _serviceProvider;
}
set => _serviceProvider = value;
}

/// <summary>
/// Internal: The types.
/// </summary>
internal static ITypes? Types;
/// <exception cref="TypeDiscoverySystemNotConfigured">Thrown if the type discovery system has not been configured.</exception>
internal static ITypes Types
{
get
{
if (_types == null)
{
throw new TypeDiscoverySystemNotConfigured();
}

return _types;
}
set => _types = value;
}
}
17 changes: 17 additions & 0 deletions Source/DotNET/Applications/ServiceProviderNotConfigured.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Cratis.Applications;

/// <summary>
/// Exception that gets thrown when the service provider has not been configured.
/// </summary>
public class ServiceProviderNotConfigured : Exception
{
/// <summary>
/// Initializes a new instance of <see cref="ServiceProviderNotConfigured"/>.
/// </summary>
public ServiceProviderNotConfigured() : base("Service provider has not been configured, have you forgotten to call 'UseCratisApplicationModel()' on your application during setup?")
{
}
}
17 changes: 17 additions & 0 deletions Source/DotNET/Applications/TypeDiscoverySystemNotConfigured.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Cratis.Applications;

/// <summary>
/// Exception that gets thrown when the service provider has not been configured.
/// </summary>
public class TypeDiscoverySystemNotConfigured : Exception
{
/// <summary>
/// Initializes a new instance of <see cref="ServiceProviderNotConfigured"/>.
/// </summary>
public TypeDiscoverySystemNotConfigured() : base("Type discovery system has not been configured, have you forgotten to call 'UseCratisApplicationModel()' on your host builder during setup?")
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class ValidationMvcOptionsExtensions
/// <returns><see cref="MvcOptions"/> for building continuation.</returns>
public static MvcOptions AddValidation(this MvcOptions options, ITypes types)
{
options.ModelValidatorProviders.Add(new DiscoverableModelValidatorProvider(types, Internals.ServiceProvider!));
options.ModelValidatorProviders.Add(new DiscoverableModelValidatorProvider(types, Internals.ServiceProvider));
return options;
}
}
10 changes: 10 additions & 0 deletions Source/DotNET/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@
<None Include="$(MSBuildThisFileDirectory)/../../README.md" Pack="true" PackagePath="/"/>
<Compile Include="$(MSBuildThisFileDirectory)/GlobalAssemblyInfo.cs"/>
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)'=='true'">
<PackageReference Include="Cratis.Specifications.XUnit" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<Compile Include="$(MSBuildThisFileDirectory)/GlobalUsings.Specs.cs"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#pragma warning disable IDE0005 // Using directive is unnecessary.

global using Cratis.Specifications;
global using Cratis.Types;
global using Moq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<PropertyGroup>
<AssemblyName>Cratis.Applications.MongoDB.Specs</AssemblyName>
<RootNamespace>Cratis.Applications.MongoDB</RootNamespace>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../Source/DotNET/MongoDB/MongoDB.csproj"/>
<ProjectReference Include="../MongoDB/MongoDB.csproj"/>
</ItemGroup>
</Project>
9 changes: 6 additions & 3 deletions Source/DotNET/MongoDB/MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<AssemblyName>Cratis.Applications.MongoDB</AssemblyName>
<RootNamespace>Cratis.Applications.MongoDB</RootNamespace>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Cratis.Fundamentals" />
<PackageReference Include="polly.core" />
Expand All @@ -14,4 +14,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Applications/Applications.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit d5f5c1d

Please sign in to comment.