public async Task Test_UpsertMatches_Success()
        {
            _matchesServices.Setup(m => m.UpsertMatches(It.IsAny <List <DomainMatch> >(), It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "test-header";
            var controller = new MatchesController(_matchesServices.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = httpContext
                }
            };

            var response = await controller.UpsertMatches(new UpsertMatchesRequest()
            {
                UpsertMatches = new List <UpsertMatch>()
                {
                    { new UpsertMatch()
                      {
                          Id = 1, Matched = true, Liked = true, FirstUserId = 2, SecondUserId = 4
                      } }
                }
            });

            Assert.IsNotNull(response);
            Assert.AreEqual(200, ((StatusCodeResult)response).StatusCode);
        }
Exemplo n.º 2
0
        public async Task WhenBodyCalledWithPageNumberGreaterThanTheNumberOfPages__Then_ReturnLastPage()
        {
            var pageSettings = Options.Create(new PageSettings()
            {
                PageSize = 1
            });
            var controller = new MatchesController(_compositeSettings, _sessionService, pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy);

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };
            controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>()
            {
                { "page", "10" }
            });

            _sessionService.GetUserSession()
            .ReturnsForAnyArgs(MockHelpers.GetUserSession(true, true, true));

            var result = await controller.Body() as ViewResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();
            result.ViewData.Model.As <MatchesCompositeViewModel>().CurrentPage.Should().Be(1);
        }
        public void ValidResponseCreate()
        {
            MatchesController controller = new MatchesController(databaseContext);
            IActionResult     result     = controller.Create() as IActionResult;

            Assert.IsNotNull(result);
        }
Exemplo n.º 4
0
 public void TestInitialize()
 {
     this.matchesService    = TestObjectFactoryServices.GetMatchesService();
     this.matchesController = new MatchesController(this.matchesService);
     this.autoMapperConfig  = new AutoMapperConfig();
     this.autoMapperConfig.Execute(typeof(MatchesController).Assembly);
 }
Exemplo n.º 5
0
        public async Task FindMatchAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(89572992, Game.LeagueOfLegends, ChallengeState.InProgress);

            var challenge = challengeFaker.FakeChallenge();

            var participants = challenge.Participants;

            var participant = participants.First();

            var matches = participant.Matches;

            TestMock.MatchQuery.Setup(matchQuery => matchQuery.FindMatchAsync(It.IsAny <MatchId>())).ReturnsAsync(matches.First()).Verifiable();

            var controller = new MatchesController(TestMock.MatchQuery.Object, TestMapper);

            // Act
            var result = await controller.FindMatchAsync(new MatchId());

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.MatchQuery.Verify(matchQuery => matchQuery.FindMatchAsync(It.IsAny <MatchId>()), Times.Once);
        }
Exemplo n.º 6
0
        public void MustReturnNullIfJSONIsInvalid(object jtoken)
        {
            JToken            token             = Parser((String)jtoken);
            MatchesController matchesController = new MatchesController(Mocked());
            var match = matchesController.MountMatchObject(token);

            NUnit.Framework.Assert.AreEqual(null, match);
        }
Exemplo n.º 7
0
        public void SetUp()
        {
            var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile(new AutoMapperProfiles()));
            var mapper       = mapperConfig.CreateMapper();

            _matchService      = new Mock <IMatchService>();
            _matchesController = new MatchesController(mapper, _matchService.Object);
        }
        public async Task Test_UpsertMatches_Fail_BadRequest()
        {
            var controller = new MatchesController(_matchesServices.Object);
            var response   = await controller.UpsertMatches(null);

            Assert.IsNotNull(response);
            Assert.AreEqual(400, ((StatusCodeResult)response).StatusCode);
        }
