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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ public void AMethodReturningAnUnsupportedTypeThrowsTheGenericUnsupportedExceptio

test.Should()
.Throw<Exception>()
.WithMessage($"Return type is not supported by Property.Reflect. Please use one of: GalaxyCheck.IGen`1[GalaxyCheck.Test], GalaxyCheck.Property, System.Boolean, System.Void. Return type was: {typeof(MyType)}.");
.WithMessage($"Return type is not supported by Property.Reflect. Please use one of: GalaxyCheck.Property, System.Boolean, System.Void. Return type was: {typeof(MyType)}.");
}

private Task TaskMethod() => null!;
private Task<bool> TaskBoolMethod() => null!;
private AsyncProperty AsyncPropertyMethod() => null!;
private IGen<AsyncTest> IGenAsyncTestMethod() => null!;

[Theory]
[InlineData(nameof(TaskMethod))]
[InlineData(nameof(TaskBoolMethod))]
[InlineData(nameof(AsyncPropertyMethod))]
[InlineData(nameof(IGenAsyncTestMethod))]
public void AMethodReturningAnUnsupportedTypeSupportedByAsyncThrowsTheMessageWithHint(string methodName)
{
var method = GetMethod(methodName);
Expand All @@ -43,7 +41,7 @@ public void AMethodReturningAnUnsupportedTypeSupportedByAsyncThrowsTheMessageWit

test.Should()
.Throw<Exception>()
.WithMessage($"Return type is not supported by Property.Reflect. Did you mean to use Property.ReflectAsync? Otherwise, please use one of: GalaxyCheck.IGen`1[GalaxyCheck.Test], GalaxyCheck.Property, System.Boolean, System.Void. Return type was: {method.ReturnType}.");
.WithMessage($"Return type is not supported by Property.Reflect. Did you mean to use Property.ReflectAsync? Otherwise, please use one of: GalaxyCheck.Property, System.Boolean, System.Void. Return type was: {method.ReturnType}.");
}

private static MethodInfo GetMethod(string name)
Expand Down Expand Up @@ -72,7 +70,7 @@ public void AMethodReturningAnUnsupportedTypeThrowsTheGenericUnsupportedExceptio

test.Should()
.Throw<Exception>()
.WithMessage($"Return type is not supported by Property.ReflectAsync. Please use one of: GalaxyCheck.AsyncProperty, GalaxyCheck.IGen`1[GalaxyCheck.AsyncTest], GalaxyCheck.IGen`1[GalaxyCheck.Test], GalaxyCheck.Property, System.Boolean, System.Threading.Tasks.Task, System.Threading.Tasks.Task`1[System.Boolean], System.Void. Return type was: {typeof(MyType)}.");
.WithMessage($"Return type is not supported by Property.ReflectAsync. Please use one of: GalaxyCheck.AsyncProperty, GalaxyCheck.Property, System.Boolean, System.Threading.Tasks.Task, System.Threading.Tasks.Task`1[System.Boolean], System.Void. Return type was: {typeof(MyType)}.");
}
}
}
Expand Down
42 changes: 36 additions & 6 deletions src/GalaxyCheck.Tests/RendererTests/AboutUnaryExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,40 @@ public void ItCanHandleCircularReferences()
rendering.Should().Be("{ Self = <Circular reference> }");
}

public static TheoryData<object?, string> Values => new TheoryData<object?, string>
public static TheoryData<object?, object[]> TupleValues => new TheoryData<object?, object[]>
{
{ new Tuple<int, int, int>(1, 2, 3), new object[] { 1, 2, 3 } },
{ (1, 2, 3), new object[] { 1, 2, 3 } },
{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), new object[] {1, 2, 3, 4, 5, 6, 7 } },
};

[Theory]
[MemberData(nameof(TupleValues))]
public void TuplesAreExpanded(object value, object[] expectedExpandedValues)
{
var rendering = ExampleRenderer.Render(new object[] { value }).ToList();

rendering.Should().HaveCount(expectedExpandedValues.Length);
}

public static TheoryData<object?, string> TupleValueRenders => new TheoryData<object?, string>
{
{ new Tuple<int, int, int>(1, 2, 3), "(Item1 = 1, Item2 = 2, Item3 = 3)" },
{ (1, 2, 3), "(Item1 = 1, Item2 = 2, Item3 = 3)" },
{ (1, 2, 3, 4, 5, 6, 7, 8), "(Item1 = 1, Item2 = 2, Item3 = 3, Item4 = 4, Item5 = 5, Item6 = 6, Item7 = 7, Rest = ...)" },
};

