public async Task <ActionResult <SudokuSolution> > Solve(
            [FromBody] SolutionRequest request)
        {
            var result = await solutionService.Solve(request);

            if (result.Success)
            {
                if (result.Solution != null)
                {
                    result.Message = ControllerMessages.StatusCode200(result.Message);

                    return(Ok(result));
                }
                else
                {
                    result.Message = ControllerMessages.StatusCode200(result.Message);

                    return(Ok(result));
                }
            }
            else
            {
                result.Message = ControllerMessages.StatusCode404(result.Message);

                return(NotFound(result));
            }
        }
Beispiel #2
0
        public async Task SolveSudokuMatrices()
        {
            // Arrange
            var solutionRequest = new SolutionRequest()
            {
                FirstRow = new List <int> {
                    0, 2, 0, 5, 0, 0, 8, 7, 6
                },
                SecondRow = new List <int> {
                    7, 0, 0, 1, 8, 0, 0, 5, 0
                },
                ThirdRow = new List <int> {
                    8, 5, 9, 7, 0, 0, 0, 4, 0
                },
                FourthRow = new List <int> {
                    5, 9, 0, 0, 0, 4, 6, 8, 1
                },
                FifthRow = new List <int> {
                    0, 1, 0, 0, 3, 0, 0, 0, 0
                },
                SixthRow = new List <int> {
                    0, 0, 0, 8, 6, 0, 0, 9, 5
                },
                SeventhRow = new List <int> {
                    2, 0, 7, 0, 0, 8, 0, 0, 9
                },
                EighthRow = new List <int> {
                    9, 0, 4, 0, 0, 7, 2, 0, 8
                },
                NinthRow = new List <int> {
                    0, 0, 0, 0, 0, 2, 4, 6, 0
                }
            };

            // Act
            var result = await sut.Solve((ISolutionRequest)solutionRequest);

            // Assert
            Assert.That(result.Success, Is.True);
            Assert.That(result.Message, Is.EqualTo("Sudoku Solution Found"));
            Assert.That(result.Solution, Is.TypeOf <SudokuSolution>());
        }