Skip to content

Commit

Permalink
Use element access over LINQ
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed May 14, 2024
1 parent d6ad804 commit 029662a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using FluentAssertions.Execution;
using Xunit;
Expand Down Expand Up @@ -351,7 +350,7 @@ public void When_strings_are_in_ascending_order_according_to_a_custom_lambda_it_
string[] strings = ["alpha", "beta", "theta"];

// Act
Action act = () => strings.Should().BeInAscendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()));
Action act = () => strings.Should().BeInAscendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]));

// Assert
act.Should().NotThrow();
Expand All @@ -365,7 +364,7 @@ public void When_strings_are_not_in_ascending_order_according_to_a_custom_lambda

// Act
Action act = () =>
strings.Should().BeInAscendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()), "of {0}", "reasons");
strings.Should().BeInAscendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]), "of {0}", "reasons");

// Assert
act.Should()
Expand Down Expand Up @@ -761,7 +760,7 @@ public void When_strings_are_not_in_ascending_order_according_to_a_custom_lambda
string[] strings = ["roy", "dennis", "thomas"];

// Act
Action act = () => strings.Should().NotBeInAscendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()));
Action act = () => strings.Should().NotBeInAscendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]));

// Assert
act.Should().NotThrow();
Expand All @@ -775,7 +774,7 @@ public void When_strings_are_unexpectedly_in_ascending_order_according_to_a_cust

// Act
Action act = () =>
strings.Should().NotBeInAscendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()), "of {0}", "reasons");
strings.Should().NotBeInAscendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]), "of {0}", "reasons");

// Assert
act.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -263,7 +262,7 @@ public void When_strings_are_in_descending_order_based_on_a_custom_lambda_it_sho
string[] strings = ["roy", "dennis", "barbara"];

// Act
Action act = () => strings.Should().BeInDescendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()));
Action act = () => strings.Should().BeInDescendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]));

// Assert
act.Should().NotThrow();
Expand All @@ -277,7 +276,7 @@ public void When_strings_are_not_in_descending_order_based_on_a_custom_lambda_it

// Act
Action act = () =>
strings.Should().BeInDescendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()), "of {0}", "reasons");
strings.Should().BeInDescendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]), "of {0}", "reasons");

// Assert
act.Should()
Expand Down Expand Up @@ -572,7 +571,7 @@ public void When_strings_are_not_in_descending_order_based_on_a_custom_lambda_it
string[] strings = ["dennis", "roy", "barbara"];

// Act
Action act = () => strings.Should().NotBeInDescendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()));
Action act = () => strings.Should().NotBeInDescendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]));

// Assert
act.Should().NotThrow();
Expand All @@ -586,7 +585,7 @@ public void When_strings_are_unexpectedly_in_descending_order_based_on_a_custom_

// Act
Action act = () =>
strings.Should().NotBeInDescendingOrder((sut, exp) => sut.Last().CompareTo(exp.Last()), "of {0}", "reasons");
strings.Should().NotBeInDescendingOrder((sut, exp) => sut[^1].CompareTo(exp[^1]), "of {0}", "reasons");

// Assert
act.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private class ByLastCharacterComparer : IComparer<string>
{
public int Compare(string x, string y)
{
return x.Last().CompareTo(y.Last());
return x[^1].CompareTo(y[^1]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/FluentAssertions.Specs/Events/EventAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public void When_constraints_are_specified_it_should_filter_the_events_based_on_

recording
.Should().ContainSingle("because we were expecting a specific property change")
.Which.Parameters.Last().Should().BeOfType<PropertyChangedEventArgs>()
.Which.Parameters[^1].Should().BeOfType<PropertyChangedEventArgs>()
.Which.PropertyName.Should().Be("Boo");
}

Expand Down

0 comments on commit 029662a

Please sign in to comment.