Added more f# tests
This PR will add more Tests to the Example project. This is to ensure all Assertions and Attributes work correctly in F#
So far a couple of potential issues.
-
String Assertions don't seem to work in F#
No overloads match for method 'IsEqualTo'. Known types of arguments: string * StringComparison Available overloads: - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo(expected: DateTime, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.DateTimeEqualToAssertionBuilderWrapper - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo(expected: DateTimeOffset, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.DateTimeOffsetEqualToAssertionBuilderWrapper - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo(expected: TimeSpan, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.TimeSpanEqualToAssertionBuilderWrapper - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo(expected: string, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.StringEqualToAssertionBuilderWrapper - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo(expected: string, stringComparison: StringComparison, ?doNotPopulateThisValue1: string, ?doNotPopulateThisValue2: string) : AssertionBuilders.Wrappers.StringEqualToAssertionBuilderWrapper - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo<'TActual>(expected: 'TActual, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.GenericEqualToAssertionBuilderWrapper<'TActual> // Argument 'expected' doesn't match - (extension) AssertConditions.Interfaces.IValueSource.IsEqualTo<'TActual>(expected: 'TActual, equalityComparer: Collections.Generic.IEqualityComparer<'TActual>, ?doNotPopulateThisValue1: string) : AssertionBuilders.Wrappers.GenericEqualToAssertionBuilderWrapper<'TActual> // Argument 'expected' doesn't match
Update
-
So sometimes extension methods in c# cannot be found easily in f#. So in the case some of the assertions. I had to do something as scoffed as this. May need to declare or wrap them in the TUnit specifically.Assertions.FSharp library
Example Test
[<Test>] [<Category("Pass")>] member _.String_And_Condition() = async { do! check (TUnit.Assertions.Extensions.StringIsExtensions.IsEqualTo(Assert.That<string>("1"), "1").And.HasLength().EqualTo(1)) // this also works do! check (Assert.That<string>(value).IsEqualTo("1")) } [<Test>] [<Category("Fail")>] member _.String_And_Condition2() = async { do! check (TUnit.Assertions.Extensions.StringIsExtensions.IsEqualTo(Assert.That<string>("1"), "2").And.HasLength().EqualTo(2)) } ```
Assertions that Throw
- Assertions seem to default to the ValueAssertions and not delegates. I am also unsure of what type they are meant to throw in the following tests
[<Test>]
[<Category("Fail")>]
member _.Throws1() = async {
do! check (Assert.That<Func<string>>(fun () -> new string([||])).ThrowsException())
}
[<Test>]
[<Category("Fail")>]
member _.Throws2() = async {
do! check (Assert.That(fun () -> task { do! Task.Yield() }).ThrowsException())
}
[<Test>]
[<Category("Pass")>]
member _.Throws3() = async {
do! check (Assert.That(fun () -> raise (ApplicationException())).ThrowsException())
}
Annoying that F# doesn't pick up things as nicely!
Annoying that F# doesn't pick up things as nicely!
Yeah, unlike VB, F# uses a completely different compiler and has a bunch of functional paradigms that don't really carry over.
Unlike VB, VB is basically older OOP so for the most part it works with the C# stuff. Although we will find out when I make more VB tests 🤣.
I will say, though, apart from a few things, F# has surprisingly picked up most of the C# stuff fine, considering they use two different compilers and paradigms
Assertions that Throw
- Assertions seem to default to the ValueAssertions and not delegates. I am also unsure of what type they are meant to throw in the following tests
[<Test>] [<Category("Fail")>] member _.Throws1() = async { do! check (Assert.That<Func<string>>(fun () -> new string([||])).ThrowsException()) } [<Test>] [<Category("Fail")>] member _.Throws2() = async { do! check (Assert.That(fun () -> task { do! Task.Yield() }).ThrowsException()) } [<Test>] [<Category("Pass")>] member _.Throws3() = async { do! check (Assert.That(fun () -> raise (ApplicationException())).ThrowsException()) }
Fixed in #2431
Example assertion usage
[<Test>]
[<Category("Fail")>]
member _.Throws1() = async {
do! check (Assert.That<string>(fun () -> task { return new string([||]) }).ThrowsException())
}
[<Test>]
[<Category("Fail")>]
member _.Throws2() = async {
do! check (Assert.That<unit>(fun () -> task { do! Task.Yield() }).ThrowsException())
}
[<Test>]
[<Category("Pass")>]
member _.Throws3() = async {
do! check (Assert.That(fun () -> raise (ApplicationException())).ThrowsException())
}
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This PR was closed because it has been stalled for 10 days with no activity.