Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using FluentAssertions;
using GalaxyCheck.Configuration;
using GalaxyCheck.Internal;
using Xunit;

namespace Tests.GlobalConfigurationTests
{
public class AboutLocatingGlobalConfiguration
{
[Fact]
public void ItWorks()
{
var instance = GlobalConfiguration.Instance;

instance.DefaultIterations.Should().Be(420);
}
}

public class MyConfigureGlobal : IConfigureGlobal
{
public void Configure(IGlobalConfiguration instance)
{
instance.DefaultIterations = 420;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using GalaxyCheck.Configuration;

namespace IntegrationSample
{
internal class ConfigureGalaxyCheck : IConfigureGlobal
{
public void Configure(IGlobalConfiguration instance)
{
instance.DefaultIterations = 100;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GalaxyCheck;
using GalaxyCheck.Gens;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using Moq;
using System;
using System.Collections.Generic;
Expand All @@ -20,7 +20,12 @@ public void WhenClassNorMethodHasFactoryConfig_ItPassesThroughNull(string testMe
var testClassType = typeof(PropertiesWithoutFactoryConfig);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
mockPropertyFactory.Object,
new GlobalConfiguration());

VerifyFactoryNotPassedThrough(mockPropertyFactory);
}
Expand All @@ -34,7 +39,12 @@ public void ItPassesThroughTheFactoryFromTheMethod(string testMethodName)
var testClassType = typeof(PropertiesWithoutFactoryConfig);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
mockPropertyFactory.Object,
new GlobalConfiguration());

VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory1));
}
Expand All @@ -48,7 +58,12 @@ public void ItPassesThroughTheFactoryFromTheClass(string testMethodName)
var testClassType = typeof(PropertiesWithFactoryConfig);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
mockPropertyFactory.Object,
new GlobalConfiguration());

VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory2));
}
Expand All @@ -62,7 +77,12 @@ public void AMethodLevelFactoryIsPreferredOverAClassLevelFactory(string testMeth
var testClassType = typeof(PropertiesWithFactoryConfig);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
mockPropertyFactory.Object,
new GlobalConfiguration());

VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory1));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using System;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -35,20 +35,42 @@ public void SampleWith10Iterations()
}

[Theory]
[InlineData(nameof(Properties.PropertyWithDefaultIterations), 100)]
[InlineData(nameof(Properties.PropertyWith10Iterations), 10)]
[InlineData(nameof(Properties.SampleWithDefaultIterations), 100)]
[InlineData(nameof(Properties.SampleWith10Iterations), 10)]
public void ItPassesThroughIterations(string testMethodName, int expectedIterations)
{
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration { DefaultIterations = 999 });

result.Parameters.Iterations.Should().Be(expectedIterations);
}

[Theory]
[InlineData(nameof(Properties.PropertyWithDefaultIterations))]
[InlineData(nameof(Properties.SampleWithDefaultIterations))]
public void ItPassesThroughTheDefaultIterationsIfNotExplicitlySet(string testMethodName)
{
var defaultIterations = 1000;
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration { DefaultIterations = defaultIterations });

result.Parameters.Iterations.Should().Be(defaultIterations);
}

private static MethodInfo GetMethod(string name)
{
var methodInfo = typeof(Properties).GetMethod(name, BindingFlags.Public | BindingFlags.Instance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Gens;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using Moq;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -87,7 +87,12 @@ public void ItErrorsWhenReferencePropertyIsNotAGen(string testMethodName)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

Action test = () => PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
Action test = () => PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

test.Should()
.Throw<Exception>()
Expand All @@ -108,7 +113,12 @@ public void ItPassesThroughGen(string testMethodName)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
mockPropertyFactory.Object,
new GlobalConfiguration());

VerifyGenPassedThrough(mockPropertyFactory, Gen, 0);
}
Expand All @@ -122,7 +132,7 @@ public void ItPassesThroughGenKeyedToCorrectIndex(string testMethodName, int exp
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);
PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object, new GlobalConfiguration());

