Beispiel #1
0
        public void GetSportTest()
        {
            IActionResult  result   = controllerToTest.Get("Tennis");
            OkObjectResult okResult = result as OkObjectResult;
            SportModelOut  modelOut = okResult.Value as SportModelOut;

            sportsService.Verify(r => r.GetSport("Tennis"), Times.Once);
            Assert.IsNotNull(okResult);
            Assert.IsNotNull(okResult.Value);
            Assert.AreEqual(modelOut.Name, "Tennis");
            Assert.IsTrue(modelOut.IsTwoTeams);
            Assert.AreEqual(okResult.StatusCode, 200);
        }
Beispiel #2
0
        public async void SportsController_GetEventsBySportAndDate_JsonResult()
        {
            var expected = new List <SportEvent>
            {
                new SportEvent()
                {
                    EventId    = 1,
                    SportId    = 2,
                    EventName  = "Fake Event",
                    EventDate  = new DateTime(1870, 4, 22),
                    Team1Price = 1.23M,
                    Team2Price = 4.56M,
                    DrawPrice  = 7.89M
                },
                new SportEvent()
                {
                    EventId    = 2,
                    SportId    = 3,
                    EventName  = "FFake EEvent",
                    EventDate  = new DateTime(1879, 11, 7),
                    Team1Price = 3.21M,
                    Team2Price = 6.54M,
                    DrawPrice  = 9.87M
                },
            };

            var logMock        = new Mock <ILogger <SportsController> >();
            var eventsRepoMock = new Mock <IEventsRepository>();
            var sportsRepoMock = new Mock <ISportsRepository>();

            eventsRepoMock.Setup(
                r => r.GetEventsBySportAndDate(It.IsAny <int>(), It.IsAny <DateTime>()))
            .ReturnsAsync(expected);

            var spControl = new SportsController(logMock.Object, eventsRepoMock.Object, sportsRepoMock.Object);
            var result    = await spControl.Get(1, DateTime.Now);

            Assert.NotNull(result);
            Assert.True(result.Result == null);
            Assert.IsType <ActionResult <IEnumerable <SportEvent> > >(result);
            Assert.IsType <List <SportEvent> >(result.Value);
            Assert.NotNull(result.Value);

            var actual = result.Value;
            var pairs  = expected.Zip(actual, (exp, act) => new { Expected = exp, Actual = act });

            foreach (var p in pairs)
            {
                Assert.Equal(p.Expected, p.Actual);
            }
        }
Beispiel #3
0
        public async void SportsController_GetAll_NotFound_WithNoDatabaseConnection()
        {
            var logMock    = new Mock <ILogger <SportsController> >();
            var eventsRepo = new EventsRepository("");
            var sportsRepo = new SportsRepository("");

            var spControl = new SportsController(logMock.Object, eventsRepo, sportsRepo);
            var result    = await spControl.Get();

            Assert.NotNull(result);

            Assert.IsType <ActionResult <IEnumerable <SportInfo> > >(result);
            Assert.NotNull(result.Result);
            Assert.IsType <NotFoundResult>(result.Result);
            Assert.True(result.Value == null);
            Assert.True((result.Result as NotFoundResult).StatusCode == 404);
        }
Beispiel #4
0
        public void GetSportTest()

        {
            var sportModel = new Sport("Basketball");

            sportModel.SportId = 1;
            var mock = new Mock <ISportService>(MockBehavior.Strict);

            mock.Setup(m => m.GetSportById(sportModel.SportId)).Returns(sportModel);
            var controller    = new SportsController(mock.Object);
            var result        = controller.Get(sportModel.SportId);
            var createdResult = result as OkObjectResult;
            var model         = createdResult.Value as SportModelOut;

            mock.VerifyAll();
            //   Assert.AreEqual(sportModel.Name, model.Name);
            Assert.AreEqual(sportModel.SportId, model.SportId);
        }
Beispiel #5
0
        public void TestGetSportsShouldReturnOKReturnSports()

        {
            var mock = new Mock <ISportService>(MockBehavior.Strict);

            mock.Setup(m => m.GetAllSports()).Returns(new List <Sport> {
                new Sport("Basketball"), new Sport("Tennis")
            });
            var sut      = new SportsController(mock.Object);
            var response = sut.Get();

            mock.Verify(m => m.GetAllSports(), Times.Once);
            var result = response as OkObjectResult;
            var model  = result.Value as IEnumerable <SportModelOut>;

            Assert.AreEqual(200, result.StatusCode);
            Assert.AreEqual(2, model.Count());
        }
Beispiel #6
0
        public async void SportsController_GetSportsWithEventsCount_JsonResult()
        {
            var expected = new List <SportInfo>
            {
                new SportInfo()
                {
                    SportId = 1, Name = "First", EventsCount = 12
                },
                new SportInfo()
                {
                    SportId = 2, Name = "Second", EventsCount = 23
                },
                new SportInfo()
                {
                    SportId = 3, Name = "Third", EventsCount = 34
                },
            };

            var logMock        = new Mock <ILogger <SportsController> >();
            var eventsRepoMock = new Mock <IEventsRepository>();
            var sportsRepoMock = new Mock <ISportsRepository>();

            sportsRepoMock.Setup(
                r => r.GetSportsWithEventsCount())
            .ReturnsAsync(expected);

            var spControl = new SportsController(logMock.Object, eventsRepoMock.Object, sportsRepoMock.Object);
            var result    = await spControl.Get();

            Assert.NotNull(result);
            Assert.True(result.Result == null);
            Assert.IsType <ActionResult <IEnumerable <SportInfo> > >(result);
            Assert.IsType <List <SportInfo> >(result.Value);
            Assert.NotNull(result.Value);

            var actual = result.Value;
            var pairs  = expected.Zip(actual, (exp, act) => new { Expected = exp, Actual = act });

            foreach (var p in pairs)
            {
                Assert.Equal(p.Expected, p.Actual);
            }
        }
Beispiel #7
0
        public void GetSportsEmptyTest()
        {
            var mockDB           = new Mock <IUnitOfWork>();
            var mocksportservice = new Mock <ISportService>();
            var controller       = new SportsController(mocksportservice.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = UserAdmin()
                }
            };
            var obtainedResult = controller.Get() as OkObjectResult;

            mocksportservice.VerifyAll();
            Assert.IsNotNull(obtainedResult);
            Assert.AreEqual(200, obtainedResult.StatusCode);
        }