[Theory]
[MemberData(nameof(TupleValueRenders))]
public void TupleExamples(object value, string expectedRendering)
{
// Pass two params to force tuple not to be unwrapped
var rendering = ExampleRenderer.Render(new object[] { value, null! }).First().Substring("[0] = ".Length);

rendering.Should().Be(expectedRendering);
}

public static TheoryData<object?, string> OtherValueRenders => new TheoryData<object?, string>
{
{ null, "null" },
{ 1, "1" },
Expand All @@ -61,16 +94,13 @@ public void ItCanHandleCircularReferences()
{ new Func<int, bool>((_) => true), "System.Func`2[System.Int32,System.Boolean]" },
{ new Func<Func<int, bool>>(() => (_) => true), "System.Func`1[System.Func`2[System.Int32,System.Boolean]]" },
{ new Action(() => { }), "System.Action" },
{ new Tuple<int, int, int>(1, 2, 3), "(Item1 = 1, Item2 = 2, Item3 = 3)" },
{ (1, 2, 3), "(Item1 = 1, Item2 = 2, Item3 = 3)" },
{ (1, 2, 3, 4, 5, 6, 7, 8), "(Item1 = 1, Item2 = 2, Item3 = 3, Item4 = 4, Item5 = 5, Item6 = 6, Item7 = 7, Rest = ...)" },
{ Operations.Create, "Create" },
{ new FaultyRecord(), "<Rendering failed>" },
};

[Theory]
[MemberData(nameof(Values))]
public void Examples(object value, string expectedRendering)
[MemberData(nameof(OtherValueRenders))]
public void OtherExamples(object value, string expectedRendering)
{
var rendering = ExampleRenderer.Render(new object[] { value }).Single();

Expand Down
5 changes: 3 additions & 2 deletions src/GalaxyCheck.Tests/RunnerTests/AssertTests/Snapshots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public void Snapshot_AssertFailure_IntLessThanEquals_BinaryProperty()
// TODO: Cross-platform consistent replay encoding
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var property =
var gen =
from x in Gen.Int32().LessThan(int.MaxValue)
from y in Gen.Int32().GreaterThan(x)
select Property.ForThese(() => x < 1000);
select (x, y);
var property = gen.ForAll(input => input.x < 1000);

Action action = () => property.Assert(seed: 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
100
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
50
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
100
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
51
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
0
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
0
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ReplayPath": [],
"Replay": "",
"Exception": null,
"PresentationalValue": [
"PresentedInput": [
0
]
},
Expand Down
20 changes: 12 additions & 8 deletions src/GalaxyCheck.Tests/RunnerTests/PrintTests/Snapshots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public void PrintUnaryProperty()
[Fact]
public void PrintBinaryProperty()
{
var property = new Property(
var gen =
from x in Gen.Int32().LessThan(int.MaxValue)
from y in Gen.Int32().GreaterThan(x)
select Property.ForThese(() => false));
select (x, y);
var property = gen.ForAll((_) => false);

var print = PrintAndCollect(property);

Expand All @@ -100,10 +101,11 @@ public void PrintUnaryListProperty()
[Fact]
public void PrintBinaryListProperty()
{
var property = new Property(
var gen =
from xs in Gen.Int32().ListOf()
from ys in Gen.Int32().ListOf().WithCountGreaterThan(xs.Count)
select Property.ForThese(() => false));
select (xs, ys);
var property = gen.ForAll((_) => false);

var print = PrintAndCollect(property);

Expand Down Expand Up @@ -145,10 +147,11 @@ public async Task PrintUnaryProperty()
[Fact]
public async Task PrintBinaryProperty()
{
var property = new AsyncProperty(
var gen =
from x in Gen.Int32().LessThan(int.MaxValue)
from y in Gen.Int32().GreaterThan(x)
select Property.ForTheseAsync(() => Task.FromResult(false)));
select (x, y);
var property = gen.ForAllAsync((_) => Task.FromResult(false));

var print = await PrintAndCollect(property);

Expand All @@ -168,10 +171,11 @@ public async Task PrintUnaryListProperty()
[Fact]
public async Task PrintBinaryListProperty()
{
var property = new AsyncProperty(
var gen =
from xs in Gen.Int32().ListOf()
from ys in Gen.Int32().ListOf().WithCountGreaterThan(xs.Count)
select Property.ForTheseAsync(() => Task.FromResult(false)));
select (xs, ys);
var property = gen.ForAllAsync((_) => Task.FromResult(false));

var print = await PrintAndCollect(property);

Expand Down
Loading