VerifyGenPassedThrough(mockPropertyFactory, Gen, expectedIndex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using System;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -46,7 +46,12 @@ public void ItPassesThroughReplay(string testMethodName, string? expectedReplay)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

result.Parameters.Replay.Should().Be(expectedReplay);
}
Expand Down
16 changes: 13 additions & 3 deletions src/GalaxyCheck.Xunit.Tests/PropertyInitializerTests/AboutSeed.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using System;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -66,7 +66,12 @@ public void ItPassesThroughSeed(string testMethodName, int expectedSeed)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

result.Parameters.Seed.Should().Be(expectedSeed);
}
Expand All @@ -81,7 +86,12 @@ public void ItDoesNotPassThroughSeed(string testMethodName)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

result.Parameters.Seed.Should().Be(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using System;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -35,20 +35,42 @@ public void SampleWith10ShrinkLimit()
}

[Theory]
[InlineData(nameof(Properties.PropertyWithDefaultShrinkLimit), 500)]
[InlineData(nameof(Properties.PropertyWith10ShrinkLimit), 10)]
[InlineData(nameof(Properties.SampleWithDefaultShrinkLimit), 500)]
[InlineData(nameof(Properties.SampleWith10ShrinkLimit), 10)]
public void ItPassesThroughShrinkLimit(string testMethodName, int expectedShrinkLimit)
{
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration() { DefaultShrinkLimit = 999 });

result.Parameters.ShrinkLimit.Should().Be(expectedShrinkLimit);
}

[Theory]
[InlineData(nameof(Properties.PropertyWithDefaultShrinkLimit))]
[InlineData(nameof(Properties.SampleWithDefaultShrinkLimit))]
public void ItPassesThroughTheDefaultShrinkLimitIfNotExplicitlySet(string testMethodName)
{
var defaultShrinkLimit = 1000;
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration { DefaultShrinkLimit = defaultShrinkLimit });

result.Parameters.ShrinkLimit.Should().Be(defaultShrinkLimit);
}

private static MethodInfo GetMethod(string name)
{
var methodInfo = typeof(Properties).GetMethod(name, BindingFlags.Instance | BindingFlags.Public);
Expand Down
16 changes: 13 additions & 3 deletions src/GalaxyCheck.Xunit.Tests/PropertyInitializerTests/AboutSize.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using GalaxyCheck;
using GalaxyCheck.Xunit.Internal;
using GalaxyCheck.Internal;
using System;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -66,7 +66,12 @@ public void ItPassesThroughSize(string testMethodName, int expectedSize)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

result.Parameters.Size.Should().Be(expectedSize);
}
Expand All @@ -81,7 +86,12 @@ public void ItDoesNotPassThroughSize(string testMethodName)
var testClassType = typeof(Properties);
var testMethodInfo = GetMethod(testMethodName);

var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());
var result = PropertyInitializer.Initialize(
testClassType,
testMethodInfo,
new object[] { },
new DefaultPropertyFactory(),
new GlobalConfiguration());

result.Parameters.Size.Should().Be(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace GalaxyCheck.Configuration
{
public class ActivateConfigureGlobalException : Exception
{
public ActivateConfigureGlobalException(Type type, Exception ex)
: base(BuildMessage(type, ex), ex)
{
}

private static string BuildMessage(Type type, Exception ex)
{
return @$"Failed to create instance of type '{type}' during global GalaxyCheck configuration.

Exception: {ex}";
}
}
}
7 changes: 7 additions & 0 deletions src/GalaxyCheck.Xunit/Configuration/IConfigureGlobal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GalaxyCheck.Configuration
{
public interface IConfigureGlobal
{
void Configure(IGlobalConfiguration instance);
}
}
15 changes: 15 additions & 0 deletions src/GalaxyCheck.Xunit/Configuration/IGlobalConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GalaxyCheck.Configuration
{
public interface IGlobalConfiguration
{
int DefaultIterations { get; set; }

int DefaultShrinkLimit { get; set; }
}
}
Loading