简体   繁体   中英

compare c# instance objects in f#

I am new to F#, and trying to learn F# by writing unit tests for C# library.

Below is sample C# code -

 public class User
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class UserSelector
{
    public User SelectUser()
    {
        return new User() { FirstName = "John", LastName = "Public" };
    }
}

In F# I am writing Unit tests with xunit -

Below is sample F# Code -

module UserSelectorTests =

[<Fact>]
let ``SelectUser Tests``() =
    let actual = (new UserSelector()).SelectUser()
    let expected = new User(FirstName = "John", LastName = "Public")
    Assert.Equal(expected, actual)

Even though actual and expected are same the test fails.

Any ideas on how to compare objects in F#?

正如Rene在评论中提到的那样,User类需要实现Equals。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM