public void GetPopularAppFromServiceTest()//тест app сервиса с помощью мок репозитория { IAppRepository appRepository = new AppRepositoryMock(); AppService appService = new AppService(appRepository); string popular = appService.GetPopularAppVk("4063926"); Assert.AreEqual("Очень популярно", popular); popular = appService.GetPopularAppVk("4063927"); Assert.AreEqual("Непопулярно", popular); popular = appService.GetPopularAppVk("4063928"); Assert.AreEqual("Популярно", popular); }
public async Task CreateAppInvalidParametersTest(string appName, bool isRepNull) { var rep = isRepNull ? null : AppRepositoryMock.CreateRepository(); try { await CreateApp.Execute(rep, appName); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(ex.GetType(), isRepNull ? typeof(ArgumentNullException) : typeof(ArgumentException)); } }
public async Task CreateAppTest(string appName, bool exception, Type exceptionType = null) { var rep = AppRepositoryMock.CreateRepository(); try { await CreateApp.Execute(rep, appName); 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 CreateAppFlowTest(string appName, bool incCreate, bool incGetByName) { var rep = AppRepositoryMock.CreateRepository(); try { await CreateApp.Execute(rep, appName); Assert.AreEqual(rep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(rep.GetByNameCount, incGetByName ? 1 : 0); } catch { Assert.AreEqual(rep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(rep.GetByNameCount, incGetByName ? 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 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)); } } }