Exemplo n.º 9
0
        public async Task WhenTotalResultsIsGreaterThanPageAndModuleOfResultByPagesISLessThan5_Then_CorrectTotalPagesNumberReturned()
        {
            var userSession = MockHelpers.GetUserSession(true, true, true);

            var x    = 1;
            var occs = new GetOccupationsWithMatchingSkillsResponse
            {
                MatchingOccupations = new List <GetOccupationsWithMatchingSkillsResponse.MatchedOccupation>()
            };

            while (x < 10)
            {
                occs.MatchingOccupations.Add(new GetOccupationsWithMatchingSkillsResponse.MatchedOccupation()
                {
                    JobProfileTitle = $"Mock Title{x}",
                    JobProfileUri   = "http://mockjoburl",
                    LastModified    = DateTime.UtcNow,
                    TotalOccupationEssentialSkills = 12,
                    MatchingEssentialSkills        = 6,
                    TotalOccupationOptionalSkills  = 4,
                    MatchingOptionalSkills         = 2,
                    Uri = "MatchUri",
                }
                                             );
                x++;
            }

            var handlerMock = MockHelpers.GetMockMessageHandler(JsonConvert.SerializeObject(occs));
            var restClient  = new RestClient(handlerMock.Object);

            _serviceTaxonomy = new ServiceTaxonomyRepository(restClient);


            var pageSettings = Options.Create(new PageSettings()
            {
                PageSize = 5
            });
            var controller = new MatchesController(_compositeSettings, _sessionService, pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy);

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };
            controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>()
            {
                { "page", "1" }
            });

            _sessionService.GetUserSession()
            .ReturnsForAnyArgs(userSession);

            var result = await controller.Body() as ViewResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();
            result.ViewData.Model.As <MatchesCompositeViewModel>().CurrentPage.Should().Be(1);
            result.ViewData.Model.As <MatchesCompositeViewModel>().TotalPages.Should().Be(2);
        }
 public void SetUp()
 {
     matchService  = new Mock <IEncounterService>();
     auth          = new Mock <IAuthenticationService>();
     mapper        = new Mock <EncounterDtoMapper>();
     testEncounter = BuildFakeMatch();
     controller    = new MatchesController(matchService.Object, auth.Object);
     controller.ControllerContext = GetFakeControllerContext();
 }
Exemplo n.º 11
0
        public void MustReturnNullIfTeamsAreEqual()
        {
            var matchesController = new MatchesController(Mocked());
            var match             = matchesController.ValidateMatchObject(new Matches {
                Championship = 1, Referee = 1, HomeTeam = 1, AwayTeam = 1
            });

            NUnit.Framework.Assert.AreEqual(null, match);
        }
        public async Task Test_GetMatchesByUserId_Fail_BadRequest_EmptyUserId()
        {
            var controller = new MatchesController(_matchesServices.Object);

            var response = await controller.GetMatchesByUserId(0);

            Assert.IsNotNull(response);
            Assert.AreEqual(400, ((StatusCodeResult)response).StatusCode);
        }
        public async Task Test_GetNewMatches_BadRequest_EmptyLocation()
        {
            var controller = new MatchesController(_matchesServices.Object);

            var response = await controller.GetNewMatches(1, "");

            Assert.IsNotNull(response);
            Assert.AreEqual(400, ((StatusCodeResult)response).StatusCode);
        }
        public void ValidResponseDelete()
        {
            MatchesController controller = new MatchesController(databaseContext);
            var resultTask = controller.Delete(1);

            resultTask.Wait();
            IActionResult result = resultTask.Result as IActionResult;

            Assert.IsNotNull(result);
        }
Exemplo n.º 15
0
        public void GetEditScore_WithMissingId_ReturnsError()
        {
            var mockService = new Mock <IModerationService>();

            var controller = new MatchesController(mockService.Object);

            var result     = controller.EditScore(1);
            var viewResult = result as ViewResult;

            Assert.IsTrue(Validator.ModelStateHasError(viewResult, "Match not found."));
        }
 public void Initialize()
 {
     this.service    = new Mock <ILeagueService>();
     this.controller = new MatchesController(service.Object);
     this.request    = new HttpRequestMessage();
     request.SetConfiguration(new System.Web.Http.HttpConfiguration());
     Mapper.Initialize(x =>
     {
         x.AddProfile <DomainToViewModelMappingProfile>();
     });
 }
