2017-10-29 6 views
2

내 유효성 검사 함수가 실패 할 경우 some 것이 반환되는지 또는 none을 반환하는지 확인해야합니다. Some<string>을 반환하면 유효성 검사 오류가 발생하고 그렇지 않으면 유효하며이 함수는 None을 반환합니다. 이 내 시도이지만, 안전 리팩토링 아니에요 :F # 테스트 결과가 Some (any)이면

[<Property(Arbitrary=[| typeof<Strings.WithLenFrom1To100> |])>] 
    let ``lengthValidator should return some error when the string's length is longer than expected``(str:string)= 
     let maxValidLen = str.Length-1 
     let actual = lengthValidator maxValidLen str 

     let expected = Some(sprintf "Maximum string length is %i but %s contains %i characters" maxValidLen str str.Length) 
     //How can I say **let expected = Some(anything) **instead 

     test <@actual = [email protected]> 

답변

4
test <@ actual.IsSome @> 
+0

완벽! 내 '차별 당사국 연합 (Discriminated Union)'을 위해 어떻게 할 수 있습니까? – Mohsen

+3

'MyDu와 MyCase를 일치 시키십시오. _ -> true | _ -> 거짓 – TheQuickBrownFox

관련 문제