public async Task TestInt16AsKey() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi, DbContext>(HttpMethod.Get, resource : "/Customers(1)", serviceCollection : di); response.IsSuccessStatusCode.Should().BeTrue(); TestContext.WriteLine(await response.Content.ReadAsStringAsync()); }
public async Task ShouldReturn403HandlerThrowsSecurityException() { var response = await RestierTestHelpers.ExecuteTestRequest <SecurityExceptionApi>(HttpMethod.Get, resource : "/Products"); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public async Task UpdateEmployee_ShouldReturn400() { var settings = new JsonSerializerSettings { Converters = new List <JsonConverter> { new JsonTimeSpanConverter(), new JsonTimeOfDayConverter() }, NullValueHandling = NullValueHandling.Ignore, DateFormatString = "yyyy-MM-ddTHH:mm:ssZ", }; var employeeRequest = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Readers?$top=1", acceptHeader : ODataConstants.DefaultAcceptHeader); employeeRequest.IsSuccessStatusCode.Should().BeTrue(); var(employeeList, ErrorContent) = await employeeRequest.DeserializeResponseAsync <ODataV4List <Employee> >(settings); employeeList.Should().NotBeNull(); employeeList.Items.Should().NotBeNullOrEmpty(); var employee = employeeList.Items.First(); employee.Should().NotBeNull(); employee.FullName += " Can't Update"; //employee.Universe = null; var employeeEditRequest = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Put, resource : $"/Readers({employee.Id})", payload : employee, acceptHeader : WebApiConstants.DefaultAcceptHeader, jsonSerializerSettings : settings); employeeEditRequest.IsSuccessStatusCode.Should().BeFalse(); employeeEditRequest.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public async Task TestInt64AsKey() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi>(HttpMethod.Get, resource : "/Stores(1)"); response.IsSuccessStatusCode.Should().BeTrue(); TestContext.WriteLine(await response.Content.ReadAsStringAsync()); }
public async Task PatchBook() { var bookRequest = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Books?$top=1", acceptHeader : ODataConstants.DefaultAcceptHeader); bookRequest.IsSuccessStatusCode.Should().BeTrue(); var(bookList, ErrorContent) = await bookRequest.DeserializeResponseAsync <ODataV4List <Book> >(); bookList.Should().NotBeNull(); bookList.Items.Should().NotBeNullOrEmpty(); var book = bookList.Items.First(); book.Should().NotBeNull(); var payload = new { Title = book.Title + " | Patch Test" }; var bookEditRequest = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(new HttpMethod("PATCH"), resource : $"/Books({book.Id})", payload : payload, acceptHeader : WebApiConstants.DefaultAcceptHeader); bookEditRequest.IsSuccessStatusCode.Should().BeTrue(); var bookCheckRequest = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : $"/Books({book.Id})", acceptHeader : ODataConstants.DefaultAcceptHeader); bookCheckRequest.IsSuccessStatusCode.Should().BeTrue(); var(book2, ErrorContent2) = await bookCheckRequest.DeserializeResponseAsync <Book>(); book2.Should().NotBeNull(); book2.Title.Should().EndWith(" | Patch Test"); }
public async Task SingleContext_MarvelApiWorks() { var response = await RestierTestHelpers.ExecuteTestRequest<MarvelApi, MarvelContext>(HttpMethod.Get, resource: "/Characters"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task FunctionImportNotInControllerShouldReturnNotImplemented() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi>(HttpMethod.Get, resource : "/GetBestProduct"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.StatusCode.Should().Be(HttpStatusCode.NotImplemented); }
public async Task GetNonExistingEntityTest() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi, DbContext>(HttpMethod.Get, resource : "/Products(-1)", serviceCollection : di); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task NonExistentEntitySetReturns404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Subscribers"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task EmptyEntitySetQueryReturns200Not404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/LibraryCards"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task FallbackApi_Resource_ShouldNotFallBack() { // Should be routed to RestierController. var response = await RestierTestHelpers.ExecuteTestRequest <FallbackApi>(HttpMethod.Get, resource : "/PreservedOrders"); TestContext.WriteLine(await response.Content.ReadAsStringAsync()); response.IsSuccessStatusCode.Should().BeTrue(); (await response.Content.ReadAsStringAsync()).Should().Contain("\"Id\":234"); }
public async Task BoundFunctionWithExpand() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Publishers/Publisher1/PublishedBooks()?$expand=Publisher"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("Publisher Way"); }
public async Task FallbackApi_NavigationProperty_ShouldFallBack() { // Should fallback to PeopleController. var response = await RestierTestHelpers.ExecuteTestRequest <FallbackApi>(HttpMethod.Get, resource : "/People(1)/Orders"); TestContext.WriteLine(await response.Content.ReadAsStringAsync()); response.IsSuccessStatusCode.Should().BeTrue(); ((Order[])((ObjectContent)response.Content).Value).Single().Id.Should().Be(123); }
public async Task EmptyFilterQueryReturns200Not404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Books?$filter=Title eq 'Sesame Street'"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task ActionImportNotInModelShouldReturnNotFound() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi, DbContext>(HttpMethod.Get, resource : "/RemoveWorstProduct2", serviceCollection : di); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task FallbackApi_EntitySet_ShouldFallBack() { // Should fallback to PeopleController. var response = await RestierTestHelpers.ExecuteTestRequest <FallbackApi, DbContext>(HttpMethod.Get, resource : "/People", serviceCollection : addTestServices); TestContext.WriteLine(await response.Content.ReadAsStringAsync()); response.IsSuccessStatusCode.Should().BeTrue(); ((Person[])((ObjectContent)response.Content).Value).Single().Id.Should().Be(999); }
public async Task FunctionParameters_IntParameter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/PublishBooks(Count=5)"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("Comes Back"); }
public async Task ObservableCollectionsAsCollectionNavigationProperties() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Publishers('Publisher2')/Books"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task EmptyEntitySetQueryReturns200Not404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(HttpMethod.Get, resource : "/LibraryCards"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task FunctionParameters_BooleanParameter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(HttpMethod.Get, resource : "/PublishBook(IsActive=true)"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("in the Hat"); }
public async Task Authorization_FilterReturns403() { var response = await RestierTestHelpers.ExecuteTestRequest <UnauthorizedLibraryApi>(HttpMethod.Get, resource : "/Books"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public async Task EmptyFilterQueryReturns200Not404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(HttpMethod.Get, resource : "/Books?$filter=Title eq 'Sesame Street'"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task NonExistentEntitySetReturns404() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(HttpMethod.Get, resource : "/Subscribers"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public async Task ObservableCollectionsAsCollectionNavigationProperties() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Publishers('Publisher2')/Books"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task CountPlusExpandShouldntThrowExceptions() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Publishers?$expand=Books"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("A Clockwork Orange"); }
public async Task PostFunctionImportShouldReturnNotFound() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi, DbContext>(HttpMethod.Post, resource : "/GetBestProduct", serviceCollection : di); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); // TODO: standalone testing shows 501, but here is 500, will figure out detail reason response.StatusCode.Should().Be(HttpStatusCode.InternalServerError); }
public async Task ActionParameters_MissingParameter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(HttpMethod.Post, resource : "/CheckoutBook"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeFalse(); content.Should().Contain("ArgumentNullException"); }
public async Task FunctionWithFilter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/FavoriteBooks()?$filter=contains(Title,'Cat')"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("Cat"); content.Should().NotContain("Mouse"); }
public async Task FunctionParameters_IntParameter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/PublishBooks(Count=5)"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("Comes Back"); }
public async Task ActionImportNotInControllerShouldReturnNotImplemented() { var response = await RestierTestHelpers.ExecuteTestRequest <StoreApi>(HttpMethod.Post, resource : "/RemoveWorstProduct"); var content = await response.Content.ReadAsStringAsync(); TestContext.WriteLine(content); // TODO: standalone testing shows 501, but here is 500, will figure out detail reason response.StatusCode.Should().Be(HttpStatusCode.InternalServerError); }