Example #1
0
        public async Task Launchpads_Get_All()
        {
            // arrange
            var controller = new LaunchesController(new LaunchDataService(new GetLaunchData()));

            // act
            var result = await controller.GetLaunches();

            // assert
            var okResult = result.Should().BeOfType <OkObjectResult>().Subject;
            var launches = okResult.Value.Should().BeAssignableTo <IEnumerable <Launchpad> >().Subject;
        }
Example #2
0
        public async Task Launchpads_Get_All_From_Mock()
        {
            // arrange
            var mockService = new Mock <ILaunchDataService>();

            // generate random number to arbitrarily compare response to mock data
            Random rnd = new Random();
            int    idx = rnd.Next(0, 3);

            List <Launchpad> launches = new List <Launchpad>
            {
                new Launchpad
                {
                    Id     = "xxx-yyyy-zzz",
                    Name   = "First Launch",
                    Status = "active"
                },
                new Launchpad
                {
                    Id     = "aaa-bbbb-ccc",
                    Name   = "Second Launch",
                    Status = "retired"
                },
                new Launchpad
                {
                    Id     = "qqq-rrrr-sss",
                    Name   = "Third Launch",
                    Status = "under construction"
                }
            };

            mockService.Setup(s => s.GetLaunchData())
            .Returns(() => Task.FromResult(launches));

            var controller = new LaunchesController(mockService.Object);

            // act
            var result = await controller.GetLaunches();

            // assert
            var okResult = result.Should().BeOfType <OkObjectResult>().Subject;
            var actual   = okResult.Value.Should().BeAssignableTo <List <Launchpad> >().Subject;

            actual.Count.Should().Be(3);
            actual[idx].Id.Should().Be(launches[idx].Id);
        }