Пример #1
0
        public void GetAllPlanets_ShouldReturnAllPlanets()
        {
            var testPlanets = GetTestPlanets();
            var controller  = new PlanetsController();

            var result = controller.GetPlanets() as List <Planet>;

            Assert.AreEqual(testPlanets.Count, result.Count);
        }
Пример #2
0
        public void Get_GetAll_SetupedResult()
        {
            IHttpActionResult actionResult = _planetsController.GetPlanets();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Planet> >;

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            contentResult.Content.Select(p => new Planet {
                Name = p.Name, Distance = p.Distance, PlanetId = Guid.Empty
            }).Should().BeEquivalentTo(_planets);
        }
        public void Then_All_Planets_Are_Returned()
        {
            //Arrange

            const string testplanetA = "TestPlanetA";
            const string testplanetB = "TestPlanetB";

            const int testplanetDistanceA = 5;
            const int testplanetDistanceB = 15;

            IEnumerable <Planet> testPlanets = new[]
            {
                new Planet
                {
                    Name          = testplanetA,
                    DistanceToSun = testplanetDistanceA
                },
                new Planet
                {
                    Name          = testplanetB,
                    DistanceToSun = testplanetDistanceB
                }
            };

            const int expectedPlanetCount = 2;

            var mockPlanetRepo = new Mock <IPlanetRepository>();

            mockPlanetRepo.Setup(x => x.GetAllPlanets()).Returns(testPlanets);

            var controller = new PlanetsController(mockPlanetRepo.Object);

            // Act
            var result  = controller.GetPlanets();
            var planets = result as IList <Planet> ?? result.ToList();

            // Assert
            Assert.IsNotNull(planets, "GetPlanets should not return Null");

            Assert.AreEqual(expectedPlanetCount, planets.Count, String.Format("GetPlanets should have returned {0} planets", expectedPlanetCount));
            Assert.AreEqual(planets[0].Name, testplanetA, String.Format("GetPlanets should return {0} as the first planet's name", testplanetA));
            Assert.AreEqual(planets[0].DistanceToSun, testplanetDistanceA, String.Format("GetPlanets should return {0} as the first planet's distance to the sun", testplanetA));
            Assert.AreEqual(planets[1].Name, testplanetB, String.Format("GetPlanets should return {0} as the second planet's name", testplanetB));
            Assert.AreEqual(planets[1].DistanceToSun, testplanetDistanceB, String.Format("GetPlanets should return {0} as the second planet's distance to the sun", testplanetB));
        }