-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
172 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@using Miru.Core | ||
@model MiruNext.Features.Orders.OrderList.Result | ||
|
||
<h3>Orders</h3> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@using Miru.Core | ||
@model MiruNext.Features.Todos.TodoList.Result | ||
|
||
<h3>Todos</h3> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@using Miru.Core | ||
@model TableList.Result | ||
|
||
<div class="card mb-4"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using Miru.Fabrication.FixtureConventions; | ||
|
||
namespace Miru.Fabrication | ||
|
||
namespace Miru.Fabrication; | ||
|
||
public static class ConventionExpressionExtensions | ||
{ | ||
public static class ConventionExpressionExtensions | ||
public static IfFilterExpression IfPropertyIs<TClass, TProperty>( | ||
this ConventionExpression conventionExpression, | ||
Expression<Func<TClass, TProperty>> property) | ||
{ | ||
public static IfFilterExpression IfPropertyIs<TClass, TProperty>( | ||
this ConventionExpression conventionExpression, | ||
Expression<Func<TClass, TProperty>> property) | ||
{ | ||
var accessor = Baseline.Reflection.ReflectionHelper.GetAccessor(property); | ||
var accessor = Baseline.Reflection.ReflectionHelper.GetAccessor(property); | ||
|
||
return conventionExpression.IfProperty(p => p.DeclaringType == accessor.OwnerType && | ||
p.PropertyType == accessor.PropertyType); | ||
} | ||
return conventionExpression.IfProperty(p => p.DeclaringType == accessor.OwnerType && | ||
p.PropertyType == accessor.PropertyType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
using System.Collections.ObjectModel; | ||
using Miru.Fabrication.FixtureConventions; | ||
|
||
namespace Miru.Fabrication | ||
namespace Miru.Fabrication; | ||
|
||
public static class EntityFrameworkConvention | ||
{ | ||
public static class EntityFrameworkConvention | ||
public static ConventionExpression AddEntityFramework(this ConventionExpression cfg) | ||
{ | ||
public static ConventionExpression AddEntityFramework(this ConventionExpression cfg) | ||
{ | ||
cfg.IfProperty(p => p.Name.EndsWith("Id")).Ignore(); | ||
cfg.IfProperty(p => p.Name.EndsWith("Id")).Ignore(); | ||
|
||
cfg.IfProperty(p => p.PropertyType.Implements(typeof(Collection<>)) || | ||
p.PropertyType.ImplementsGenericOf(typeof(Collection<>))).Ignore(); | ||
cfg.IfProperty(p => p.PropertyType.Implements(typeof(Collection<>)) || | ||
p.PropertyType.ImplementsGenericOf(typeof(Collection<>))).Ignore(); | ||
|
||
return cfg; | ||
} | ||
return cfg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using System; | ||
using AutoFixture; | ||
using Bogus; | ||
|
||
namespace Miru.Fabrication; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 38 additions & 45 deletions
83
src/Miru.Fabrication/FabricationServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,56 @@ | ||
using System; | ||
using AutoFixture; | ||
using Bogus; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Miru.Fabrication.FixtureConventions; | ||
namespace Miru.Fabrication; | ||
|
||
namespace Miru.Fabrication | ||
public static class FabricationServiceCollectionExtensions | ||
{ | ||
public static class FabricationServiceCollectionExtensions | ||
public static IServiceCollection AddFabrication<TFabricator>( | ||
this IServiceCollection services, | ||
Action<ConventionExpression> conventions = null) | ||
where TFabricator : Fabricator | ||
{ | ||
public static IServiceCollection AddFabrication<TFabricator>( | ||
this IServiceCollection services, | ||
Action<ConventionExpression> conventions = null) | ||
where TFabricator : Fabricator | ||
{ | ||
services.Scan(scan => scan | ||
.FromAssemblies(typeof(TFabricator).Assembly) | ||
.AddClasses(classes => classes.AssignableTo(typeof(ICustomFabricator<>))) | ||
.AsImplementedInterfaces() | ||
.As<ICustomFabricator>() | ||
.WithSingletonLifetime()); | ||
services.Scan(scan => scan | ||
.FromAssemblies(typeof(TFabricator).Assembly) | ||
.AddClasses(classes => classes.AssignableTo(typeof(ICustomFabricator<>))) | ||
.AsImplementedInterfaces() | ||
.As<ICustomFabricator>() | ||
.WithSingletonLifetime()); | ||
|
||
services.AddFabrication(conventions); | ||
services.AddFabrication(conventions); | ||
|
||
services.AddSingleton<TFabricator>(); | ||
services.ReplaceSingleton<Fabricator>(sp => sp.GetRequiredService<TFabricator>()); | ||
services.AddSingleton<TFabricator>(); | ||
services.ReplaceSingleton<Fabricator>(sp => sp.GetRequiredService<TFabricator>()); | ||
|
||
return services; | ||
} | ||
return services; | ||
} | ||
|
||
public static IServiceCollection AddFabrication( | ||
this IServiceCollection services, | ||
Action<ConventionExpression> conventions = null) | ||
{ | ||
services.AddSingleton<Faker>(); | ||
public static IServiceCollection AddFabrication( | ||
this IServiceCollection services, | ||
Action<ConventionExpression> conventions = null) | ||
{ | ||
services.AddSingleton<Faker>(); | ||
|
||
services.AddSingleton<FabricatedSession, FabricatedSession>(); | ||
services.AddSingleton<FabricatedSession, FabricatedSession>(); | ||
|
||
services.AddSingleton(sp => | ||
{ | ||
var fixture = new Fixture(); | ||
var faker = sp.GetService<Faker>(); | ||
var session = sp.GetService<FabricatedSession>(); | ||
services.AddSingleton(sp => | ||
{ | ||
var fixture = new Fixture(); | ||
var faker = sp.GetService<Faker>(); | ||
var session = sp.GetService<FabricatedSession>(); | ||
fixture.AddDefaultMiruConvention(faker); | ||
fixture.AddDefaultMiruConvention(faker); | ||
if (conventions != null) | ||
fixture.AddConvention(faker, conventions); | ||
if (conventions != null) | ||
fixture.AddConvention(faker, conventions); | ||
// TODO: better name for this builder | ||
fixture.Customizations.Add(new FabricationSpecimenBuilder(fixture, session)); | ||
// TODO: better name for this builder | ||
fixture.Customizations.Add(new FabricationSpecimenBuilder(fixture, session)); | ||
return fixture; | ||
}); | ||
return fixture; | ||
}); | ||
|
||
services.AddSingleton<FabSupport>(); | ||
services.AddSingleton<FabSupport>(); | ||
|
||
services.AddSingleton<Fabricator>(); | ||
services.AddSingleton<Fabricator>(); | ||
|
||
return services; | ||
} | ||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,68 @@ | ||
using System.Reflection; | ||
using AutoFixture; | ||
using AutoFixture.Kernel; | ||
using Miru.Domain; | ||
using Miru.Fabrication.FixtureConventions; | ||
|
||
namespace Miru.Fabrication | ||
|
||
namespace Miru.Fabrication; | ||
|
||
public class FabricationSpecimenBuilder : ISpecimenBuilder | ||
{ | ||
public class FabricationSpecimenBuilder : ISpecimenBuilder | ||
{ | ||
private readonly Fixture _fixture; | ||
private readonly FabricatedSession _session; | ||
private readonly Fixture _fixture; | ||
private readonly FabricatedSession _session; | ||
|
||
public FabricationSpecimenBuilder( | ||
Fixture fixture, | ||
FabricatedSession session) | ||
{ | ||
_fixture = fixture; | ||
_session = session; | ||
} | ||
public FabricationSpecimenBuilder( | ||
Fixture fixture, | ||
FabricatedSession session) | ||
{ | ||
_fixture = fixture; | ||
_session = session; | ||
} | ||
|
||
private bool ShouldReturnNoSpecimen(PropertyInfo propertyInfo) | ||
{ | ||
return propertyInfo.PropertyType.IsPrimitive || | ||
propertyInfo.PropertyType.IsValueType || | ||
propertyInfo.PropertyType == typeof(string); | ||
} | ||
private bool ShouldReturnNoSpecimen(PropertyInfo propertyInfo) | ||
{ | ||
return propertyInfo.PropertyType.IsPrimitive || | ||
propertyInfo.PropertyType.IsValueType || | ||
propertyInfo.PropertyType == typeof(string); | ||
} | ||
|
||
public object Create(object request, ISpecimenContext context) | ||
{ | ||
var propertyInfo = request as PropertyInfo; | ||
var typeInfo = request as TypeInfo; | ||
public object Create(object request, ISpecimenContext context) | ||
{ | ||
var propertyInfo = request as PropertyInfo; | ||
var typeInfo = request as TypeInfo; | ||
|
||
if (propertyInfo == null || ShouldReturnNoSpecimen(propertyInfo)) | ||
return new NoSpecimen(); | ||
if (propertyInfo == null || ShouldReturnNoSpecimen(propertyInfo)) | ||
return new NoSpecimen(); | ||
|
||
var propertyIsEntity = propertyInfo.PropertyType.Implements<IEntity>(); | ||
var propertyIsEntity = propertyInfo.PropertyType.Implements<IEntity>(); | ||
|
||
if (propertyIsEntity) | ||
{ | ||
var singleton = _session.GetSingleton(propertyInfo.PropertyType); | ||
if (propertyIsEntity) | ||
{ | ||
var singleton = _session.GetSingleton(propertyInfo.PropertyType); | ||
|
||
if (singleton != null) | ||
return singleton; | ||
} | ||
if (singleton != null) | ||
return singleton; | ||
} | ||
|
||
object instance; | ||
object instance; | ||
|
||
// if (propertyIsEntity) | ||
// { | ||
// MethodInfo method = _fabricator.GetType().GetMethod(nameof(Fabricator.Make)); | ||
// MethodInfo generic = method.MakeGenericMethod(propertyInfo.PropertyType); | ||
// instance = generic.Invoke(this, null); | ||
// } | ||
// else | ||
// { | ||
instance = _fixture.CreateByType(propertyInfo.PropertyType); | ||
// } | ||
// if (propertyIsEntity) | ||
// { | ||
// MethodInfo method = _fabricator.GetType().GetMethod(nameof(Fabricator.Make)); | ||
// MethodInfo generic = method.MakeGenericMethod(propertyInfo.PropertyType); | ||
// instance = generic.Invoke(this, null); | ||
// } | ||
// else | ||
// { | ||
instance = _fixture.CreateByType(propertyInfo.PropertyType); | ||
// } | ||
|
||
// var instance = _fabricator.Make(propertyInfo.PropertyType); | ||
// var instance = _fabricator.Make(propertyInfo.PropertyType); | ||
|
||
// if (instance is OmitSpecimen) | ||
// return new NoSpecimen(); | ||
// if (instance is OmitSpecimen) | ||
// return new NoSpecimen(); | ||
|
||
if (propertyIsEntity && instance != null && instance is not OmitSpecimen) | ||
_session.AddSingleton(propertyInfo.PropertyType, instance); | ||
if (propertyIsEntity && instance != null && instance is not OmitSpecimen) | ||
_session.AddSingleton(propertyInfo.PropertyType, instance); | ||
|
||
return instance; | ||
} | ||
return instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/Miru.Fabrication/FixtureConventions/ConventionExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using System; | ||
global using Baseline; | ||
global using Miru.Core; | ||
global using Miru; | ||
global using Miru.Domain; | ||
global using System.Threading; | ||
global using System.Threading.Tasks; | ||
global using System.Collections.Generic; | ||
global using AutoFixture; | ||
global using Bogus; | ||
global using System.Linq.Expressions; | ||
global using Miru.Fabrication.FixtureConventions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Miru.Fabrication; | ||
|
||
public interface ICustomFabricator | ||
|
Oops, something went wrong.