Exemplo n.º 17
0
        public void MatchesTestInitialize()
        {
            MatchesRepository = new MatchesRepository();
            PlayersRepository = new PlayersRepository();

            Controller = new MatchesController(MatchesRepository, PlayersRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };
        }
Exemplo n.º 18
0
 public void can_get_index_happy_path()
 {
     var homeController = new MatchesController(_textMatchService);
     var textMatchInputModel = new TextMatchInputModel
     {
         SubText = "Polly",
         Text = _testText
     };
     var indexPage = homeController.Index(textMatchInputModel.Text, textMatchInputModel.SubText) as ViewResult;
     var model = (TextMatchOutputModel) indexPage.Model;
     model.Output.Should().Be("1,26,51");
 }
        private IEnumerable <PlayDay> GetKnockoutClassification(IDbConnection c, IDbTransaction t, long idStage)
        {
            var par = new { idStage = idStage };

            var days = c.Query <PlayDay>(
                $"SELECT p.* FROM playdays p WHERE p.idStage = @idStage ORDER BY idGroup, id", par);

            var matches = MatchesController.GetMatchesWithField(c, t, "idStage = @idStage", par);
            var result  = MatchesController.CreateDaysTree(days, matches);

            return(result);
        }
Exemplo n.º 20
0
        public void GetMatchesTest_Check_Result_Type()
        {
            // arrange
            var matches = new List <MatchInfo>
            {
                new MatchInfo
                {
                    Id        = 4,
                    Location  = "Jeziorany",
                    Year      = "2018",
                    ScoreInfo = new List <ScoreInfo>
                    {
                        new ScoreInfo {
                            TeamId = 1, HalfTimeScore = 2, FullTimeScore = 6
                        },
                        new ScoreInfo {
                            TeamId = 2, HalfTimeScore = 1, FullTimeScore = 2
                        }
                    }
                },
                new MatchInfo
                {
                    Id        = 5,
                    Location  = "Olsztyn",
                    Year      = "2012",
                    ScoreInfo = new List <ScoreInfo>
                    {
                        new ScoreInfo {
                            TeamId = 1, HalfTimeScore = 3, FullTimeScore = 5
                        },
                        new ScoreInfo {
                            TeamId = 2, HalfTimeScore = 2, FullTimeScore = 3
                        }
                    }
                }
            };

            var mockLogger  = new Mock <ILogger <MatchesController> >();
            var mockService = new Mock <IMatchesService>();

            mockService.Setup(x => x.GetMatches()).Returns(matches);
            var controller = new MatchesController(mockLogger.Object, mockService.Object);

            //act
            var result = controller.Get();

            //assert
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            Assert.IsInstanceOfType(result.Value, typeof(JsonMobileResult));
            Assert.IsInstanceOfType(((JsonMobileResult)result.Value).Data, typeof(List <MatchInfo>));
            Assert.IsTrue(((JsonMobileResult)result.Value).Success);
        }
Exemplo n.º 21
0
        public async void DetailsNullPageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            //Act
            var r = await c.Details(null);


            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Exemplo n.º 22
0
        public void InterestedTest()
        {
            mockProjectService.Setup(service => service.GetInterested(It.IsAny <int>())).Returns(this.users);
            var controller = new MatchesController(mockProjectService.Object);

            controller.ControllerContext = this.controllerContext;
            var result     = controller.Interested(0);
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <InterestedViewModel>(viewResult.ViewData.Model);

            mockProjectService.Reset();
        }
Exemplo n.º 23
0
        public async void EditCoachNotFoundPageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            //Act
            var r = await c.Edit(2);


            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Exemplo n.º 24
0
        public async Task PostEditScore_WithInvalidStateModel_ReturnsError()
        {
            var mockService = new Mock <IModerationService>();

            var controller = new MatchesController(mockService.Object);

            controller.ModelState.AddModelError(string.Empty, "Some Error");

            var result     = controller.EditScore(null, 1);
            var viewResult = await result as ViewResult;

            Assert.IsTrue(Validator.ModelStateHasErrors(viewResult));
        }
