在Nullable Enum上设置FluentAssertions期望值

时间:2017-11-03 12:12:35

标签: c# fluent-assertions

我有以下对象(为简洁而简化为单一属性)

public class MyDto {
    public MyEnum? MyProperty {get; set;}
}

和相应的DTO

MyProperty

我的映射设置为当字符串myDto.ShouldBeEquivalentTo(myObject, opt => opt.Using<MyEnum?>(ctx => ctx.Subject.Should().Be(null)).When(info => info.SelectedMemberPath.Equals(nameof(MyDto.MyProperty)))); 为空时,枚举设置为null。现在我想使用FluentAssertions测试它(还有很多其他属性),所以我尝试使用以下

设置等效性比较行为
Expected member MyProperty to be a System.String, but found a System.Nullable

但是当我得到异常时,这并不起作用

let homeObject = ["deeplink_url":"com://www.xxxyyy.com?title=topPersons&url=google.com"]
    if let url = homeObject["deeplink_url"], url != "" {

      if url.contains("www.xxxyyy.com") {

        if url.contains("?url") {
         //asdj asd asd asdasdfasdf asdfa sdf asdf asdf asdf asdf a sdf asd asdghgjkkjkjkljkljkjkl jkljkljkl jklj jl jljasd asd asdf asd asdf asdf asdf asd asdf asdf aasasaasdasdfasdf asdf asdasdfasdf hoasdasd


        } else {




          if let urlComponents = URLComponents(url:URL.init(string: url)!, resolvingAgainstBaseURL: false)
          {


            let webViewTitle = urlComponents.queryItems!.filter({ $0.name == "title" }).first
            let webViewURL = urlComponents.queryItems!.filter({$0.name == "url"}).first

            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "FeaturedWebViewController") as! FeaturedWebViewController
            vc.webViewTitle = webViewTitle!.value
            vc.dynamicURL = webViewURL!.value
            self.navigationController?.pushViewController(vc, animated: true)
          }
        }

      } else {

        UIApplication.shared.openURL(URL(string: url)!)
      }

我做错了什么?

1 个答案:

答案 0 :(得分:2)

我认为你在这里找到了一个优势案例。 FluentAssertions将枚举字符串视为特殊,但不处理可空的枚举。 Using / WhenTypes不支持处理不同类型的属性。解决这个问题的唯一方法是提交更改请求。