mirror of
https://github.com/bitwarden/server.git
synced 2024-12-30 18:17:36 +01:00
231eb84e69
* Turn on ImplicitUsings * Fix formatting * Run linter
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using AutoFixture;
|
|
using AutoFixture.Kernel;
|
|
|
|
namespace Bit.Test.Common.AutoFixture
|
|
{
|
|
public class BuilderWithoutAutoProperties : ISpecimenBuilder
|
|
{
|
|
private readonly Type _type;
|
|
public BuilderWithoutAutoProperties(Type type)
|
|
{
|
|
_type = type;
|
|
}
|
|
|
|
public object Create(object request, ISpecimenContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
var type = request as Type;
|
|
if (type == null || type != _type)
|
|
{
|
|
return new NoSpecimen();
|
|
}
|
|
|
|
var fixture = new Fixture();
|
|
// This is the equivalent of _fixture.Build<_type>().OmitAutoProperties().Create(request, context), but no overload for
|
|
// Build(Type type) exists.
|
|
dynamic reflectedComposer = typeof(Fixture).GetMethod("Build").MakeGenericMethod(_type).Invoke(fixture, null);
|
|
return reflectedComposer.OmitAutoProperties().Create(request, context);
|
|
}
|
|
}
|
|
public class BuilderWithoutAutoProperties<T> : ISpecimenBuilder
|
|
{
|
|
public object Create(object request, ISpecimenContext context) =>
|
|
new BuilderWithoutAutoProperties(typeof(T)).Create(request, context);
|
|
}
|
|
}
|