Skip to content

Commit

Permalink
Add template for CustomAutoDataAttributes (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek committed Jan 21, 2021
1 parent e1640b0 commit 1d2b53a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions content/CustomAutoDataAttributes/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Insight Architectures",
"classifications": ["IA", "Testing", "AutoData"],
"name": "[IA] CustomAutoDataAttributes",
"identity": "InsightArchitectures.Templates.Items.CustomAutoDataAttributes",
"groupIdentity": "InsightArchitectures.Templates.Items.CustomAutoDataAttributes.CSharp",
"shortName": "autodata",
"tags": {
"language": "C#",
"type": "item"
},
"defaultName": "CustomAutoDataAttributes",
"description": "This templates creates a CustomAutoDataAttributes file that uses AutoFixture AutoData for NUnit3 with AutoFixture.AutoMoq"
}
39 changes: 39 additions & 0 deletions content/CustomAutoDataAttributes/CustomAutoDataAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using AutoFixture;
using AutoFixture.AutoMoq;
using AutoFixture.NUnit3;

namespace Tests
{
[AttributeUsage(AttributeTargets.Method)]
public class CustomAutoDataAttribute : AutoDataAttribute
{
public CustomAutoDataAttribute() : base(FixtureHelpers.CreateFixture)
{
}
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class CustomInlineAutoDataAttribute : InlineAutoDataAttribute
{
public CustomInlineAutoDataAttribute(params object[] args) : base(FixtureHelpers.CreateFixture, args)
{
}
}

internal static class FixtureHelpers
{
public static IFixture CreateFixture()
{
var fixture = new Fixture();

fixture.Customize(new AutoMoqCustomization
{
ConfigureMembers = true,
GenerateDelegates = true
});

return fixture;
}
}
}

0 comments on commit 1d2b53a

Please sign in to comment.