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

Added support of instanceOfType operator for xUnit, MsTest and MbUnit #65

Merged
merged 1 commit into from
Jul 31, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Operators comparison across frameworks
| `startWith` | + | + | + | + |
| `haveSubstring` | + | + | + | + |
| `ofExactType` | + | + | + | + |
| `instanceOfType` | + | | | |
| `instanceOfType` | + | + | + | + |
| `choice` | + | + | + | + |
| `ascending` | + | + | + | + |
| `descending` | + | + | + | + |
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.MbUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.MsTestUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/FsUnit.MsTestUnit/paket.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/FsUnit.NUnit/paket.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/FsUnit.Xunit/CustomMatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ let haveSubstring (x:string) = CustomMatcher<obj>(string x, fun s -> (string s).

let ofExactType<'a> = CustomMatcher<obj>(typeof<'a>.ToString(), fun x -> (unbox x).GetType() = typeof<'a>)

let instanceOfType<'a> = CustomMatcher<obj>(typeof<'a>.ToString(), fun x -> typeof<'a>.IsInstanceOfType(x))

let contain x = CustomMatcher<obj>(sprintf "Contains %s" (x.ToString()),
fun c -> match c with
| :? list<_> as l -> l |> List.exists(fun i -> i = x)
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.Xunit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="shouldStartWithTests.fs" />
<Compile Include="shouldHaveSubstringTests.fs" />
<Compile Include="equalWithinTests.fs" />
<Compile Include="instanceOfTests.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions tests/FsUnit.MbUnit.Test/instanceOfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace FsUnit.Test
open MbUnit.Framework
open FsUnit.MbUnit

[<TestFixture>]
type ``Instance Of tests`` ()=
[<Test>] member test.
``int should be instance of type Object`` ()=
1 |> should be instanceOfType<obj>

[<Test>] member test.
``int should be instance of type int`` ()=
1 |> should be instanceOfType<int>

[<Test>] member test.
``string should be instance of type string`` ()=
"test" |> should be instanceOfType<string>

[<Test>] member test.
``list should be instance of type fsharplist`` ()=
[] |> should be instanceOfType<list<_>>

[<Test>] member test.
``array should be instance of type array`` ()=
[||] |> should be instanceOfType<array<_>>

[<Test>] member test.
``string should not be instance of type int`` ()=
"test" |> should not' (be instanceOfType<int>)
1 change: 1 addition & 0 deletions tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="shouldEndWithTests.fs" />
<Compile Include="shouldStartWithTests.fs" />
<Compile Include="shouldHaveSubstringTests.fs" />
<Compile Include="instanceOfTests.fs" />
<None Include="App.config" />
<None Include="paket.references" />
<None Include="MSTest.runsettings" />
Expand Down
30 changes: 30 additions & 0 deletions tests/FsUnit.MsTest.Test/instanceOfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace FsUnit.Test
open Microsoft.VisualStudio.TestTools.UnitTesting
open FsUnit.MsTest
open NHamcrest.Core

[<TestClass>]
type ``Instance Of tests`` ()=
[<TestMethod>] member test.
``int should be instance of type Object`` ()=
1 |> should be instanceOfType<obj>

[<TestMethod>] member test.
``int should be instance of type int`` ()=
1 |> should be instanceOfType<int>

[<TestMethod>] member test.
``string should be instance of type string`` ()=
"test" |> should be instanceOfType<string>

[<TestMethod>] member test.
``list should be instance of type fsharplist`` ()=
[] |> should be instanceOfType<list<_>>

[<TestMethod>] member test.
``array should be instance of type array`` ()=
[||] |> should be instanceOfType<array<_>>

[<TestMethod>] member test.
``string should not be instance of type int`` ()=
"test" |> should not' (be instanceOfType<int>)
1 change: 1 addition & 0 deletions tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="shouldStartWithTests.fs" />
<Compile Include="shouldHaveSubstringTests.fs" />
<Compile Include="equalWithinTests.fs" />
<Compile Include="instanceOfTests.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions tests/FsUnit.Xunit.Test/instanceOfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace FsUnit.Test
open Xunit
open FsUnit.Xunit


type ``Instance Of tests`` ()=
[<Fact>] member test.
``int should be instance of type Object`` ()=
1 |> should be instanceOfType<obj>

[<Fact>] member test.
``int should be instance of type int`` ()=
1 |> should be instanceOfType<int>

[<Fact>] member test.
``string should be instance of type string`` ()=
"test" |> should be instanceOfType<string>

[<Fact>] member test.
``list should be instance of type fsharplist`` ()=
[] |> should be instanceOfType<list<_>>

[<Fact>] member test.
``array should be instance of type array`` ()=
[||] |> should be instanceOfType<array<_>>

[<Fact>] member test.
``string should not be instance of type int`` ()=
"test" |> should not' (be instanceOfType<int>)