Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern combinators #2039

Merged
merged 2 commits into from Dec 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Common/FullFrameworkReflector.cs
Expand Up @@ -30,8 +30,7 @@ private static bool IsRelevant(Assembly ass)

private static bool IsDynamic(Assembly assembly)
{
return (assembly.GetType().FullName == "System.Reflection.Emit.AssemblyBuilder") ||
(assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder");
return assembly.GetType().FullName is "System.Reflection.Emit.AssemblyBuilder" or "System.Reflection.Emit.InternalAssemblyBuilder";
}

private static IEnumerable<Type> GetExportedTypes(Assembly assembly)
Expand Down
Expand Up @@ -12,7 +12,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon
Type expectationType = comparands.GetExpectedType(context.Options);
EqualityStrategy strategy = context.Options.GetEqualityStrategy(expectationType);

bool canHandle = (strategy == EqualityStrategy.Equals) || (strategy == EqualityStrategy.ForceEquals);
bool canHandle = strategy is EqualityStrategy.Equals or EqualityStrategy.ForceEquals;
if (canHandle)
{
context.Tracer.WriteLine(member =>
Expand Down
28 changes: 4 additions & 24 deletions Src/FluentAssertions/Extensions/FluentDateTimeExtensions.cs
Expand Up @@ -144,12 +144,12 @@ public static DateTime At(this DateTime date, TimeSpan time)
/// </summary>
public static DateTime At(this DateTime date, int hours, int minutes, int seconds = 0, int milliseconds = 0, int microseconds = 0, int nanoseconds = 0)
{
if (microseconds < 0 || microseconds > 999)
if (microseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(microseconds), "Valid values are between 0 and 999");
}

if (nanoseconds < 0 || nanoseconds > 999)
if (nanoseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(nanoseconds), "Valid values are between 0 and 999");
}
Expand All @@ -175,12 +175,12 @@ public static DateTime At(this DateTime date, int hours, int minutes, int second
/// </summary>
public static DateTimeOffset At(this DateTimeOffset date, int hours, int minutes, int seconds = 0, int milliseconds = 0, int microseconds = 0, int nanoseconds = 0)
{
if (microseconds < 0 || microseconds > 999)
if (microseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(microseconds), "Valid values are between 0 and 999");
}

if (nanoseconds < 0 || nanoseconds > 999)
if (nanoseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(nanoseconds), "Valid values are between 0 and 999");
}
Expand Down Expand Up @@ -257,11 +257,6 @@ public static int Nanosecond(this DateTimeOffset self)
/// </summary>
public static DateTime AddNanoseconds(this DateTime self, long nanoseconds)
{
if (nanoseconds == 0)
{
return self;
}

return self + nanoseconds.Nanoseconds();
}

Expand All @@ -270,11 +265,6 @@ public static DateTime AddNanoseconds(this DateTime self, long nanoseconds)
/// </summary>
public static DateTimeOffset AddNanoseconds(this DateTimeOffset self, long nanoseconds)
{
if (nanoseconds == 0)
{
return self;
}

return self + nanoseconds.Nanoseconds();
}

Expand All @@ -299,11 +289,6 @@ public static int Microsecond(this DateTimeOffset self)
/// </summary>
public static DateTime AddMicroseconds(this DateTime self, long microseconds)
{
if (microseconds == 0)
{
return self;
}

return self + microseconds.Microseconds();
}

Expand All @@ -312,11 +297,6 @@ public static DateTime AddMicroseconds(this DateTime self, long microseconds)
/// </summary>
public static DateTimeOffset AddMicroseconds(this DateTimeOffset self, long microseconds)
{
if (microseconds == 0)
{
return self;
}

return self + microseconds.Microseconds();
}

Expand Down
Expand Up @@ -15,7 +15,7 @@ public class DateTimeOffsetValueFormatter : IValueFormatter
/// </returns>
public bool CanHandle(object value)
{
return (value is DateTime) || (value is DateTimeOffset);
return value is DateTime or DateTimeOffset;
}

public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
Expand Down
2 changes: 1 addition & 1 deletion Tests/FluentAssertions.Specs/Common/TimeSpanExtensions.cs
Expand Up @@ -17,7 +17,7 @@ public static TimeSpan Multiply(this TimeSpan timeSpan, double factor)
// Rounding to the nearest tick is as close to the result we would have with unlimited
// precision as possible, and so likely to have the least potential to surprise.
double ticks = Math.Round(timeSpan.Ticks * factor);
if (ticks > long.MaxValue || ticks < long.MinValue)
if (ticks is > long.MaxValue or < long.MinValue)
{
throw new OverflowException("TimeSpan overflowed because the duration is too long.");
}
Expand Down