public async Task GetSolutionsById()
        {
            // Arrange

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

            // Assert
            Assert.That(result.Success, Is.True);
            Assert.That((SudokuSolution)result.Object, Is.InstanceOf <SudokuSolution>());
        }
Esempio n. 2
0
        public async Task <ISolutionResult> GetSolution(
            int id,
            bool fullRecord = true)
        {
            var result = new SolutionResult();

            if (id == 0)
            {
                result.Success = false;
                result.Message = SolutionsMessages.SolutionNotFoundMessage;

                return(result);
            }

            try
            {
                var solutionResponse = await solutionsRepository.GetById(id, fullRecord);

                if (solutionResponse.Success)
                {
                    var solution = (SudokuSolution)solutionResponse.Object;

                    if (fullRecord && solution.Game != null)
                    {
                        solution.Game.SudokuMatrix.Difficulty.Matrices = null;
                    }

                    result.Success  = solutionResponse.Success;
                    result.Message  = SolutionsMessages.SolutionFoundMessage;
                    result.Solution = solution;

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

                    return(result);
                }
                else
                {
                    result.Success = false;
                    result.Message = SolutionsMessages.SolutionNotFoundMessage;

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

                return(result);
            }
        }