diff --git a/test/Nancy.Hosting.Self.Tests/NancySelfHostFixture.cs b/test/Nancy.Hosting.Self.Tests/NancySelfHostFixture.cs index 5ef262b2a3..e6712d96e4 100644 --- a/test/Nancy.Hosting.Self.Tests/NancySelfHostFixture.cs +++ b/test/Nancy.Hosting.Self.Tests/NancySelfHostFixture.cs @@ -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] diff --git a/test/Nancy.Tests.Functional/Tests/ContentNegotiationFixture.cs b/test/Nancy.Tests.Functional/Tests/ContentNegotiationFixture.cs index 6190ac49ac..68f1289374 100644 --- a/test/Nancy.Tests.Functional/Tests/ContentNegotiationFixture.cs +++ b/test/Nancy.Tests.Functional/Tests/ContentNegotiationFixture.cs @@ -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] @@ -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] diff --git a/test/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs b/test/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs index a5de8fefaa..f3b5e0b9fe 100644 --- a/test/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs +++ b/test/Nancy.Tests.Functional/Tests/TracingSmokeTests.cs @@ -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"); } } } diff --git a/test/Nancy.Tests.Functional/Tests/ViewBagTests.cs b/test/Nancy.Tests.Functional/Tests/ViewBagTests.cs index 5f51d2c1a3..9c3e4c2ee2 100644 --- a/test/Nancy.Tests.Functional/Tests/ViewBagTests.cs +++ b/test/Nancy.Tests.Functional/Tests/ViewBagTests.cs @@ -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] @@ -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] diff --git a/test/Nancy.Tests/Helpers/ExceptionExtensionsFixture.cs b/test/Nancy.Tests/Helpers/ExceptionExtensionsFixture.cs index 2b60fb19e8..56c71735bd 100644 --- a/test/Nancy.Tests/Helpers/ExceptionExtensionsFixture.cs +++ b/test/Nancy.Tests/Helpers/ExceptionExtensionsFixture.cs @@ -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); } } } diff --git a/test/Nancy.Tests/ShouldExtensions.cs b/test/Nancy.Tests/ShouldExtensions.cs index 000e052e10..b14d1054d6 100644 --- a/test/Nancy.Tests/ShouldExtensions.cs +++ b/test/Nancy.Tests/ShouldExtensions.cs @@ -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(this IEnumerable list, Func predicate) + public static void ShouldHave(this IEnumerable list, T expected) { - Assert.True(list.Any(predicate)); + Assert.Contains(expected, list); + } + + public static void ShouldHave(this IEnumerable list, Predicate predicate) + { + Assert.Contains(list, predicate); } public static void ShouldHaveCount(this IEnumerable list, int expected) diff --git a/test/Nancy.Tests/Unit/AfterPipelineFixture.cs b/test/Nancy.Tests/Unit/AfterPipelineFixture.cs index 62ac2e2c78..3a76974385 100644 --- a/test/Nancy.Tests/Unit/AfterPipelineFixture.cs +++ b/test/Nancy.Tests/Unit/AfterPipelineFixture.cs @@ -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] @@ -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] diff --git a/test/Nancy.Tests/Unit/BeforePipelineFixture.cs b/test/Nancy.Tests/Unit/BeforePipelineFixture.cs index 109d57cee9..d84d34979f 100644 --- a/test/Nancy.Tests/Unit/BeforePipelineFixture.cs +++ b/test/Nancy.Tests/Unit/BeforePipelineFixture.cs @@ -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()); } diff --git a/test/Nancy.Tests/Unit/Diagnostics/DiagnosticsHookFixture.cs b/test/Nancy.Tests/Unit/Diagnostics/DiagnosticsHookFixture.cs index 2fd61a2394..a08dde7a26 100644 --- a/test/Nancy.Tests/Unit/Diagnostics/DiagnosticsHookFixture.cs +++ b/test/Nancy.Tests/Unit/Diagnostics/DiagnosticsHookFixture.cs @@ -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] @@ -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 diff --git a/test/Nancy.Tests/Unit/DynamicDictionaryFixture.cs b/test/Nancy.Tests/Unit/DynamicDictionaryFixture.cs index aac5c040c1..3ccf24ce78 100644 --- a/test/Nancy.Tests/Unit/DynamicDictionaryFixture.cs +++ b/test/Nancy.Tests/Unit/DynamicDictionaryFixture.cs @@ -1133,7 +1133,7 @@ public void Should_return_dictionary_from_dynamic_dictionary() var result = input.ToDictionary(); //Then - Assert.IsType(typeof(Dictionary), result); + result.ShouldBeOfType>(); } [Fact] @@ -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(GetLongValue(result["TestInt"])); + ShouldAssertExtensions.ShouldBeOfType(GetStringValue(result["TestString"])); } [Fact] diff --git a/test/Nancy.Tests/Unit/ModelBinding/DefaultConverters/FallbackConverterFixture.cs b/test/Nancy.Tests/Unit/ModelBinding/DefaultConverters/FallbackConverterFixture.cs index a05b794942..4185b1d7b3 100644 --- a/test/Nancy.Tests/Unit/ModelBinding/DefaultConverters/FallbackConverterFixture.cs +++ b/test/Nancy.Tests/Unit/ModelBinding/DefaultConverters/FallbackConverterFixture.cs @@ -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(); } diff --git a/test/Nancy.Tests/Unit/NamedPipelineBaseFixture.cs b/test/Nancy.Tests/Unit/NamedPipelineBaseFixture.cs index 50b479db08..4ccec60f42 100644 --- a/test/Nancy.Tests/Unit/NamedPipelineBaseFixture.cs +++ b/test/Nancy.Tests/Unit/NamedPipelineBaseFixture.cs @@ -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()); } diff --git a/test/Nancy.ViewEngines.Markdown.Tests/MarkdownViewEngineFixture.cs b/test/Nancy.ViewEngines.Markdown.Tests/MarkdownViewEngineFixture.cs index 2b3b6380f8..e913f1a1b8 100644 --- a/test/Nancy.ViewEngines.Markdown.Tests/MarkdownViewEngineFixture.cs +++ b/test/Nancy.ViewEngines.Markdown.Tests/MarkdownViewEngineFixture.cs @@ -122,7 +122,7 @@ public void Should_convert_standalone() var result = this.viewEngine.ConvertMarkdown(location); - Assert.True(result.StartsWith("")); + result.ShouldStartWith(""); } [Fact] @@ -152,7 +152,7 @@ public void Should_convert_standalone_view_with_no_master() var result = ReadAll(stream); - Assert.True(result.StartsWith("")); + result.ShouldStartWith(""); } [Fact]