Skip to content

Commit

Permalink
Add extensions for occurrence constraint that reads more fluently
Browse files Browse the repository at this point in the history
Authored by @siewers, committed by @IT-VBFK
  • Loading branch information
IT-VBFK committed Dec 28, 2022
1 parent 8841e12 commit b887f5c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Src/FluentAssertions/Extensions/OccurrenceConstraintExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace FluentAssertions.Extensions;

public static class OccurrenceConstraintExtensions
{
public static OccurrenceConstraint Times(this int times)
{
return Exactly.Times(times);
}

public static OccurrenceConstraint TimesOrLess(this int times)
{
return AtMost.Times(times);
}

public static OccurrenceConstraint TimesOrMore(this int times)
{
return AtLeast.Times(times);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ namespace FluentAssertions.Extensions
public static double TotalMicroseconds(this System.TimeSpan self) { }
public static double TotalNanoseconds(this System.TimeSpan self) { }
}
public static class OccurrenceConstraintExtensions
{
public static FluentAssertions.OccurrenceConstraint Times(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrLess(this int times) { }
public static FluentAssertions.OccurrenceConstraint TimesOrMore(this int times) { }
}
}
namespace FluentAssertions.Formatting
{
Expand Down
15 changes: 15 additions & 0 deletions Tests/FluentAssertions.Specs/OccurrenceConstraintSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using FluentAssertions.Execution;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Sdk;

Expand All @@ -17,6 +18,8 @@ public class OccurrenceConstraintSpecs
{ AtLeast.Thrice(), 4 },
{ AtLeast.Times(4), 4 },
{ AtLeast.Times(4), 5 },
{ 4.TimesOrMore(), 4 },
{ 4.TimesOrMore(), 5 },
{ AtMost.Once(), 0 },
{ AtMost.Once(), 1 },
{ AtMost.Twice(), 1 },
Expand All @@ -25,17 +28,24 @@ public class OccurrenceConstraintSpecs
{ AtMost.Thrice(), 3 },
{ AtMost.Times(4), 3 },
{ AtMost.Times(4), 4 },
{ 4.TimesOrLess(), 4 },
{ 4.TimesOrLess(), 1 },
{ Exactly.Once(), 1 },
{ Exactly.Twice(), 2 },
{ Exactly.Thrice(), 3 },
{ Exactly.Times(4), 4 },
{ 4.Times(), 4 },
{ LessThan.Twice(), 1 },
{ LessThan.Thrice(), 2 },
{ LessThan.Times(4), 3 },
{ 4.TimesOrLess(), 4 },
{ 4.TimesOrLess(), 1 },
{ MoreThan.Once(), 2 },
{ MoreThan.Twice(), 3 },
{ MoreThan.Thrice(), 4 },
{ MoreThan.Times(4), 5 },
{ 4.TimesOrMore(), 4 },
{ 4.TimesOrMore(), 5 },
};

[Theory]
Expand All @@ -54,10 +64,12 @@ public void Occurrence_constraint_passes(OccurrenceConstraint constraint, int oc
{ AtLeast.Twice(), 1 },
{ AtLeast.Thrice(), 2 },
{ AtLeast.Times(4), 3 },
{ 4.TimesOrMore(), 3 },
{ AtMost.Once(), 2 },
{ AtMost.Twice(), 3 },
{ AtMost.Thrice(), 4 },
{ AtMost.Times(4), 5 },
{ 4.TimesOrLess(), 5 },
{ Exactly.Once(), 0 },
{ Exactly.Once(), 2 },
{ Exactly.Twice(), 1 },
Expand All @@ -66,12 +78,14 @@ public void Occurrence_constraint_passes(OccurrenceConstraint constraint, int oc
{ Exactly.Thrice(), 4 },
{ Exactly.Times(4), 3 },
{ Exactly.Times(4), 5 },
{ 4.Times(), 1 },
{ LessThan.Twice(), 2 },
{ LessThan.Twice(), 3 },
{ LessThan.Thrice(), 3 },
{ LessThan.Thrice(), 4 },
{ LessThan.Times(4), 4 },
{ LessThan.Times(4), 5 },
{ 4.TimesOrLess(), 5 },
{ MoreThan.Once(), 0 },
{ MoreThan.Once(), 1 },
{ MoreThan.Twice(), 1 },
Expand All @@ -80,6 +94,7 @@ public void Occurrence_constraint_passes(OccurrenceConstraint constraint, int oc
{ MoreThan.Thrice(), 3 },
{ MoreThan.Times(4), 3 },
{ MoreThan.Times(4), 4 },
{ 4.TimesOrMore(), 3 },
};

[Theory]
Expand Down

0 comments on commit b887f5c

Please sign in to comment.