Beispiel #1
0
        public async System.Threading.Tasks.Task GetSportsTestAsync()
        {
            var manager = new Mock <ISportManager>();

            manager.Setup(m => m.GetAll())
            .ReturnsAsync(new List <Sport>()
            {
                new Sport()
                {
                    Id = 11
                }
            });

            var controller   = new SportsController(manager.Object);
            var actionResult = await controller.GetSports();

            actionResult.Should().NotBeNull();
            actionResult.Should().BeOfType <ActionResult <IEnumerable <Sport> > >();

            // Checks the 200 response
            actionResult.Result.Should().BeOfType <OkObjectResult>();
            var result = actionResult.Result as OkObjectResult;

            //Checks the content of the response
            var responseValue = result.Value as IEnumerable <Sport>;

            responseValue.Count().Should().Be(1);
            responseValue.ElementAt(0).Id.Should().Be(11);
        }
Beispiel #2
0
        public void getSports()
        {
            List <Sport> testObjects = new List <Sport>();

            testObjects.Add(new Sport {
                sportId = 1, name = "test1"
            });
            testObjects.Add(new Sport {
                sportId = 2, name = "test2"
            });

            Mock <ISportRepository> myMock = new Mock <ISportRepository>();

            myMock.Setup(x => x.GetAll())
            .Returns(testObjects.AsQueryable);

            SportsController sportsController = new SportsController(myMock.Object);

            IQueryable <Sport> returnedTask = sportsController.GetSports();

            var contentResult = returnedTask.ToList();

            Assert.IsNotNull(contentResult);

            Assert.AreEqual(contentResult.Count, 2);
            Assert.AreEqual(contentResult[0].sportId, 1);
            Assert.AreEqual(contentResult[1].sportId, 2);

            myMock.VerifyAll();
        }
        public void Get_Zero_Items()
        {
            TestHelpers.SetupDbSet(this.mockSet, new List <sport>());

            SportsController controller = new SportsController(this.mockContext.Object);

            IQueryable <sport> result = controller.GetSports();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
        }
        public void Get_Should_Return_Items()
        {
            TestHelpers.SetupDbSet(this.mockSet, this.data);

            SportsController controller = new SportsController(this.mockContext.Object);

            IQueryable <sport> result = controller.GetSports();

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Count());
        }