namespace monotouchtestWatchKitExtension open System open System.Collections open System.Linq open System.Threading open WatchKit open Foundation open NUnit.Framework.Internal.Filters open MonoTouch.NUnit.UI [] type InterfaceController (handle: IntPtr) = inherit WKInterfaceController (handle) let mutable runner = Unchecked.defaultof let mutable running = false [] member val lblStatus = Unchecked.defaultof with get, set [] member val lblSuccess = Unchecked.defaultof with get, set [] member val lblFailed = Unchecked.defaultof with get, set [] member val lblIgnInc = Unchecked.defaultof with get, set [] member val cmdRun = Unchecked.defaultof with get, set member this.LoadTests () = runner <- new WatchOSRunner () let ce = new CategoryExpression ("MobileNotWorking,NotOnMac,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingInterpreter") runner.Filter <- new NotFilter (ce.Filter) let tp = this.GetType () runner.Add (tp.Assembly) ThreadPool.QueueUserWorkItem (fun v -> runner.LoadSync () this.BeginInvokeOnMainThread (fun x -> this.lblStatus.SetText (String.Format ("{0} tests", runner.TestCount)) this.RenderResults () this.cmdRun.SetEnabled (true) this.cmdRun.SetHidden (false) runner.AutoRun () ) ) |> ignore override this.Awake (context: NSObject) = base.Awake (context) this.BeginInvokeOnMainThread (fun x -> this.LoadTests () () ) member this.RenderResults () = if runner.TestCount > 0 then this.lblSuccess.SetText (String.Format ("P: {0}/{1} {2}%", runner.PassedCount, runner.TestCount, 100 * runner.PassedCount / runner.TestCount)) this.lblFailed.SetText (String.Format ("F: {0}/{1} {2}%", runner.FailedCount, runner.TestCount, 100 * runner.FailedCount / runner.TestCount)) this.lblIgnInc.SetText (String.Format ("I: {0}/{1} {2}%", (runner.IgnoredCount + runner.InconclusiveCount), runner.TestCount, 100 * (runner.IgnoredCount + runner.InconclusiveCount) / runner.TestCount)) if running && runner.PassedCount > 0 then if runner.FailedCount = 0 then this.lblSuccess.SetTextColor (UIKit.UIColor.Green); this.lblStatus.SetTextColor (UIKit.UIColor.Green); this.lblStatus.SetText ("Success"); if runner.FailedCount > 0 then this.lblFailed.SetTextColor (UIKit.UIColor.Red); this.lblStatus.SetTextColor (UIKit.UIColor.Red); this.lblStatus.SetText ("Failed"); member this.RunTests () = if running then printf "Already running" else let running = true this.cmdRun.SetEnabled (false) this.lblStatus.SetText ("Running") this.BeginInvokeOnMainThread (fun v -> runner.Run () this.lblStatus.SetText ("Done") let running = false this.RenderResults () ) [] member this.RunTests (obj: NSObject) = this.RunTests ()