Skip to content

Conversation

@licon4812
Copy link
Contributor

This PR will add more Tests to the Example project. This is to ensure all Assertions and Attributes work correctly in F#

@licon4812 licon4812 marked this pull request as draft May 21, 2025 04:26
@licon4812
Copy link
Contributor Author

licon4812 commented May 21, 2025

So far a couple of potential issues.

  • String Assertions don't seem to work in F#

    image

    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))
     }
     ```
    

@licon4812
Copy link
Contributor Author

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())
 }

@thomhurst
Copy link
Owner

Annoying that F# doesn't pick up things as nicely!

@licon4812
Copy link
Contributor Author

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

@licon4812
Copy link
Contributor Author

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())
}

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Jun 23, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2025

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions bot closed this Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants