private static void PropertyIsEmptyInternal(string responseProperty, bool requiresEmpty) { ListShowsContext context = GetContext(); var propertyInfo = typeof(ShowsPage).GetProperty(responseProperty); if (propertyInfo == null) { Assert.Fail($"There is no such property: {responseProperty}"); } var propertyValue = propertyInfo.GetValue(context.ResponsePage); if (propertyValue == null) { Assert.AreEqual(true, requiresEmpty); return; } switch (propertyValue) { case string str: Assert.AreEqual(string.IsNullOrEmpty(str), requiresEmpty); break; case IEnumerable enumerable: Assert.AreEqual(!enumerable.Cast <object>().Any(), requiresEmpty); break; default: Assert.Fail($"{propertyValue.GetType().Name} is not supported as property type for checking"); break; } }
public async Task WhenRequestSendToServer() { ListShowsContext context = GetContext(); using (var client = new HttpClient()) { string listShowsBaseUri = ConfigurationManager.AppSettings["listShowsBaseUri"]; string queryString = string.Join("&", context.QueryParameters.Select(par => $"{par.Key}={par.Value}")); string listShowsUri; if (string.IsNullOrEmpty(queryString)) { listShowsUri = listShowsBaseUri; } else { listShowsUri = $"{listShowsBaseUri}?{queryString}"; } context.ServerResponseMessage = await client.GetAsync(listShowsUri); string responseJson = await context.ServerResponseMessage.Content.ReadAsStringAsync(); context.ResponsePage = JsonConvert.DeserializeObject <ShowsPage>(responseJson); } ScenarioContext.Current[nameof(ListShowsContext)] = context; }
public void GivenPageNumberIsSetTo(string queryParameterName, string queryParameterValue) { ListShowsContext context = GetContext(); context.QueryParameters[queryParameterName] = queryParameterValue; ScenarioContext.Current[nameof(ListShowsContext)] = context; }
public void ThenResponseContainsStatusCode(int code) { ListShowsContext context = GetContext(); if (context.ServerResponseMessage == null) { Assert.Fail("Context is null"); } Assert.AreEqual(code, (int)context.ServerResponseMessage.StatusCode); }