public async Task GetSpaceShouldSerializeIntoCorrectObject() { //Arrange _handler.Response = GetResponseFromFile(@"SampleSpace.json"); //Act var res = await _client.GetSpace(); //Assert Assert.Equal("Products", res.Name); Assert.Equal("n9r7gd2bwvqt", res.SystemProperties.Id); Assert.Equal("Space", res.SystemProperties.Type); Assert.Collection(res.Locales, (l) => { Assert.Equal("en-US", l.Code); Assert.True(l.Default); Assert.Equal("U.S. English", l.Name); Assert.Null(l.FallbackCode); }, (l) => { Assert.Equal("sv", l.Code); Assert.False(l.Default); Assert.Equal("Swedish", l.Name); Assert.Equal("en-US", l.FallbackCode); }); }
private IEnumerable <ValidationResult> MakeTestCalls(HttpClient httpClient, IContentfulClient contentfulClient, IViewLocalizer localizer) { ValidationResult validationResult = null; try { var space = contentfulClient.GetSpace().Result; } catch (AggregateException ae) { ae.Handle((ce) => { if (ce is ContentfulException) { if ((ce as ContentfulException).StatusCode == 401) { validationResult = new ValidationResult(localizer["deliveryKeyInvalidLabel"].Value, new[] { nameof(AccessToken) }); } else if ((ce as ContentfulException).StatusCode == 404) { validationResult = new ValidationResult(localizer["spaceOrTokenInvalid"].Value, new[] { nameof(SpaceId) }); } else { validationResult = new ValidationResult($"{localizer["somethingWentWrongLabel"].Value}: {ce.Message}", new[] { nameof(AccessToken) }); } return(true); } return(false); }); } if (validationResult != null) { yield return(validationResult); } contentfulClient = new ContentfulClient(httpClient, AccessToken, PreviewToken, SpaceId, true); try { var space = contentfulClient.GetSpace().Result; } catch (AggregateException ae) { ae.Handle((ce) => { if (ce is ContentfulException) { if ((ce as ContentfulException).StatusCode == 401) { validationResult = new ValidationResult(localizer["previewKeyInvalidLabel"].Value, new[] { nameof(PreviewToken) }); } else if ((ce as ContentfulException).StatusCode == 404) { validationResult = new ValidationResult(localizer["spaceOrTokenInvalid"].Value, new[] { nameof(SpaceId) }); } else { validationResult = new ValidationResult($"{localizer["somethingWentWrongLabel"].Value}: {ce.Message}", new[] { nameof(PreviewToken) }); } return(true); } return(false); }); } if (validationResult != null) { yield return(validationResult); } }