Ejemplo n.º 1
0
        public async Task GetByTeamId_Success()
        {
            List <RugbyMatch> matchResponse     = RugbyMatchMocks.GetData();
            string            matchResponseJson = JsonSerializer.Serialize(matchResponse);

            HttpResponseMessage response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(matchResponseJson)
            };

            IHttpClientFactory            mockFactory        = BuildMockHttpClient(response);
            IOptions <ExternalApiOptions> externalApiOptions = CreateMockConfiguration();
            IMatchService matchService = new MatchService(externalApiOptions, mockFactory);

            List <RugbyMatch> result = await matchService.GetByTeamId(103969);

            Assert.AreEqual(3, result.Count);

            RugbyMatch firstMatch = result.First(m => m.matchId == 1);

            Assert.AreEqual("W", firstMatch.result);
            Assert.AreEqual("Old Trafford", firstMatch.stadiumName);

            RugbyMatch secondMatch = result.First(m => m.matchId == 2);

            Assert.AreEqual("W", secondMatch.result);
            Assert.AreEqual("Signal Iduna Park", secondMatch.stadiumName);

            RugbyMatch thirdMatch = result.First(m => m.matchId == 3);

            Assert.AreEqual("L", thirdMatch.result);
            Assert.AreEqual("Bernabeu", thirdMatch.stadiumName);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a match by a specific ID
        /// </summary>
        /// <param name="matchId">The match ID</param>
        /// <returns></returns>
        public RugbyMatch GetById(int matchId)
        {
            using (MatchContext context = new MatchContext())
            {
                RugbyMatch result = context.Matches
                                    .FirstOrDefault(m => m.matchId == matchId);

                return(result);
            }
        }
Ejemplo n.º 3
0
        public IActionResult GetById(int matchId)
        {
            RugbyMatch result = _matchDal.GetById(matchId);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
        public void GetById_ReturnsMatch()
        {
            RugbyMatch       toReturn = RugbyMatchMocks.GetData().First();
            Mock <IMatchDal> mockDal  = new Mock <IMatchDal>();

            mockDal.Setup(m => m.GetById(It.IsAny <int>())).Returns(toReturn);

            MatchController controller = new MatchController(mockDal.Object);

            OkObjectResult actionResult = controller.GetById(1) as OkObjectResult;

            Assert.AreEqual(200, actionResult.StatusCode);

            RugbyMatch rugbyMatchResult = actionResult.Value as RugbyMatch;

            Assert.AreEqual(toReturn, rugbyMatchResult);
        }