示例#1
0
        public async Task Setup()
        {
            context = await TestDatabase.GetDatabaseContext();

            MockSolutionsRepository = new MockSolutionsRepository(context);

            sut = new SolutionsService(
                MockSolutionsRepository.SolutionsRepositorySuccessfulRequest.Object);

            sutFailure = new SolutionsService(
                MockSolutionsRepository.SolutionsRepositoryFailedRequest.Object);

            baseRequest = TestObjects.GetBaseRequest();
        }
示例#2
0
        public async Task Setup()
        {
            context = await TestDatabase.GetDatabaseContext();

            mockGamesRepository = new MockGamesRepository(context);
            mockAppsRepository  = new MockAppsRepository(context);
            mockUsersRepository = new MockUsersRepository(context);
            mockDifficultiesRepositorySuccessful = new MockDifficultiesRepository(context);
            mockDifficultiesRepositoryFailed     = new MockDifficultiesRepository(context);
            mockSolutionsRepository = new MockSolutionsRepository(context);

            sut = new GamesService(
                mockGamesRepository.GamesRepositorySuccessfulRequest.Object,
                mockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                mockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                mockDifficultiesRepositorySuccessful.DifficultiesRepositorySuccessfulRequest.Object,
                mockSolutionsRepository.SolutionsRepositorySuccessfulRequest.Object);

            sutFailure = new GamesService(
                mockGamesRepository.GamesRepositoryFailedRequest.Object,
                mockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                mockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                mockDifficultiesRepositorySuccessful.DifficultiesRepositorySuccessfulRequest.Object,
                mockSolutionsRepository.SolutionsRepositorySuccessfulRequest.Object);

            sutAnonFailure = new GamesService(
                mockGamesRepository.GamesRepositorySuccessfulRequest.Object,
                mockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                mockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                mockDifficultiesRepositoryFailed.DifficultiesRepositoryFailedRequest.Object,
                mockSolutionsRepository.SolutionsRepositorySuccessfulRequest.Object);

            sutUpdateFailure = new GamesService(
                mockGamesRepository.GamesRepositoryUpdateFailedRequest.Object,
                mockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                mockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                mockDifficultiesRepositorySuccessful.DifficultiesRepositorySuccessfulRequest.Object,
                mockSolutionsRepository.SolutionsRepositorySuccessfulRequest.Object);

            getGamesRequest = TestObjects.GetGamesRequest();
        }
