public async Task ChangePasswordCodeTest(int userId, string newPassword, string appKey, bool exception, Type exceptionType = null) { var userRep = UserRepositoryMock.CreateRepository(); try { await ChangePassword.Execute(userRep, userId, newPassword, appKey); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task CreateUserTest(string appKey, string userName, string password, bool exception, Type exceptionType = null) { var userRep = UserRepositoryMock.CreateRepository(); var appRep = AppRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, appKey, userName, password); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task ChangePasswordFlowTest(int userId, string newPassword, string appKey, bool callGetById, bool callChangePassword) { var userRep = UserRepositoryMock.CreateRepository(); try { await ChangePassword.Execute(userRep, userId, newPassword, appKey); Assert.AreEqual(userRep.GetByIdCount, callGetById ? 1 : 0); Assert.AreEqual(userRep.ChangePasswordCount, callChangePassword ? 1 : 0); } catch { Assert.AreEqual(userRep.GetByIdCount, callGetById ? 1 : 0); Assert.AreEqual(userRep.ChangePasswordCount, callChangePassword ? 1 : 0); } }
public async Task LoginCodeTest(string appKey, string userName, string password, string device, bool exception, Type exceptionType = null) { var userRep = UserRepositoryMock.CreateRepository(); var tokenRep = TokenRepositoryMock.CreateRepository(); var tokenCreator = TokenCreatorMock.Create(); try { await Login.Execute(tokenRep, userRep, tokenCreator, appKey, userName, password, device); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task ChangePasswordCodeTest(string token, string currentPassword, string newPassword, string appKey, string device, bool exception, Type exceptionType = null) { var userRep = UserRepositoryMock.CreateRepository(); var tokenRepository = TokenRepositoryMock.CreateRepository(); try { await ChangeMyPassword.Execute(tokenRepository, userRep, token, currentPassword, newPassword, appKey, device); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task CreateUserFlowTest(string token, string appKey, string device, bool callGetUserIdByTokenCount, bool callGetByIdCount) { var tokenRep = TokenRepositoryMock.CreateRepository(); var userRep = UserRepositoryMock.CreateRepository(); var tokenExtactor = TokenInfoExtractorMock.Create(); try { await GetTokenInfo.Execute(tokenRep, userRep, tokenExtactor, token, appKey, device); Assert.AreEqual(userRep.GetByIdCount, callGetByIdCount ? 1 : 0); Assert.AreEqual(tokenRep.GetUserIdByTokenCount, callGetUserIdByTokenCount ? 1 : 0); } catch { Assert.AreEqual(userRep.GetByIdCount, callGetByIdCount ? 1 : 0); Assert.AreEqual(tokenRep.GetUserIdByTokenCount, callGetUserIdByTokenCount ? 1 : 0); } }
public async Task CreateUserFlowTest(string appKey = "", string userName = "", string password = "", bool incCreate = false, bool incGetByKeyToAppCount = false, bool incAppGetByKey = false) { var userRep = UserRepositoryMock.CreateRepository(); var appRep = AppRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, appKey, userName, password); Assert.AreEqual(userRep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(userRep.GetByKeyToAppCount, incGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(appRep.GetByKeyCount, incAppGetByKey ? 1 : 0, "Não deveria ter chamado a verificação de app"); } catch { Assert.AreEqual(userRep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(userRep.GetByKeyToAppCount, incGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(appRep.GetByKeyCount, incAppGetByKey ? 1 : 0, "Não deveria ter chamado a verificação de app"); } }
public async Task LoginFlowTest(string appKey = "", string userName = "", string password = "", string device = "", bool callGetByKeyToAppCount = false, bool callCreateToken = false, bool callTokenCreator = false) { var userRep = UserRepositoryMock.CreateRepository(); var tokenRep = TokenRepositoryMock.CreateRepository(); var tokenCreator = TokenCreatorMock.Create(); try { await Login.Execute(tokenRep, userRep, tokenCreator, appKey, userName, password, device); Assert.AreEqual(userRep.GetByKeyToAppCount, callGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(tokenRep.CreateCount, callCreateToken ? 1 : 0); Assert.AreEqual(tokenCreator.CreateCount, callTokenCreator ? 1 : 0); } catch { Assert.AreEqual(userRep.GetByKeyToAppCount, callGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(tokenRep.CreateCount, callCreateToken ? 1 : 0); Assert.AreEqual(tokenCreator.CreateCount, callTokenCreator ? 1 : 0); } }
public async Task ChangeMyPasswordFlowTest(string token, string currentPassword, string newPassword, string appKey, string device, bool callGetUserIdByToken, bool callGetById, bool callChangePassword) { var userRep = UserRepositoryMock.CreateRepository(); var tokenRepository = TokenRepositoryMock.CreateRepository(); try { await ChangeMyPassword.Execute(tokenRepository, userRep, token, currentPassword, newPassword, appKey, device); Assert.AreEqual(userRep.GetByIdCount, callGetById ? 1 : 0); Assert.AreEqual(userRep.ChangePasswordCount, callChangePassword ? 1 : 0); Assert.AreEqual(tokenRepository.GetUserIdByTokenCount, callGetUserIdByToken ? 1 : 0); } catch { Assert.AreEqual(userRep.GetByIdCount, callGetById ? 1 : 0); Assert.AreEqual(userRep.ChangePasswordCount, callChangePassword ? 1 : 0); Assert.AreEqual(tokenRepository.GetUserIdByTokenCount, callGetUserIdByToken ? 1 : 0); } }
public async Task ChangePasswordInvalidParametersTest(bool isUserRepNull, int userId, string newPassword, string appKey) { var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); try { await ChangePassword.Execute(userRep, userId, newPassword, appKey); Assert.Fail(); } catch (Exception ex) { if (isUserRepNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }
public async Task CreateUserInvalidParametersTest(bool isAppRepNull, bool isUserRepNull, string key = "", string userName = "", string password = "") { var appRep = isAppRepNull ? null : AppRepositoryMock.CreateRepository(); var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, key, userName, password); Assert.Fail(); } catch (Exception ex) { if (isAppRepNull || isUserRepNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }
public async Task LoginInvalidParametersTest(bool isTokenRepNull, bool isUserRepNull, bool isTokenCreatorNull, string key = "", string userName = "", string password = "", string device = "") { var tokenRep = isTokenRepNull ? null : TokenRepositoryMock.CreateRepository(); var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); var tokenCreator = isTokenCreatorNull ? null : TokenCreatorMock.Create(); try { await Login.Execute(tokenRep, userRep, tokenCreator, key, userName, password, device); Assert.Fail(); } catch (Exception ex) { if (isTokenRepNull || isUserRepNull || isTokenCreatorNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }
public async Task GetTokenInfoInvalidParametersTest(bool isTokenRepNull, bool isUserRepNull, bool isTokenExtractorNull, string token, string appKey, string device) { var tokenRep = isTokenRepNull ? null : TokenRepositoryMock.CreateRepository(); var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); var tokenExytactor = isTokenExtractorNull ? null : TokenInfoExtractorMock.Create(); try { await GetTokenInfo.Execute(tokenRep, userRep, tokenExytactor, token, appKey, device); Assert.Fail(); } catch (Exception ex) { if (isTokenRepNull || isUserRepNull || isTokenExtractorNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }
public async Task ChangeMyPasswordInvalidParametersTest(bool isUserRepNull, bool isTokenRepNull, string token, string currentPassword, string newPassword, string appKey, string device) { var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); var tokenRepository = isTokenRepNull ? null : TokenRepositoryMock.CreateRepository(); try { await ChangeMyPassword.Execute(tokenRepository, userRep, token, currentPassword, newPassword, appKey, device); Assert.Fail(); } catch (Exception ex) { if (isUserRepNull || isTokenRepNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }