From 5ae31300fe7144cafbad7f628b1fabebad30afcf Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Fri, 31 Jul 2015 09:41:45 +0300 Subject: [PATCH] Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit --- RELEASE_NOTES.md | 3 +- docs/content/operators.md | 2 +- src/FsUnit.MbUnit/FsUnit.fs | 2 ++ src/FsUnit.MsTestUnit/FsUnit.fs | 2 ++ src/FsUnit.MsTestUnit/paket.template | 4 +-- src/FsUnit.NUnit/paket.template | 4 +-- src/FsUnit.Xunit/CustomMatchers.fs | 2 ++ src/FsUnit.Xunit/FsUnit.fs | 2 ++ .../FsUnit.MbUnit.Test.fsproj | 1 + tests/FsUnit.MbUnit.Test/instanceOfTests.fs | 29 ++++++++++++++++++ .../Fs30Unit.MsTest.Test.fsproj | 1 + tests/FsUnit.MsTest.Test/instanceOfTests.fs | 30 +++++++++++++++++++ .../FsUnit.Xunit.Test.fsproj | 1 + tests/FsUnit.Xunit.Test/instanceOfTests.fs | 29 ++++++++++++++++++ 14 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 tests/FsUnit.MbUnit.Test/instanceOfTests.fs create mode 100644 tests/FsUnit.MsTest.Test/instanceOfTests.fs create mode 100644 tests/FsUnit.Xunit.Test/instanceOfTests.fs diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 89e2d5bd..f1f00149 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -3,7 +3,8 @@ * FsUnitDepricated module renamed to FsUnitDeprecated https://github.com/fsprojects/FsUnit/pull/46 * Enable substring checks https://github.com/fsprojects/FsUnit/pull/45 * Fixed assertion message for NUnit equal constraint - https://github.com/fsprojects/FsUnit/pull/60 -* Added support of `shouldFail` operator for xUnit, MsTest and MbUnit +* Added support of `shouldFail` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/64 +* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit - ### 1.3.1.0 - 26 July 2015 * Bump NUnit version up to 2.6.4 diff --git a/docs/content/operators.md b/docs/content/operators.md index edf7607c..6d828a5a 100644 --- a/docs/content/operators.md +++ b/docs/content/operators.md @@ -30,7 +30,7 @@ Operators comparison across frameworks | `startWith` | + | + | + | + | | `haveSubstring` | + | + | + | + | | `ofExactType` | + | + | + | + | -| `instanceOfType` | + | | | | +| `instanceOfType` | + | + | + | + | | `choice` | + | + | + | + | | `ascending` | + | + | + | + | | `descending` | + | + | + | + | diff --git a/src/FsUnit.MbUnit/FsUnit.fs b/src/FsUnit.MbUnit/FsUnit.fs index e30139be..7cfcd097 100644 --- a/src/FsUnit.MbUnit/FsUnit.fs +++ b/src/FsUnit.MbUnit/FsUnit.fs @@ -63,6 +63,8 @@ let haveSubstring (expected:string) = CustomMatchers.haveSubstring expected let ofExactType<'a> = CustomMatchers.ofExactType<'a> +let instanceOfType<'a> = CustomMatchers.instanceOfType<'a> + let contain expected = CustomMatchers.contain expected let matchList = CustomMatchers.matchList diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index 77e269e8..4bb4846d 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.fs +++ b/src/FsUnit.MsTestUnit/FsUnit.fs @@ -73,6 +73,8 @@ let haveSubstring (expected:string) = CustomMatchers.haveSubstring expected let ofExactType<'a> = CustomMatchers.ofExactType<'a> +let instanceOfType<'a> = CustomMatchers.instanceOfType<'a> + let contain expected = CustomMatchers.contain expected let matchList = CustomMatchers.matchList diff --git a/src/FsUnit.MsTestUnit/paket.template b/src/FsUnit.MsTestUnit/paket.template index 9c2bd980..7b2d6f52 100644 --- a/src/FsUnit.MsTestUnit/paket.template +++ b/src/FsUnit.MsTestUnit/paket.template @@ -22,6 +22,6 @@ summary description FsUnit is a set of extensions that add special testing syntax to MsTest. files - ../../bin/FsUnit.MsTest/FsUnit.* ==> lib - ../../bin/FsUnit.MsTest/NHamcrest.* ==> lib + ../../bin/FsUnit.MsTest/FsUnit.* ==> lib/net40 + ../../bin/FsUnit.MsTest/NHamcrest.* ==> lib/net40 ../../src/install.ps1 ==> tools diff --git a/src/FsUnit.NUnit/paket.template b/src/FsUnit.NUnit/paket.template index 8d0593cd..a617f631 100644 --- a/src/FsUnit.NUnit/paket.template +++ b/src/FsUnit.NUnit/paket.template @@ -24,6 +24,6 @@ description dependencies NUnit 2.6.4 files - ../../bin/FsUnit.NUnit/FsUnit.* ==> lib - ../../bin/FsUnit.Xunit/NHamcrest.* ==> lib + ../../bin/FsUnit.NUnit/FsUnit.* ==> lib/net20 + ../../bin/FsUnit.Xunit/NHamcrest.* ==> lib/net20 ../../src/install.ps1 ==> tools diff --git a/src/FsUnit.Xunit/CustomMatchers.fs b/src/FsUnit.Xunit/CustomMatchers.fs index 69b87b65..e2f1fc65 100644 --- a/src/FsUnit.Xunit/CustomMatchers.fs +++ b/src/FsUnit.Xunit/CustomMatchers.fs @@ -74,6 +74,8 @@ let haveSubstring (x:string) = CustomMatcher(string x, fun s -> (string s). let ofExactType<'a> = CustomMatcher(typeof<'a>.ToString(), fun x -> (unbox x).GetType() = typeof<'a>) +let instanceOfType<'a> = CustomMatcher(typeof<'a>.ToString(), fun x -> typeof<'a>.IsInstanceOfType(x)) + let contain x = CustomMatcher(sprintf "Contains %s" (x.ToString()), fun c -> match c with | :? list<_> as l -> l |> List.exists(fun i -> i = x) diff --git a/src/FsUnit.Xunit/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index 2732416a..bbd3c711 100644 --- a/src/FsUnit.Xunit/FsUnit.fs +++ b/src/FsUnit.Xunit/FsUnit.fs @@ -77,6 +77,8 @@ let haveSubstring (expected:string) = CustomMatchers.haveSubstring expected let ofExactType<'a> = CustomMatchers.ofExactType<'a> +let instanceOfType<'a> = CustomMatchers.instanceOfType<'a> + let contain expected = CustomMatchers.contain expected let matchList = CustomMatchers.matchList diff --git a/tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj b/tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj index 0658b9cf..00343946 100644 --- a/tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj +++ b/tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj @@ -78,6 +78,7 @@ + diff --git a/tests/FsUnit.MbUnit.Test/instanceOfTests.fs b/tests/FsUnit.MbUnit.Test/instanceOfTests.fs new file mode 100644 index 00000000..1f2b8897 --- /dev/null +++ b/tests/FsUnit.MbUnit.Test/instanceOfTests.fs @@ -0,0 +1,29 @@ +namespace FsUnit.Test +open MbUnit.Framework +open FsUnit.MbUnit + +[] +type ``Instance Of tests`` ()= + [] member test. + ``int should be instance of type Object`` ()= + 1 |> should be instanceOfType + + [] member test. + ``int should be instance of type int`` ()= + 1 |> should be instanceOfType + + [] member test. + ``string should be instance of type string`` ()= + "test" |> should be instanceOfType + + [] member test. + ``list should be instance of type fsharplist`` ()= + [] |> should be instanceOfType> + + [] member test. + ``array should be instance of type array`` ()= + [||] |> should be instanceOfType> + + [] member test. + ``string should not be instance of type int`` ()= + "test" |> should not' (be instanceOfType) diff --git a/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj b/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj index 841a1bff..0afe8cd5 100644 --- a/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj +++ b/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj @@ -77,6 +77,7 @@ + diff --git a/tests/FsUnit.MsTest.Test/instanceOfTests.fs b/tests/FsUnit.MsTest.Test/instanceOfTests.fs new file mode 100644 index 00000000..e6f8ff74 --- /dev/null +++ b/tests/FsUnit.MsTest.Test/instanceOfTests.fs @@ -0,0 +1,30 @@ +namespace FsUnit.Test +open Microsoft.VisualStudio.TestTools.UnitTesting +open FsUnit.MsTest +open NHamcrest.Core + +[] +type ``Instance Of tests`` ()= + [] member test. + ``int should be instance of type Object`` ()= + 1 |> should be instanceOfType + + [] member test. + ``int should be instance of type int`` ()= + 1 |> should be instanceOfType + + [] member test. + ``string should be instance of type string`` ()= + "test" |> should be instanceOfType + + [] member test. + ``list should be instance of type fsharplist`` ()= + [] |> should be instanceOfType> + + [] member test. + ``array should be instance of type array`` ()= + [||] |> should be instanceOfType> + + [] member test. + ``string should not be instance of type int`` ()= + "test" |> should not' (be instanceOfType) diff --git a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj index 54081259..169d50a4 100644 --- a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj +++ b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj @@ -78,6 +78,7 @@ + diff --git a/tests/FsUnit.Xunit.Test/instanceOfTests.fs b/tests/FsUnit.Xunit.Test/instanceOfTests.fs new file mode 100644 index 00000000..92d3c15e --- /dev/null +++ b/tests/FsUnit.Xunit.Test/instanceOfTests.fs @@ -0,0 +1,29 @@ +namespace FsUnit.Test +open Xunit +open FsUnit.Xunit + + +type ``Instance Of tests`` ()= + [] member test. + ``int should be instance of type Object`` ()= + 1 |> should be instanceOfType + + [] member test. + ``int should be instance of type int`` ()= + 1 |> should be instanceOfType + + [] member test. + ``string should be instance of type string`` ()= + "test" |> should be instanceOfType + + [] member test. + ``list should be instance of type fsharplist`` ()= + [] |> should be instanceOfType> + + [] member test. + ``array should be instance of type array`` ()= + [||] |> should be instanceOfType> + + [] member test. + ``string should not be instance of type int`` ()= + "test" |> should not' (be instanceOfType)