Exemple #1
0
        public async Task <ActionResult <Driver> > CreateDriver(Driver driver)
        {
            try
            {
                bool driverInStarWars = await StarWarsApi.GetDriverName(driver.Name);

                if (driverInStarWars)
                {
                    _repo.Add(driver);
                    if (await _repo.Save())
                    {
                        return(Created("/api/v1.0/drivers/" + driver.DriverId, new Driver {
                            DriverId = driver.DriverId, Name = driver.Name
                        }));
                    }
                    return(BadRequest());
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database failure {e.Message}"));
            }
        }
Exemple #2
0
        public void FetchTravelerShipURI_FromRecievedJObject_FetchCorrectShipURI()
        {
            List <string> expectedURIs = new List <string>()
            {
                "https://swapi.co/api/starships/12/", "https://swapi.co/api/starships/22/"
            };

            JObject testObject = JObject.Parse(@"{
            'count': 1, 
            'next': null, 
            'previous': null, 
            'results': [
                {
                    'name': 'Luke Skywalker',                 
                    'starships': [
                        'https://swapi.co/api/starships/12/',
                        'https://swapi.co/api/starships/22/'
                        ]
                    }
                ]
            }");

            StarWarsApi   api        = new StarWarsApi();
            List <string> actualURIs = api.FetchTravelerShipURI(testObject);

            Assert.Equal(expectedURIs, actualURIs);
        }
 public async Task<IActionResult> FilmView(int filmId) {
     StarWarsApi<Film> apiResult = new StarWarsApi<Film>();
     FilmViewModel model = new FilmViewModel() {
         Film = await apiResult.RetrieveItem("films", filmId)
     };
     return View(model);
 }
Exemple #4
0
        public void CreateApifields()
        {
            StarWarsApi api    = new StarWarsApi();
            string      path   = api.Path;
            RestClient  client = api.Client;

            Assert.NotNull(api);
        }
        public void GetTravelerDataAsunc_SearchByName_ExpectJObjectReturned(string name)
        {
            StarWarsApi api = new StarWarsApi();

            JObject jObjectReturned = api.GetTravelerDataAsync(name.ToLower()).Result;

            Assert.IsType <JObject>(jObjectReturned);
        }
 public async Task<JsonResult> FilmsData() {
     StarWarsApi<Film> apiResult = new StarWarsApi<Film>();
     return Json(await apiResult.RetrieveItemList("films"),
         new Newtonsoft.Json.JsonSerializerSettings() {
             ContractResolver = new DefaultContractResolver()
         }
     );
 }
        public void ValidateTraveler_IncorrectInput_ExpectFalse(string name)
        {
            StarWarsApi api     = new StarWarsApi();
            JObject     jObject = api.GetTravelerDataAsync(name.ToLower()).Result;

            bool isTraveler = api.ValidateTraveler(jObject, name.ToLower());

            Assert.False(isTraveler);
        }
Exemple #8
0
        public void FetchTravelerShipURI_FromRecievedJObject_FetchCorrectShipURI()
        {
            string        name         = "Luke SKYWalKeR";
            List <string> expectedURIs = new List <string>()
            {
                "https://swapi.co/api/starships/12/", "https://swapi.co/api/starships/22/"
            };

            StarWarsApi   api        = new StarWarsApi();
            JObject       jObject    = api.GetTravelerDataAsync(name.ToLower()).Result;
            List <string> actualURIs = api.FetchTravelerShipURI(jObject);

            Assert.Equal(expectedURIs, actualURIs);
        }
Exemple #9
0
        public void GetShipDataAsync_InsertListOfURI_ReturnShipValues()
        {
            string name = "Luke SKYWalKeR";

            Dictionary <string, double> ExpectedShipData = new Dictionary <string, double>();

            ExpectedShipData.Add("X-wing", 12.5);
            ExpectedShipData.Add("Imperial shuttle", 20);

            StarWarsApi   api      = new StarWarsApi();
            JObject       jObject  = api.GetTravelerDataAsync(name.ToLower()).Result;
            List <string> shipURIs = api.FetchTravelerShipURI(jObject);

            Dictionary <string, double> actualShipData = api.GetShipDataAsync(shipURIs).Result;

            Assert.Equal(ExpectedShipData, actualShipData);
        }
Exemple #10
0
        public ExplorerViewModel()
        {
            _api = new StarWarsApi();
            var whenPropertyChanges = Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                handler => handler.Invoke,
                h => PropertyChanged += h,
                h => PropertyChanged += h);

            whenPropertyChanges
            .Where(p => p.EventArgs.PropertyName == nameof(SelectedChoice))
            .Subscribe(p => _api.SearchRequest(SelectedChoice, SearchText));
            whenPropertyChanges
            .Where(p => p.EventArgs.PropertyName == nameof(SearchText))
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Subscribe(p => _api.SearchRequest(SelectedChoice, SearchText));

            _api.StatusStream.Subscribe(UpdateStatus);

            ResourceChoices = _api.Resources;
            SelectedChoice  = ResourceChoices.First();
            LoadMoreCommand = new RelayCommand(() => _api.LoadMoreData(), () => true);
        }
Exemple #11
0
        public void TestPath()
        {
            StarWarsApi api = new StarWarsApi();

            Assert.Equal("https://swapi.co/api/", api.Path);
        }
Exemple #12
0
        public void createApiClass()
        {
            StarWarsApi api = new StarWarsApi();

            Assert.NotNull(api);
        }
Exemple #13
0
 public ParseController(ConfigHelper configHelper)
 {
     _api = new StarWarsApi(configHelper);
 }
Exemple #14
0
 public ClienteServico(StarWarsApi api, IMapper mapper)
 {
     _api    = api;
     _mapper = mapper;
 }
 public async Task<IActionResult> FilmListing(int filmId) {
     StarWarsApi<Film> apiResult = new StarWarsApi<Film>();
     var model = await apiResult.RetrieveItemList("films");
     return View(model);
 }