Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Fix xUnit analyzer warnings #2951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion test/Nancy.Hosting.Self.Tests/NancySelfHostFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void Should_be_able_to_recover_from_rendering_exception()
public void Should_be_serializable()
{
var type = typeof(NancyHost);
Assert.True(type.Attributes.ToString().Contains("Serializable"));
type.Attributes.ToString().ShouldContain("Serializable");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public async Task Should_add_vary_accept_header()

// Then
Assert.True(response.Headers.ContainsKey("Vary"));
Assert.True(response.Headers["Vary"].Contains("Accept"));
response.Headers["Vary"].ShouldContain("Accept");
}

[Fact]
Expand Down Expand Up @@ -660,7 +660,7 @@ public async Task Should_not_try_and_serve_view_with_invalid_name()
var result = await RecordAsync.Exception(() => browser.Get("/invalid-view-name"));

// Then
Assert.True(result.ToString().Contains("Unable to locate requested view"));
result.ToString().ShouldContain("Unable to locate requested view");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task Should_render_content_from_viewbag()
});

// Then
Assert.True(response.Body.AsString().Contains(@"Hello Bob"));
response.Body.AsString().ShouldContain(@"Hello Bob");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Nancy.Tests.Functional/Tests/ViewBagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Should_render_content_from_viewbag()
});

// Then
Assert.True(response.Body.AsString().Contains(@"Hello Bob"));
response.Body.AsString().ShouldContain(@"Hello Bob");
}

[Fact]
Expand All @@ -50,7 +50,7 @@ public async Task Should_render_content_from_viewbags()
});

// Then
Assert.True(response.Body.AsString().Contains(@"Hello Bob"));
response.Body.AsString().ShouldContain(@"Hello Bob");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/Nancy.Tests/Helpers/ExceptionExtensionsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Should_flatten_aggregate_exceptions()
Assert.Equal(3, innerExceptions.Count);

foreach (var exception in expectedExceptions)
Assert.True(innerExceptions.Contains(exception));
innerExceptions.ShouldHave(exception);
}
}
}
9 changes: 7 additions & 2 deletions test/Nancy.Tests/ShouldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ public static void ShouldNotContain(this string actual, string expected)
Assert.False(actual.Contains(expected), string.Format("'{0}' does contain '{1}'", actual, expected));
}

public static void ShouldHave<T>(this IEnumerable<T> list, Func<T, bool> predicate)
public static void ShouldHave<T>(this IEnumerable<T> list, T expected)
{
Assert.True(list.Any(predicate));
Assert.Contains(expected, list);
}

public static void ShouldHave<T>(this IEnumerable<T> list, Predicate<T> predicate)
{
Assert.Contains(list, predicate);
}

public static void ShouldHaveCount<T>(this IEnumerable<T> list, int expected)
Expand Down
3 changes: 1 addition & 2 deletions test/Nancy.Tests/Unit/AfterPipelineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void PlusEquals_with_func_add_item_to_end_of_pipeline()
pipeline += r => { };

pipeline.PipelineDelegates.ShouldHaveCount(1);
Assert.Equal(1, pipeline.PipelineDelegates.Count());
}

[Fact]
Expand Down Expand Up @@ -75,7 +74,7 @@ public void When_cast_from_func_creates_a_pipeline_with_one_item()
var castPipeline = new AfterPipeline();
castPipeline += r => { };

Assert.Equal(1, castPipeline.PipelineDelegates.Count());
castPipeline.PipelineDelegates.ShouldHaveCount(1);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/Nancy.Tests/Unit/BeforePipelineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void When_cast_from_func_creates_a_pipeline_with_one_item()
BeforePipeline castPipeline = item2;

// Then
Assert.Equal(1, castPipeline.PipelineDelegates.Count());
castPipeline.PipelineDelegates.ShouldHaveCount(1);
Assert.Same(item2, castPipeline.PipelineDelegates.First());
}

Expand Down
4 changes: 2 additions & 2 deletions test/Nancy.Tests/Unit/Diagnostics/DiagnosticsHookFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task Should_return_info_page_if_password_null()
var result = await browser.Get(DiagnosticsConfiguration.Default.Path);

// Then
Assert.True(result.Body.AsString().Contains("Diagnostics Disabled"));
result.Body.AsString().ShouldContain("Diagnostics Disabled");
}

[Fact]
Expand All @@ -77,7 +77,7 @@ public async Task Should_return_info_page_if_password_empty()
var result = await browser.Get(DiagnosticsConfiguration.Default.Path);

// Then
Assert.True(result.Body.AsString().Contains("Diagnostics Disabled"));
result.Body.AsString().ShouldContain("Diagnostics Disabled");
}
#endif

Expand Down
7 changes: 4 additions & 3 deletions test/Nancy.Tests/Unit/DynamicDictionaryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ public void Should_return_dictionary_from_dynamic_dictionary()
var result = input.ToDictionary();

//Then
Assert.IsType(typeof(Dictionary<string, object>), result);
result.ShouldBeOfType<Dictionary<string, object>>();
}

[Fact]
Expand All @@ -1143,8 +1143,9 @@ public void Should_return_dynamic_values_as_objects()
var result = this.dictionary.ToDictionary();

//Then
Assert.IsType(typeof(long), GetLongValue(result["TestInt"]));
Assert.IsType(typeof(string), GetStringValue(result["TestString"]));
//Can't invoke extension methods on dynamic objects using instance method syntax, so access via class.
ShouldAssertExtensions.ShouldBeOfType<long>(GetLongValue(result["TestInt"]));
ShouldAssertExtensions.ShouldBeOfType<string>(GetStringValue(result["TestString"]));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public void Should_convert_datetime()
[InlineData("ON")]
public void Should_convert_on_to_true_for_bool(string value)
{
string input = "on";

var result = (bool)converter.Convert(input, typeof(bool), null);
var result = (bool)converter.Convert(value, typeof(bool), null);

result.ShouldBeTrue();
}
Expand Down
2 changes: 1 addition & 1 deletion test/Nancy.Tests/Unit/NamedPipelineBaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void Should_be_able_to_remove_a_named_item()

pipeline.RemoveByName("item2");

Assert.Equal(1, pipeline.Items.Count());
pipeline.Items.ShouldHaveCount(1);
Assert.Same(item1, pipeline.Items.First());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void Should_convert_standalone()

var result = this.viewEngine.ConvertMarkdown(location);

Assert.True(result.StartsWith("<!DOCTYPE html>"));
result.ShouldStartWith("<!DOCTYPE html>");
}

[Fact]
Expand Down Expand Up @@ -152,7 +152,7 @@ public void Should_convert_standalone_view_with_no_master()

var result = ReadAll(stream);

Assert.True(result.StartsWith("<!DOCTYPE html>"));
result.ShouldStartWith("<!DOCTYPE html>");
}

[Fact]
Expand Down