예제 #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);
        }
        public void Get_ReturnsMatches()
        {
            Mock <IMatchDal> mockDal = new Mock <IMatchDal>();

            mockDal.Setup(m => m.GetAll()).Returns(RugbyMatchMocks.GetData());
            MatchController controller = new MatchController(mockDal.Object);

            List <RugbyMatch> result = controller.Get();

            Assert.AreEqual(3, result.Count);
        }
        public async Task Execute_ExistingData_DoesNotCacheData()
        {
            List <RugbyMatch> matches  = RugbyMatchMocks.GetData();
            Mock <IMatchDal>  matchDal = new Mock <IMatchDal>();

            matchDal.Setup(m => m.GetAll()).Returns(matches);

            Mock <IMatchService> matchService = new Mock <IMatchService>();

            IWarmupService warmupService = new WarmupService(matchDal.Object, matchService.Object);

            await warmupService.Execute();

            matchService.Verify(m => m.GetByTeamId(It.IsAny <int>()), Times.Never);
            matchDal.Verify(m => m.Add(matches), Times.Never);
        }
        public async Task Execute_NoData_CachesData()
        {
            List <RugbyMatch>    matches      = RugbyMatchMocks.GetData();
            Mock <IMatchService> matchService = new Mock <IMatchService>();

            matchService.Setup(m => m.GetByTeamId(It.IsAny <int>())).ReturnsAsync(matches);

            Mock <IMatchDal> matchDal = new Mock <IMatchDal>();

            matchDal.Setup(m => m.GetAll()).Returns(new List <RugbyMatch>());

            IWarmupService warmupService = new WarmupService(matchDal.Object, matchService.Object);

            await warmupService.Execute();

            matchDal.Verify(m => m.Add(matches));
        }
        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);
        }