public void Initialize() { using (var dbContext = DataContextCreator.CreateTestContext()) { SqlScriptRunner.RunAddTestDataScript(dbContext); } }
public void GetByIgdbIds_GamesNotInDatabaseNotReturned_ActualCountEqualsExpected() { var expectedIgdbIdsInDb = new int[] { 1331, 1277, 115 }; var igdbIdsNotInDB = new int[] { 434, 3432, 434, 4344 }; var ids = new List <int>(); ids.AddRange(expectedIgdbIdsInDb); ids.AddRange(igdbIdsNotInDB); using (var gameManager = new GameManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { var games = gameManager.GetByIgdbIds(ids.ToArray()); foreach (var gameId in expectedIgdbIdsInDb) { Assert.IsNotNull(games.FirstOrDefault(p => p.igdbID == gameId)); } foreach (var gameId in igdbIdsNotInDB) { Assert.IsNull(games.FirstOrDefault(p => p.igdbID == gameId)); } } }
public async Task TestMethod1() { using (var unitOfWork = new BrothershipUnitOfWork(DataContextCreator.CreateTestContext())) { var twitchClient = new TwitchClient(); var userIntegration = unitOfWork.UserIntegrations.GetById(1, (int)IntegrationType.IntegrationTypes.Twitch); var content = await twitchClient.GetRecentVideo(userIntegration.ChannelId, 0, 10); } }
public void GetByIgdbIds_GamesInDataBaseReturn_ActualCountEqualsExpected() { var expectedIgdbIds = new int[] { 1331, 1277, 115 }; using (var gameManager = new GameManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { var games = gameManager.GetByIgdbIds(expectedIgdbIds); Assert.AreEqual(expectedIgdbIds.Length, games.Count); } }
public async Task GetByUserName_InValidUserName_ReturnsNull() { using (var userManager = new UserManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { var invalidUserName = "******"; var actualUser = userManager.GetByUserName(invalidUserName); Assert.IsNull(actualUser); } }
public async Task GetByUserName_ValidUserName_ReturnsUser() { using (var userManager = new UserManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { var expectedUserName = "******"; var actualUser = userManager.GetByUserName(expectedUserName); Assert.AreEqual(expectedUserName, actualUser.UserName); } }
public void UpdatePassword_IncorrentCurrentPassword_ThrowsInvalidPasswordException() { using (var userManager = new UserManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { const string userName = "******"; const string currentPassword = "******"; const string newPassword = "******"; var user = userManager.Login(userName, "Password"); userManager.UpdatePassword(currentPassword, newPassword, user); } }
public void GetAll_AllNationalitiesReturned_CountEqualsActual() { const int expectedCount = 3; int actualCount; using (var nationalityRepo = new NationalityRepository(DataContextCreator.CreateTestContext())) { actualCount = nationalityRepo.GetAll().Count(); } Assert.AreEqual(expectedCount, actualCount); }
public void GetAll_AllGendersReturned_CountEqualsActual() { const int expectedCount = 3; int actualCount; using (var genderRepo = new GenderRepository(DataContextCreator.CreateTestContext())) { actualCount = genderRepo.GetAll().Count(); } Assert.AreEqual(expectedCount, actualCount); }
public async Task AddGameIfNotExistAsync_ExistingGameNotAdded_TotalGameCountIsNotChanged() { using (var gameManager = new GameManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { const int gameIdToAdd = 1331; int gameCount = gameManager.GetAll().Count; await gameManager.AddGameIfNotExistAsync(gameIdToAdd); int newGameCount = gameManager.GetAll().Count; Assert.IsTrue(gameCount == newGameCount); } }
public async Task AddGameIfNotExistAsync_NonExistingGameAdded_TotalGameCountIncreasedByOne() { using (var gameManager = new GameManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { const int gameIdToAdd = 5314; int gameCount = gameManager.GetAll().Count; await gameManager.AddGameIfNotExistAsync(gameIdToAdd); int newGameCount = gameManager.GetAll().Count; Assert.IsTrue(gameCount + 1 == newGameCount); } }
public void DeleteById_WasDeleted_ActualDataIsNull() { var typeIdToDelete = AddandGetTestNationality().ID; Nationality actualNationality; using (var nationalityRepo = new NationalityRepository(DataContextCreator.CreateTestContext())) { nationalityRepo.Delete(typeIdToDelete); nationalityRepo.SaveChanges(); actualNationality = nationalityRepo.GetById(typeIdToDelete); } Assert.IsNull(actualNationality); }
public async Task Update_WasDataUpdated_ExpectedDataEqualsActual() { using (var userManager = new UserManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { const int expectedCount = 4; const int userId = 1; var expectedUser = new User { ID = 1, Bio = "UpdatedBio", DOB = new DateTime(1999, 3, 22), Email = "*****@*****.**", GenderId = 2, DateJoined = new DateTime(2017, 2, 20), ProfileImagePath = "UpdatedImagePath.jpg", UserTypeID = 1, UserName = "******", NationalityID = 1, Games = new List <Game> { new Game { igdbID = 4325 }, new Game { igdbID = 1277 }, new Game { igdbID = 2276 }, new Game { igdbID = 1039 } } }; await userManager.Update(expectedUser); var actualUser = userManager.GetById(userId); AssertUsersEqual(expectedUser, actualUser); Assert.AreEqual(expectedCount, actualUser.Games.Count); foreach (var game in expectedUser.Games) { Assert.IsNotNull(actualUser.Games.FirstOrDefault(p => p.igdbID == game.igdbID)); } } }
public void DeleteByEntity_WasDeleted_ActualGameIsNull() { Game actualGame; var typeToDelete = AddandGetTestGame(); using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { gameRepo.Delete(typeToDelete); gameRepo.SaveChanges(); actualGame = gameRepo.GetById(typeToDelete.ID); } Assert.IsNull(actualGame); }
public void DeleteById_WasDeleted_ActualDataIsNull() { var typeIdToDelete = AddandGetTestGender().Id; Gender actualGender; using (var genderRepo = new GenderRepository(DataContextCreator.CreateTestContext())) { genderRepo.Delete(typeIdToDelete); genderRepo.SaveChanges(); actualGender = genderRepo.GetById(typeIdToDelete); } Assert.IsNull(actualGender); }
public void UpdatePassword_PasswordUpdated_CanLoginWithNewPassword() { using (var userManager = new UserManager(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))) { const string userName = "******"; const string currentPassword = "******"; const string newPassword = "******"; var user = userManager.Login(userName, "Password"); userManager.UpdatePassword(currentPassword, newPassword, user); user = userManager.Login(userName, newPassword); Assert.IsFalse(user is InvalidUser); } }
private Nationality AddandGetTestNationality() { var nationalityType = new Nationality { Description = "TestType" }; using (var nationalityRepo = new NationalityRepository(DataContextCreator.CreateTestContext())) { nationalityRepo.Add(nationalityType); nationalityRepo.SaveChanges(); } return(nationalityType); }
public void DeleteById_WasDeleted_ActualGameDataIsNull() { var typeIdToDelete = AddandGetTestGame().ID; Game actualGame; using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { Game game = gameRepo.GetById(typeIdToDelete); game.GameCategories.Clear(); gameRepo.Delete(typeIdToDelete); gameRepo.SaveChanges(); actualGame = gameRepo.GetById(typeIdToDelete); Assert.IsNull(actualGame); } }
private Gender AddandGetTestGender() { var genderType = new Gender { Description = "TestGender" }; using (var genderRepo = new GenderRepository(DataContextCreator.CreateTestContext())) { genderRepo.Add(genderType); genderRepo.SaveChanges(); } return(genderType); }
public void GetById_CorrectDataGot_EqualsExpectedData() { var expectedGender = new Gender { Id = 1, Description = "Male" }; Gender actualGender; using (var genderRepo = new GenderRepository(DataContextCreator.CreateTestContext())) { actualGender = genderRepo.GetById(expectedGender.Id); } AssertGendersEqual(expectedGender, actualGender); }
public void GetById_CorrectDataGot_ActualEqualsExpectedData() { var expectedNationality = new Nationality { ID = 1, Description = "US and A" }; Nationality actualNationality; using (var nationalityRepo = new NationalityRepository(DataContextCreator.CreateTestContext())) { actualNationality = nationalityRepo.GetById(expectedNationality.ID); } AssertNationalitysEqual(expectedNationality, actualNationality); }
public async Task GetAuthorization_InvalidCodeIsNotInserted_IntegrationNotInDB() { using (var unitOfWork = new BrothershipUnitOfWork(DataContextCreator.CreateTestContext())) { const string InValidCode = "ThisIsNotACode"; const int expectedUserId = 2; using (TwitchIntegration twitchIntegration = new TwitchIntegration(unitOfWork, new TwitchClientFake())) { await twitchIntegration.AuthorizeTwitch(expectedUserId, InValidCode); var userIntegration = unitOfWork.UserIntegrations.GetById(expectedUserId, (int)IntegrationType.IntegrationTypes.Twitch); Assert.IsNull(userIntegration); } } }
public void Add_WasGenderAdded_ActualEqualsExpectedData() { var expectedGender = new Gender { Description = "Test Gender" }; Gender actualGender; using (var genderRepo = new GenderRepository(DataContextCreator.CreateTestContext())) { genderRepo.Add(expectedGender); genderRepo.SaveChanges(); actualGender = genderRepo.GetById(expectedGender.Id); } AssertGendersEqual(expectedGender, actualGender); }
public void Add_ActualAddedData_ActualEqualsExpectedData() { var expectedNationality = new Nationality { Description = "Beam" }; Nationality actualNationality; using (var nationalityRepo = new NationalityRepository(DataContextCreator.CreateTestContext())) { nationalityRepo.Add(expectedNationality); nationalityRepo.SaveChanges(); actualNationality = nationalityRepo.GetById(expectedNationality.ID); } AssertNationalitysEqual(expectedNationality, actualNationality); }
private Game AddandGetTestGame() { var game = new Game { igdbID = 23434, Title = "Test Game", }; game.GameCategories.Add(new GameCategory { ID = 11, Description = "Real Time Strategy (RTS)" }); using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { gameRepo.Add(game); gameRepo.SaveChanges(); } return(game); }
public void GetById_CorrectDataGot_ActualEqualsExpected() { var expectedGame = new Game { ID = 4, GameCategories = new List <GameCategory> { new GameCategory { ID = 31, Description = "Adventure" } }, igdbID = null, Title = "Fallout 4", }; Game actualGame; using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { actualGame = gameRepo.GetById(expectedGame.ID); AssertGamesEqual(expectedGame, actualGame); } }
public void GetByIgdbId_WasCorrectGameGot_ExpectedDataEqualsActual() { var expectedGame = new Game { ID = 40, igdbID = 1277, GameCategories = new List <GameCategory> { new GameCategory { ID = 11, Description = "Real Time Strategy (RTS)" } }, Title = "Plants vs. Zombies" }; Game actualGame; using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { gameRepo.GetByIgdbId((int)expectedGame.igdbID); gameRepo.SaveChanges(); actualGame = gameRepo.GetById(expectedGame.ID); AssertGamesEqual(expectedGame, actualGame); } }
public void Add_WasDataAdded_ActualEqualsExpected() { var expectedGame = new Game { GameCategories = new List <GameCategory> { new GameCategory { ID = 12, Description = "Role-playing (RPG)" } }, igdbID = 243242, Title = "Best Test Game", }; Game actualGame; using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { gameRepo.Add(expectedGame); gameRepo.SaveChanges(); actualGame = gameRepo.GetById(expectedGame.ID); } AssertGamesEqual(expectedGame, actualGame); }
public void Update_WasGameUpdatad_ExpectedEqualsActual() { var expectedGame = new Game { ID = 2, igdbID = 3452354, GameCategories = new List <GameCategory> { new GameCategory { ID = 312 } }, Title = "Test Updated Title" }; Game actualGame; using (var gameRepo = new GameRepository(DataContextCreator.CreateTestContext())) { gameRepo.Update(expectedGame); gameRepo.SaveChanges(); actualGame = gameRepo.GetById(expectedGame.ID); } AssertGamesEqual(expectedGame, actualGame); }
public async Task DeAuthorize_IsSucessfull_NoIntegrationInDB() { using (var unitOfWork = new BrothershipUnitOfWork(DataContextCreator.CreateTestContext())) { const int expectedUserId = 2; unitOfWork.UserIntegrations.Add(new UserIntegration { IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Twitch, Token = "token", UserName = "******", UserID = expectedUserId, }); unitOfWork.Commit(); using (TwitchIntegration twitchIntegration = new TwitchIntegration(unitOfWork, new TwitchClientFake())) { await twitchIntegration.DeAuthorizeTwitch(expectedUserId); var userIntegration = unitOfWork.UserIntegrations.GetById(expectedUserId, (int)IntegrationType.IntegrationTypes.Twitch); Assert.IsNull(userIntegration); } } }