Exemplo n.º 25
0
        public void AcceptedTest()
        {
            mockProjectService.Setup(service => service.GetAcceptedProjects(It.IsAny <string>())).Returns(this.interests);
            var controller = new MatchesController(mockProjectService.Object);

            controller.ControllerContext = this.controllerContext;
            var result     = controller.Accepted();
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <List <InterestedInProject> >(viewResult.ViewData.Model);

            mockProjectService.Reset();
        }
Exemplo n.º 26
0
        public async void IndexTest()
        {
            //Arrange
            var dbContext        = MockDb.CreateMockDb();
            MatchesController sc = new MatchesController(dbContext);
            //Act
            var r = await sc.Index();

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <List <Matches> >(result.ViewData.Model);

            Assert.Equal(1, model.Count());
        }
Exemplo n.º 27
0
        public void GetEditScore_WithCorrectId_ReturnsModel()
        {
            var mockService = new Mock <IModerationService>();

            mockService.Setup(x => x.PrepareMatchScore(1))
            .Returns(new BetMatchBindingModel());

            var controller = new MatchesController(mockService.Object);

            var result     = controller.EditScore(1);
            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult.Model);
        }
Exemplo n.º 28
0
        public async Task FindMatchAsync_ShouldBeNotFoundObjectResult()
        {
            // Arrange
            TestMock.MatchQuery.Setup(matchQuery => matchQuery.FindMatchAsync(It.IsAny <MatchId>())).Verifiable();

            var controller = new MatchesController(TestMock.MatchQuery.Object, TestMapper);

            // Act
            var result = await controller.FindMatchAsync(new MatchId());

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();

            TestMock.MatchQuery.Verify(matchQuery => matchQuery.FindMatchAsync(It.IsAny <MatchId>()), Times.Once);
        }
Exemplo n.º 29
0
        public async Task Ok_Success()
        {
            _teamsService.Setup(x => x.GetYearTeamsAsync(It.IsAny <short>())).ReturnsAsync(MockedTeams());
            var controller = new MatchesController(_service.Object, _teamsService.Object, _mapper, _logger.Object);
            var result     = await controller.SetRoundResults(Year, Season, Round, MockedMatches().ToList());

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <IActionResult>(result);
            Assert.IsInstanceOf <OkResult>(result);

            _service.Verify(x => x.SetRoundResults(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>(), It.IsAny <IList <Seasons.BusinessEntities.Match> >()), Times.Once);
            _logger.Verify(x => x.Log(LogLevel.Debug, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once);
            _logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Never);
            _teamsService.Verify(x => x.GetYearTeamsAsync(It.IsAny <short>()), Times.Once);
        }
Exemplo n.º 30
0
        public async Task ServiceFail_Return500()
        {
            _service.Setup(x => x.GetSeasonRoundMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>())).ThrowsAsync(new DataException());
            var controller = new MatchesController(_service.Object, _teamsService.Object, _mapper, _logger.Object);
            var result     = await controller.GetSeasonRoundMatchesAsync(Year, Season, Round);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <IActionResult>(result);
            Assert.IsInstanceOf <ObjectResult>(result);
            Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ObjectResult)result).StatusCode);
            Assert.IsNotNull(((ObjectResult)result).Value);
            Assert.IsNotEmpty(((ObjectResult)result).Value.ToString());

            _service.Verify(x => x.GetSeasonRoundMatchesAsync(It.IsAny <short>(), It.IsAny <byte>(), It.IsAny <byte>()), Times.Once);
            _logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once);
        }
        private static void ApplyAllSanctions(IDbConnection c, IDbTransaction t, long idTournament, long idUser)
        {
            // Get all the matches and reapply the sanctions
            var matches = GetMatches(c, t, idTournament);

            if (matches == null || matches.Count() == 0)
            {
                return;
            }

            foreach (var match in matches)
            {
                var sanctions = GetSanctionsForMatch(c, t, match);
                MatchesController.ApplyMatchSanctions(c, t, idUser, sanctions);
            }
        }