public Task <int?> AskKPIAsync(int max, int min = 1) { var newTcs = new TaskCompletionSource <int?>(); if (System.Threading.Interlocked.CompareExchange(ref _askKpiTcs, newTcs, null) != null)//if _askKpiTcs == null then _askKpiTcs = newTcs; return origianl value of _askKpiTcs { throw new InvalidOperationException("only one dialog can be active at a time"); } var view = new AskKpiView() { MinKPI = min, MaxKPI = max }; void handelClose(object sender, object output) { var result = output as AskKPIResult; var tcs = System.Threading.Interlocked.Exchange(ref _askKpiTcs, null);//_askKpiTcs = null; return original value of _askKpiTcs view.OnClosed -= handelClose; if (result == null || result.DialogResult == DialogResult.Cancel) { tcs?.SetResult(null); } else if (result.IsSTM) { tcs?.SetResult(-1); } else { tcs?.SetResult(result.KPI); } } view.OnClosed += handelClose; GetCurrentPage().Navigation.PushModalAsync(view); return(_askKpiTcs.Task); }
[InlineData("101", 100, 10, 101, null)]//ignore max if less than min public void CheckInput_test(string input, int minKPI, int maxKPI, int?expectedKpi, string expectedErrorMessage) { var result = AskKpiView.CheckInput(input, minKPI, maxKPI, out var errormessage); if (expectedErrorMessage != null) { result.Should().BeNull(); if (expectedErrorMessage == "something") { Output.WriteLine(errormessage); } else { errormessage.Should().Be(expectedErrorMessage); } } if (expectedKpi != null) { result.KPI.Should().Be(expectedKpi); } }
public void CheckInput_test_stm() { var result = AskKpiView.CheckInput("STM", null, null, out var errormessage); result.IsSTM.Should().BeTrue(); }