public async Task GetDifficultiesById()
        {
            // Arrange

            // Act
            var result = await sut.GetById(1);

            // Assert
            Assert.That(result.Success, Is.True);
            Assert.That((Difficulty)result.Object, Is.InstanceOf <Difficulty>());
        }
        public async Task <IDifficultyResult> GetDifficulty(
            int id, bool fullRecord = true)
        {
            var result = new DifficultyResult();

            if (id == 0)
            {
                result.Success = false;
                result.Message = DifficultiesMessages.DifficultiesNotFoundMessage;

                return(result);
            }

            try
            {
                var response = await difficultiesRepository.GetById(id, fullRecord);

                if (response.Success)
                {
                    result.Success    = response.Success;
                    result.Message    = DifficultiesMessages.DifficultyFoundMessage;
                    result.Difficulty = (Difficulty)response.Object;

                    return(result);
                }
                else if (!response.Success && response.Exception != null)
                {
                    result.Success = response.Success;
                    result.Message = response.Exception.Message;

                    return(result);
                }
                else
                {
                    result.Success = false;
                    result.Message = DifficultiesMessages.DifficultyNotFoundMessage;

                    return(result);
                }
            }
            catch (Exception exp)
            {
                result.Success = false;
                result.Message = exp.Message;

                return(result);
            }
        }
        public async Task <IGameResult> CreateGame(
            ICreateGameRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var result = new GameResult();

            try
            {
                var userResponse = await usersRepository.GetById(request.UserId);

                if (userResponse.Success)
                {
                    var difficultyResponse = await difficultiesRepository.GetById(request.DifficultyId);

                    if (difficultyResponse.Success)
                    {
                        var game = new Game(
                            (User)userResponse.Object,
                            new SudokuMatrix(),
                            (Difficulty)difficultyResponse.Object,
                            request.AppId);

                        game.SudokuMatrix.GenerateSolution();

                        var gameResponse = await gamesRepository.Add(game);

                        if (gameResponse.Success)
                        {
                            ((IGame)gameResponse.Object).User = null;
                            ((IGame)gameResponse.Object).SudokuMatrix.Difficulty.Matrices = new List <SudokuMatrix>();
                            ((IGame)gameResponse.Object).SudokuMatrix.SudokuCells.OrderBy(cell => cell.Index);

                            result.Success = gameResponse.Success;
                            result.Message = GamesMessages.GameCreatedMessage;
                            result.Game    = (IGame)gameResponse.Object;

                            return(result);
                        }
                        else if (!gameResponse.Success && gameResponse.Exception != null)
                        {
                            result.Success = gameResponse.Success;
                            result.Message = gameResponse.Exception.Message;

                            return(result);
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = GamesMessages.GameNotCreatedMessage;

                            return(result);
                        }
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = DifficultiesMessages.DifficultyDoesNotExistMessage;

                        return(result);
                    }
                }
                else
                {
                    result.Success = false;
                    result.Message = UsersMessages.UserDoesNotExistMessage;

                    return(result);
                }
            }
            catch (Exception exp)
            {
                result.Success = false;
                result.Message = exp.Message;

                return(result);
            }
        }