-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/riplikash/DapperAutoData
- Loading branch information
Showing
25 changed files
with
406 additions
and
345 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Reflection; | ||
using AutoFixture; | ||
using AutoFixture.AutoMoq; | ||
using AutoFixture.Xunit2; | ||
|
||
namespace DapperAutoData.ContentFiles; | ||
|
||
/// <summary> | ||
/// Attribute used to mark a test method for AutoFixture data generation. | ||
/// </summary> | ||
public class DapperAutoDataAttribute : InlineAutoDataAttribute | ||
{ | ||
public DapperAutoDataAttribute(params object[] values) | ||
: base(new AutoFixtureMoqDataAttribute(), values) | ||
{ | ||
} | ||
|
||
public class AutoFixtureMoqDataAttribute : AutoDataAttribute | ||
{ | ||
public AutoFixtureMoqDataAttribute() | ||
: base(() => | ||
{ | ||
var fixture = new Fixture().Customize(new DefaultCustomizations()); | ||
|
||
var customizationsTypes = Assembly.GetExecutingAssembly() | ||
.GetTypes() | ||
.Where(t => typeof(IDapperProjectCustomization).IsAssignableFrom(t) && !t.IsInterface); | ||
|
||
foreach (var customizationsType in customizationsTypes) | ||
{ | ||
var customizations = (IDapperProjectCustomization)Activator.CreateInstance(customizationsType); | ||
fixture.Customize(customizations); | ||
} | ||
|
||
return fixture; | ||
}) | ||
{ | ||
} | ||
} | ||
|
||
} | ||
|
||
[AttributeUsage(AttributeTargets.Method)] | ||
public class AutoDomainDataAttribute : AutoDataAttribute | ||
{ | ||
public AutoDomainDataAttribute() | ||
: base(() => new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true })) | ||
{ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
using AutoFixture; | ||
using DapperAutoData.Generators; | ||
|
||
namespace DapperAutoData; | ||
|
||
/// <summary> | ||
/// This class is responsible for registering all the data generators in the assembly. | ||
/// It uses reflection to find all the classes that implement the IDataGenerator interface and registers them. | ||
/// It also filters out the DateTimeGenerator and DateTimeOffsetGenerator classes as they are generic and should not be registered. | ||
/// </summary> | ||
public static class DataGeneratorInstaller | ||
{ | ||
public static void Run(IFixture fixture) | ||
{ | ||
var list = System.Reflection.Assembly.GetCallingAssembly() | ||
.GetTypes() | ||
.Where(type => typeof(IDataGenerator).IsAssignableFrom(type) | ||
&& !type.IsInterface | ||
&& !type.IsAbstract | ||
&& !type.ContainsGenericParameters | ||
&& !IsSubclassOfRawGeneric(typeof(DateTimeGenerator<>), type) | ||
&& !IsSubclassOfRawGeneric(typeof(DateTimeOffsetGenerator<>), type)) | ||
.ToList(); | ||
list.ForEach(type => | ||
(Activator.CreateInstance(type) as IDataGenerator)?.RegisterGenerators(fixture)); | ||
} | ||
|
||
private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) | ||
{ | ||
while (toCheck != null && toCheck != typeof(object)) | ||
{ | ||
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; | ||
if (generic == cur) | ||
{ | ||
return true; | ||
} | ||
toCheck = toCheck.BaseType; | ||
} | ||
return false; | ||
} | ||
|
||
} |
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,17 @@ | ||
using AutoFixture; | ||
using AutoFixture.AutoMoq; | ||
|
||
namespace DapperAutoData; | ||
|
||
/// <summary> | ||
/// Class that registers the default customizations for the AutoFixture instance. | ||
/// Sets up AutoMoqCustomization and registers the data generators. | ||
/// </summary> | ||
public class DefaultCustomizations : ICustomization | ||
{ | ||
public void Customize(IFixture fixture) | ||
{ | ||
fixture.Customize(new AutoMoqCustomization() { ConfigureMembers = true }); | ||
DataGeneratorInstaller.Run(fixture); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...oData/Lib/Generators/BooleanGenerators.cs → ...rAutoData/Generators/BooleanGenerators.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
Oops, something went wrong.