public void Union3_MatchShouldInvokeTheFunctionForTheThirdCase() => Assert.IsTrue( Union3 <int, string, bool> .Case3(false) .Match( case1 => false, case2 => false, case3 => true));
private async Task TryGetToken(TokenListener tokenListener) { _loginTask = _loginTask ?? _internalAuthService.LoginWithXToken(_userInfo.Xtoken); Union3 <UserInfo, LoginErrorDto, Exception> loginResult = await _loginTask; loginResult.Match(userInfo => { _userInfo.Token = userInfo.Token; _userInfo.Uid = userInfo.Uid; tokenListener.OnTokenReceived(_userInfo.Token); }, error => { tokenListener.OnTokenRefreshFailed(error.Error); AppAnalytics.Instance.TrackError(error.ErrorDescription); }, ex => { tokenListener.OnTokenRefreshFailed(ex.Message); AppAnalytics.Instance.TrackError(ex); }); _loginTask = null; }
public async Task <UserInfoUnion> Login(string userName, string password, CaptchaAnswer captchaAnswer = null) { _logger.Method().Start($"{userName} | {captchaAnswer}"); Union3 <UserInfo, LoginErrorDto, Exception> userInfoUnion = await _internalAuthService.Login(userName, password, captchaAnswer); return(userInfoUnion.Match(userInfo => { ProcessUserInfo(userInfo); return new UserInfoUnion.Case1(userInfo.RetWithLog(_logger).Log()); }, error => string.IsNullOrWhiteSpace(error.CaptchaKey) || string.IsNullOrWhiteSpace(error.CaptchaUrl) ? (UserInfoUnion) new UserInfoUnion.Case2(new LoginError(error.Error, error.ErrorDescription).RetWithLog(_logger).Log()) : new UserInfoUnion.Case4(new CaptchaQuery(error.CaptchaKey, error.CaptchaUrl).RetWithLog(_logger).Log()), ex => new UserInfoUnion.Case3(ex.RetWithLog(_logger).Log()))); }
public void Union3_TwoUnionsWithTheDifferentTypesShouldNotBeEqual() => Assert.AreNotEqual( Union3 <int, string, bool> .Case1(1), Union3 <string, bool, int> .Case2(true));
public void Union3_TwoUnionsWithTheSameTypeButDifferentCaseShouldNotBeEqual() => Assert.AreNotEqual( Union3 <int, string, bool> .Case1(1), Union3 <int, string, bool> .Case2("1"));
public void Union3_TwoUnionsWithTheSameTypeAndCaseAndValueShouldBeEqual() => Assert.AreEqual( Union3 <int, string, bool> .Case1(1), Union3 <int, string, bool> .Case1(1));