示例#3
0
        public MockSolutionsService(DatabaseContext context)
        {
            MockSolutionsRepository = new MockSolutionsRepository(context);
            MockUsersRepository     = new MockUsersRepository(context);

            SolutionsServiceSuccessfulRequest  = new Mock <ISolutionsService>();
            SolutionsServiceFailedRequest      = new Mock <ISolutionsService>();
            SolutionsServiceSolveFailedRequest = new Mock <ISolutionsService>();

            SolutionsServiceSuccessfulRequest.Setup(solutionsService =>
                                                    solutionsService.GetSolution(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new SolutionResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositorySuccessfulRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Success,
                Message  = SolutionsMessages.SolutionFoundMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositorySuccessfulRequest
                           .Object
                           .GetById(It.IsAny <int>(), It.IsAny <bool>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceSuccessfulRequest.Setup(solutionsService =>
                                                    solutionsService.GetSolutions(It.IsAny <BaseRequest>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new SolutionsResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositorySuccessfulRequest
                          .Object
                          .GetAll(It.IsAny <bool>())
                          .Result
                          .Success,
                Message   = SolutionsMessages.SolutionsFoundMessage,
                Solutions = MockSolutionsRepository
                            .SolutionsRepositorySuccessfulRequest
                            .Object
                            .GetAll(It.IsAny <bool>())
                            .Result
                            .Objects
                            .ConvertAll(s => (ISudokuSolution)s)
            } as ISolutionsResult));

            SolutionsServiceSuccessfulRequest.Setup(solutionsService =>
                                                    solutionsService.Solve(It.IsAny <ISolutionRequest>()))
            .Returns(Task.FromResult(new SolutionResult()
            {
                Success  = true,
                Message  = SolutionsMessages.SudokuSolutionFoundMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositorySuccessfulRequest
                           .Object
                           .Create(It.IsAny <SudokuSolution>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceSuccessfulRequest.Setup(solutionsService =>
                                                    solutionsService.Generate()).Returns(
                Task.FromResult(new SolutionResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositorySuccessfulRequest
                          .Object
                          .Create(It.IsAny <SudokuSolution>())
                          .Result
                          .Success,
                Message  = SolutionsMessages.SolutionGeneratedMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositorySuccessfulRequest
                           .Object
                           .Create(It.IsAny <SudokuSolution>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceSuccessfulRequest.Setup(solutionsService =>
                                                    solutionsService.AddSolutions(It.IsAny <int>())).Returns(
                Task.FromResult(new BaseResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositorySuccessfulRequest
                          .Object
                          .AddSolutions(It.IsAny <List <ISudokuSolution> >())
                          .Result
                          .Success,
                Message = SolutionsMessages.SolutionsAddedMessage
            } as IBaseResult));

            SolutionsServiceFailedRequest.Setup(solutionsService =>
                                                solutionsService.GetSolution(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new SolutionResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositoryFailedRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Success,
                Message  = SolutionsMessages.SolutionNotFoundMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositoryFailedRequest
                           .Object
                           .GetById(It.IsAny <int>(), It.IsAny <bool>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceFailedRequest.Setup(solutionsService =>
                                                solutionsService.GetSolutions(It.IsAny <BaseRequest>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new SolutionsResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositoryFailedRequest
                          .Object
                          .GetAll(It.IsAny <bool>())
                          .Result
                          .Success,
                Message   = SolutionsMessages.SolutionsNotFoundMessage,
                Solutions = null
            } as ISolutionsResult));

            SolutionsServiceFailedRequest.Setup(solutionsService =>
                                                solutionsService.Solve(It.IsAny <ISolutionRequest>()))
            .Returns(Task.FromResult(new SolutionResult()
            {
                Success  = false,
                Message  = SolutionsMessages.SudokuSolutionNotFoundMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositoryFailedRequest
                           .Object
                           .Create(It.IsAny <SudokuSolution>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceFailedRequest.Setup(solutionsService =>
                                                solutionsService.Generate()).Returns(
                Task.FromResult(new SolutionResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositoryFailedRequest
                          .Object
                          .Create(It.IsAny <SudokuSolution>())
                          .Result
                          .Success,
                Message  = SolutionsMessages.SolutionNotGeneratedMessage,
                Solution = (SudokuSolution)MockSolutionsRepository
                           .SolutionsRepositoryFailedRequest
                           .Object
                           .Create(It.IsAny <SudokuSolution>())
                           .Result
                           .Object
            } as ISolutionResult));

            SolutionsServiceFailedRequest.Setup(solutionsService =>
                                                solutionsService.AddSolutions(It.IsAny <int>())).Returns(
                Task.FromResult(new BaseResult()
            {
                Success = MockSolutionsRepository
                          .SolutionsRepositoryFailedRequest
                          .Object
                          .AddSolutions(It.IsAny <List <ISudokuSolution> >())
                          .Result
                          .Success,
                Message = SolutionsMessages.SolutionsNotAddedMessage
            } as IBaseResult));

            SolutionsServiceSolveFailedRequest.Setup(solutionsService =>
                                                     solutionsService.Solve(It.IsAny <ISolutionRequest>()))
            .Returns(Task.FromResult(new SolutionResult()
            {
                Success  = true,
                Message  = SolutionsMessages.SudokuSolutionNotFoundMessage,
                Solution = null
            } as ISolutionResult));
        }