public void PutAdd()
        {
            //Arrange.
            Exception internalEx = new EncounterNotFoundException();
            Exception toThrow    = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND);

            matchService.Setup(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                        It.IsAny <DateTime>(), It.IsAny <string>())).Throws(toThrow);
            matchService.Setup(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                     It.IsAny <string>(), It.IsAny <DateTime>())).Returns(testEncounter);

            MatchModelIn input = BuildMatchModelIn(testEncounter);

            //Act.
            IActionResult        result        = controller.Put(1, input);
            CreatedAtRouteResult createdResult = result as CreatedAtRouteResult;
            EncounterModelOut    modified      = createdResult.Value as EncounterModelOut;

            //Assert.
            matchService.Verify(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                         It.IsAny <DateTime>(), It.IsAny <string>()), Times.Once);

            matchService.Verify(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                      It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);

            Assert.IsNotNull(result);
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual("GetMatchById", createdResult.RouteName);
            Assert.IsNotNull(modified);
            Assert.AreEqual(modified.Id, testEncounter.id);
        }
Exemplo n.º 2
0
        private IActionResult TryPut(int id, MatchModelIn aMatch)
        {
            IActionResult result;

            try
            {
                SetSession();
                EncounterDto modified = encounterService.ModifyEncounter(id, aMatch.TeamIds, aMatch.Date, aMatch.SportName);
                modified.id = id;
                EncounterModelOut output = factory.CreateModelOut(modified);
                result = Ok(output);
            }
            catch (ServiceException e)
            {
                if (e.Error.Equals(ErrorType.ENTITY_NOT_FOUND))
                {
                    result = TryPostMatch(id, aMatch.TeamIds, aMatch.SportName, aMatch.Date);
                }
                else
                {
                    result = errors.GenerateError(e);
                }
            }
            return(result);
        }
        public void PutModifyMatchTest()
        {
            //Arrange.
            MatchModelIn input = BuildMatchModelIn(testEncounter);

            matchService.Setup(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                        It.IsAny <DateTime>(), It.IsAny <string>())).Returns(testEncounter);

            //Act.
            IActionResult     result   = controller.Put(1, input);
            OkObjectResult    okResult = result as OkObjectResult;
            EncounterModelOut modified = okResult.Value as EncounterModelOut;

            //Assert.
            matchService.Verify(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                         It.IsAny <DateTime>(), It.IsAny <string>()), Times.Once);

            matchService.Verify(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                      It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never);
            Assert.IsNotNull(result);
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsNotNull(modified);
            Assert.AreEqual(modified.Id, testEncounter.id);
        }
Exemplo n.º 4
0
        public void CompetitionModelOutTest()
        {
            EncounterModelOut   modelOut    = factory.CreateModelOut(testCompetition);
            CompetitionModelOut competition = modelOut as CompetitionModelOut;

            Assert.IsNotNull(competition);
            Assert.AreEqual(competition.Team_Position.Count, 3);
        }
Exemplo n.º 5
0
        private IActionResult TryGetMatch(int matchId)
        {
            EncounterDto      stored   = encounterService.GetEncounter(matchId);
            EncounterModelOut modelOut = factory.CreateModelOut(stored);
            IActionResult     result   = Ok(modelOut);

            return(result);
        }
Exemplo n.º 6
0
        public void MatchModelOutTest()
        {
            EncounterModelOut modelOut = factory.CreateModelOut(testMatch);
            MatchModelOut     match    = modelOut as MatchModelOut;

            Assert.IsNotNull(match);
            Assert.IsTrue(match.HasResult);
            Assert.IsTrue(match.HasWinner);
            Assert.AreEqual(match.WinnerId, match.TeamIds.ToList()[0]);
        }
Exemplo n.º 7
0
        private IActionResult TrySetResult(int matchId, ResultModel resultModel)
        {
            ICollection <Tuple <int, int> > team_positions = resultModel.Team_Position
                                                             .Select(tp => new Tuple <int, int>(tp.TeamId, tp.Position)).ToList();
            ResultDto encounterResult = new ResultDto()
            {
                teams_positions = team_positions
            };

            encounterService.SetResult(matchId, encounterResult);
            EncounterDto      matchWithResult = encounterService.GetEncounter(matchId);
            EncounterModelOut result          = factory.CreateModelOut(matchWithResult);

            return(Ok(result));
        }
        public void GetMatchTest()
        {
            //Arrange.
            matchService.Setup(ms => ms.GetEncounter(It.IsAny <int>())).Returns(testEncounter);

            //Act.
            IActionResult     result      = controller.Get(1);
            OkObjectResult    foundResult = result as OkObjectResult;
            EncounterModelOut match       = foundResult.Value as EncounterModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(foundResult);
            Assert.AreEqual(200, foundResult.StatusCode);
            Assert.IsNotNull(match);
            Assert.AreEqual(1, match.Id);
            Assert.IsFalse(match.CommentsIds.Any());
        }
Exemplo n.º 9
0
        private IActionResult TryPostMatch(int id, ICollection <int> teamIds, string sportName, DateTime date)
        {
            IActionResult result;

            try
            {
                SetSession();
                EncounterDto      added  = encounterService.AddEncounter(id, teamIds, sportName, date);
                EncounterModelOut output = factory.CreateModelOut(added);
                result = CreatedAtRoute("GetMatchById", new { matchId = added.id }, output);
            }
            catch (ServiceException e)
            {
                result = errors.GenerateError(e);
            }

            return(result);
        }
        public void SetResultTest()
        {
            //Arrange.
            matchService.Setup(ms => ms.SetResult(It.IsAny <int>(), It.IsAny <ResultDto>()));
            matchService.Setup(ms => ms.GetEncounter(It.IsAny <int>())).Returns(testEncounter);
            ResultModel resultModel = GetFakeResult();

            //Act.
            IActionResult     result          = controller.SetResult(1, resultModel);
            OkObjectResult    okResult        = result as OkObjectResult;
            EncounterModelOut matchWithResult = okResult.Value as EncounterModelOut;

            //Assert.
            matchService.VerifyAll();
            Assert.IsNotNull(result);
            Assert.IsNotNull(okResult);
            Assert.IsNotNull(matchWithResult);
            Assert.AreEqual(matchWithResult.Id, testEncounter.id);
        }
        public void CreateValidMatchTest()
        {
            matchService.Setup(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                     It.IsAny <string>(), It.IsAny <DateTime>())).Returns(testEncounter);
            MatchModelIn input = BuildMatchModelIn(testEncounter);

            IActionResult        result        = controller.Post(input);
            CreatedAtRouteResult createdResult = result as CreatedAtRouteResult;
            EncounterModelOut    created       = createdResult.Value as EncounterModelOut;

            matchService.Verify(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(),
                                                      It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);
            Assert.IsNotNull(result);
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual("GetMatchById", createdResult.RouteName);
            Assert.IsNotNull(created);
            Assert.AreEqual(testEncounter.date, testEncounter.date);
        }