-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for binding vm helpers
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
module BindingVmHelpersTests.M | ||
|
||
open System | ||
open System.Collections.ObjectModel | ||
open System.Collections.Specialized | ||
|
||
open Xunit | ||
open Hedgehog | ||
open Swensen.Unquote | ||
|
||
open Elmish.WPF | ||
open Elmish.WPF.BindingVmHelpers | ||
|
||
|
||
|
||
module Initialize = | ||
|
||
let checker<'t when 't : equality> () = | ||
Property.check <| property { | ||
let! m1 = GenX.auto<'t> | ||
|
||
let binding = BindingData.OneWay.create id | ||
|
||
let vmBinding = | ||
Initialize(LoggingViewModelArgs.none, "Nothing", (fun _ -> failwith "not selected item")) | ||
.Recursive(m1, ignore, (fun () -> m1), binding) | ||
|
||
let result = | ||
match vmBinding with | ||
| Some (BaseVmBinding (OneWay b)) -> b | ||
| b -> failwithf "Expected a OneWay binding, instead found %O" b | ||
|
||
test <@ result.OneWayData.Get m1 = m1 @> | ||
} | ||
|
||
[<Fact>] | ||
let ``should initialize successfully with various types`` () = | ||
checker<float> () | ||
checker<int32> () | ||
checker<string> () | ||
checker<Guid> () | ||
checker<obj> () | ||
|
||
module Get = | ||
|
||
let checker<'t when 't : equality> () = | ||
Property.check <| property { | ||
let! m1 = GenX.auto<'t> | ||
|
||
let binding = BindingData.OneWay.create id | ||
|
||
let vmBinding = | ||
Initialize(LoggingViewModelArgs.none, "Nothing", (fun _ -> failwith "not selected item")) | ||
.Recursive(m1, ignore, (fun () -> m1), binding) | ||
|
||
let getResult = vmBinding |> Option.map (fun b -> Get("Nothing").Recursive(m1, b)) | ||
|
||
let get = | ||
match getResult with | ||
| Some (Ok x) -> x | ||
| x -> failwithf "Expected a success, instead got %O" x | ||
|
||
test <@ get = m1 @> | ||
} | ||
|
||
[<Fact>] | ||
let ``should get successfully with various types`` () = | ||
checker<float> () | ||
checker<int32> () | ||
checker<string> () | ||
checker<Guid> () | ||
checker<obj> () | ||
|
||
module Set = | ||
|
||
let checker<'t when 't : equality> () = | ||
Property.check <| property { | ||
let! m1 = GenX.auto<'t> | ||
let! m2 = GenX.auto<'t> |> GenX.notEqualTo m1 | ||
|
||
let model = ref m1 | ||
|
||
let binding = BindingData.TwoWay.create id (fun m _ -> m) | ||
|
||
let vmBinding = | ||
Initialize(LoggingViewModelArgs.none, "Nothing", (fun _ -> failwith "not selected item")) | ||
.Recursive(m1, (fun m -> model.Value <- m), (fun () -> model.Value), binding) | ||
|
||
let _setResult = vmBinding |> Option.map (fun b -> Set(m2).Recursive(model.Value, b)) | ||
|
||
test <@ model.Value = m2 @> | ||
test <@ model.Value <> m1 @> | ||
} | ||
|
||
[<Fact>] | ||
let ``should set successfully with various types`` () = | ||
checker<float> () | ||
checker<int32> () | ||
checker<string> () | ||
checker<Guid> () | ||
checker<obj> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters