public async Task UserStartGame_ShouldDoNotAddUserToGame_IfUserAureadyExistInThisGame() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "10" }; await sut.UserStartGame("7", user); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.AddRangeAsync(It.IsAny <List <GameLevelParticipant> >()), Times.Never); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); gameRepoBuilder.GamesRepoMock.Verify(); levelsRepoBuilder.LevelsRepoMock.Verify(); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); }
public async Task UserStartGame_ShouldThrowIfGameNotExist() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "1" }; var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.UserStartGame("11", user)); Assert.Equal("Game do not exist!", ex.Message); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.AddRangeAsync(It.IsAny <List <GameLevelParticipant> >()), Times.Never); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); gameRepoBuilder.GamesRepoMock.Verify(); levelsRepoBuilder.LevelsRepoMock.Verify(); }
public async Task UserAddImageToLevel_ShouldDoNotAddItIfUserIsNotInThisGame() { var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(null, null, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "6" }; await sut.UserAddImageToLevel("7", user, "1", SetupFileMock().Object); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); }
public async Task AddLevelResult_ShouldThrow_IfGameLevelParticipantNotExist() { var userRepoBuilder = new GoUserRepositoryBuilder(); var userRepo = userRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(null, levelRepo, levelsParticipantsRepo, userRepo, Mapper); var user = new GoUser { Id = "1" }; var gameLevelUserViewModel = new GameLevelParticipantViewModel { GameId = "7", LevelId = "6", ParticipantId = "10", Participant = "Saso", CorrespondingImage = ConvertImageToByteArray(SetupFileMock().Object), StatusLevel = StatusLevel.SuccessfullyPassed }; var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.AddLevelResult(gameLevelUserViewModel, user)); Assert.Equal("This GameLevelParticipant not exist!", ex.Message); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); userRepoBuilder.UsersRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); }
public async Task AddLevelResult_ShouldAddResultToGameLevelUserCorrect() { var userRepoBuilder = new GoUserRepositoryBuilder(); var userRepo = userRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(null, levelRepo, levelsParticipantsRepo, userRepo, Mapper); var user = new GoUser { Id = "1" }; var gameLevelUserViewModel = new GameLevelParticipantViewModel { GameId = "7", LevelId = "3", ParticipantId = "10", Participant = "Saso", CorrespondingImage = ConvertImageToByteArray(SetupFileMock().Object), StatusLevel = StatusLevel.SuccessfullyPassed }; await sut.AddLevelResult(gameLevelUserViewModel, user); userRepoBuilder.UsersRepoMock.Verify(); levelsRepoBuilder.LevelsRepoMock.Verify(); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); userRepoBuilder.UsersRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once); }
public async Task UserAddImageToLevel_ShouldThrowIfUserIsPassedThisLevelSuccessffuly() { var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(null, null, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "9" }; var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.UserAddImageToLevel("7", user, "1", SetupFileMock().Object)); Assert.Equal("You are auready pass successfully this level!", ex.Message); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); }
public void GetDetails_ShouldReturn_GameDetailsViewModel() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var usersRepoBuilder = new GoUserRepositoryBuilder(); var userRepo = usersRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, levelsParticipantsRepo, userRepo, Mapper); var actual = sut.GetDetails("7"); var expected = new GameDetailsViewModel { Id = "7", Name = "Nameri mqstoto", Description = "nameriiiiiiiiiii", Creator = "Niki", Level1 = new LevelViewModel { Id = "1", Description = "mmmmm", Points = 1, GameId = "7", NumberInGame = 1, Image = levelRepo.All().FirstOrDefault(x => x.Id == "1").Image }, Level2 = new LevelViewModel { Id = "2", Description = "nnnnnnnnnnnnnnnn", Points = 3, GameId = "7", NumberInGame = 2, Image = levelRepo.All().FirstOrDefault(x => x.Id == "2").Image }, Level3 = new LevelViewModel { Id = "3", Description = "rrrrrrrrrrrrrrrrrr", Points = 5, GameId = "7", NumberInGame = 3, Image = levelRepo.All().FirstOrDefault(x => x.Id == "3").Image }, GameParticipantsLevel1 = new List <GameLevelParticipantViewModel> { new GameLevelParticipantViewModel { GameId = "7", LevelId = "1", ParticipantId = "10", Participant = "Saso ", CorrespondingImage = ConvertImageToByteArray(SetupFileMock().Object), StatusLevel = StatusLevel.NotPassed } }, GameParticipantsLevel2 = new List <GameLevelParticipantViewModel> { new GameLevelParticipantViewModel { GameId = "7", LevelId = "2", ParticipantId = "10", Participant = "Saso ", CorrespondingImage = ConvertImageToByteArray(SetupFileMock().Object), StatusLevel = StatusLevel.NotPassed } }, GameParticipantsLevel3 = new List <GameLevelParticipantViewModel> { new GameLevelParticipantViewModel { GameId = "7", LevelId = "3", ParticipantId = "10", Participant = "Saso ", CorrespondingImage = ConvertImageToByteArray(SetupFileMock().Object), StatusLevel = StatusLevel.NotPassed } } }; Assert.Equal(expected, actual, new GameDetailsViewModelComparer()); Assert.Equal(expected.Level1, actual.Level1, new LevelViewModelComparer()); Assert.Equal(expected.Level2, actual.Level2, new LevelViewModelComparer()); Assert.Equal(expected.Level3, actual.Level3, new LevelViewModelComparer()); Assert.Equal(expected.GameParticipantsLevel1, actual.GameParticipantsLevel1, new GameLevelParticipantViewModelComparer()); Assert.Equal(expected.GameParticipantsLevel2, actual.GameParticipantsLevel2, new GameLevelParticipantViewModelComparer()); Assert.Equal(expected.GameParticipantsLevel3, actual.GameParticipantsLevel3, new GameLevelParticipantViewModelComparer()); gameRepoBuilder.GamesRepoMock.Verify(); }