public void GetAllTest() { using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync("api/language"); var list = ((StreamContent)(response.Result.Content)).ReadAsAsync<List<Language>>().Result; Assert.AreEqual(list.Count(), _languageList.Count()); Language[] array = list.ToArray(); var index = 0; foreach (var artist in _languageList) { var saved = (Language)array.GetValue(index); Assert.IsNotNull(saved.Id); Assert.AreNotEqual(new string('0', 24), saved.Id); Assert.AreEqual(saved.FlagImage, artist.FlagImage); Assert.AreEqual(saved.Locale, artist.Locale); Assert.AreEqual(saved.EnName, artist.EnName); Assert.AreEqual(saved.Abbreviation, artist.Abbreviation); Assert.AreEqual(saved.Name, artist.Name); index++; } } }
public void PostNewLanguageTest() { using (var client = HttpSelfHost.GetServer().CreateClient()) { var newLang = new Language() { Id = ObjectId.GenerateNewId().ToString(), Background = "bkg", Abbreviation = "abbr1", EnName = "enName1", FlagImage = "flagImage1", Locale = "locale1", Name = "name1", Icon = "icon" }; var requestMessage = HttpSelfHost.CreateHttpRequestMessage<Language>(newLang); var x = client.PutAsync("api/language", requestMessage).Result; var response = client.GetAsync("api/language"); var list = ((StreamContent)(response.Result.Content)).ReadAsAsync<List<Language>>().Result; var actual = list.First(l => l.Locale == newLang.Locale); Assert.AreEqual(actual.Abbreviation, newLang.Abbreviation); Assert.AreEqual(actual.EnName, newLang.EnName); Assert.AreEqual(actual.FlagImage, newLang.FlagImage); Assert.AreEqual(actual.Locale, newLang.Locale); Assert.AreEqual(actual.Name, newLang.Name); } }
public void GetByArtistIdTest_FindExisting() { int targetId = 1; List <Artwork> targetArtists = _artworkList.FindAll(a => a.ArtworkId == targetId); using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync(string.Format("api/artworks/artworkId/{0}", targetId)); var artworks = ((StreamContent)(response.Result.Content)).ReadAsAsync <List <Artwork> >().Result; Artwork[] array = artworks.ToArray(); var index = 0; foreach (var artist in targetArtists) { var saved = (Artwork)array.GetValue(index); Assert.IsNotNull(saved.Id); Assert.AreNotEqual(new string('0', 24), saved.Id); Assert.AreEqual(saved.Name, artist.Name); Assert.AreEqual(saved.ArtistId, artist.ArtistId); Assert.AreEqual(saved.IsSold, artist.IsSold); index++; } } }
public void GetAllTest() { using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync("api/artworks"); var list = ((StreamContent)(response.Result.Content)).ReadAsAsync <List <Artwork> >().Result; Assert.AreEqual(list.Count(), _artworkList.Count()); Artwork[] array = list.ToArray(); var index = 0; foreach (var artwork in _artworkList) { var saved = (Artwork)array.GetValue(index); Assert.IsNotNull(saved.Id); Assert.AreNotEqual(new string('0', 24), saved.Id); Assert.AreEqual(saved.Name, artwork.Name); Assert.AreEqual(saved.ArtistId, artwork.ArtistId); Assert.AreEqual(saved.IsSold, artwork.IsSold); index++; } } }
public void GetByIdTest_BadRequest() { int targetId = 201; using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync(string.Format("api/artworks/id/{0}", targetId)); Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.BadRequest); } }
public void GetByIdTest_EmptyList() { int targetId = 115; using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync(string.Format("api/artworks/artworkId/{0}", targetId)); var artworks = ((StreamContent)(response.Result.Content)).ReadAsAsync <List <Artwork> >().Result; Assert.AreEqual(artworks.Count, 0); } }
public void GetByIdTest_FindExisting() { var savedArtwork = _artworkRepo.First(); string targetId = savedArtwork.Id; using (var client = HttpSelfHost.GetServer().CreateClient()) { var response = client.GetAsync(string.Format("api/artworks/id/{0}", targetId)); var artwork = ((StreamContent)(response.Result.Content)).ReadAsAsync <Artwork>().Result; Assert.AreEqual(savedArtwork.Name, artwork.Name); Assert.AreEqual(savedArtwork.ArtistId, artwork.ArtistId); Assert.AreEqual(savedArtwork.IsSold, artwork.IsSold); Assert.AreEqual(savedArtwork.Id, artwork.Id); } }