public async Task CountPlusSelectShouldntThrowExceptions() { var client = await RestierTestHelpers.GetTestableHttpClient <LibraryApi, LibraryContext>(); var response = await client.ExecuteTestRequest(HttpMethod.Get, resource : "/Readers?$count=true&$select=Id,FullName"); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain("\"@odata.count\":2,"); }
public async Task CountPlusExpandShouldntThrowExceptions() { var client = await RestierTestHelpers.GetTestableHttpClient <LibraryApi, LibraryContext>(); var response = await client.ExecuteTestRequest(HttpMethod.Get, resource : "/Publishers?$top=5&$count=true&$expand=Books"); var content = await response.Content.ReadAsStringAsync(); content.Should().Contain("\"@odata.count\":2,"); }
public async Task GetQueryableSource_ProviderCannotGenericExecute() { var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase; var source = api.GetQueryableSource <string>("Test"); Action exceptionTest = () => { source.Provider.Execute <string>(null); }; exceptionTest.Should().Throw <NotSupportedException>(); }
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 GetQueryableSource_OfT_ContainerElementThrowsIfWrongType() { var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di) as ApiBase; var arguments = new object[0]; Action exceptionTest = () => { api.GetQueryableSource <object>("Test", arguments); }; exceptionTest.Should().Throw <ArgumentException>(); }
public async Task GetQueryableSource_ComposableFunction_ThrowsIfWrongType() { var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase; var arguments = new object[0]; Action exceptionTest = () => { api.GetQueryableSource <object>("Namespace", "Function", arguments); }; exceptionTest.Should().Throw <ArgumentException>(); }
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 GetQueryableSource_ProviderCannotExecute() { var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di) as ApiBase; var source = api.GetQueryableSource <string>("Test"); Action exceptionTest = () => { source.Provider.Execute(null); }; exceptionTest.Should().Throw <NotSupportedException>(); }
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>(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 CountPlusExpandShouldntThrowExceptions() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi>(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 ApiModelBuilder_ShouldProduceCorrectModelForDerivedApi() { var model = await RestierTestHelpers.GetTestableModelAsync <ApiB>(); model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("ApiConfiguration"); model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Invisible"); model.EntityContainer.FindEntitySet("Customers").Should().NotBeNull(); model.EntityContainer.FindSingleton("Me").Should().NotBeNull(); model.EntityContainer.FindEntitySet("People").Should().NotBeNull(); }
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 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 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 ApiModelBuilder_ShouldProduceCorrectModelForOverridingProperty() { var model = await RestierTestHelpers.GetTestableModelAsync <ApiC, DbContext>(serviceCollection : di); model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("ApiConfiguration"); model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Invisible"); model.EntityContainer.FindEntitySet("People").Should().NotBeNull(); model.EntityContainer.FindEntitySet("Customers").EntityType().Name.Should().Be("Customer"); model.EntityContainer.FindSingleton("Me").EntityType().Name.Should().Be("Customer"); }
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 GetQueryableSource_EntitySet_ThrowsIfNotMapped() { var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : diEmpty) as ApiBase; var arguments = new object[0]; Action exceptionTest = () => { api.GetQueryableSource("Test", arguments); }; exceptionTest.Should().Throw <NotSupportedException>(); }
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 GetQueryableSource_OfT_ComposableFunction_ThrowsIfNotMapped() { var api = await RestierTestHelpers.GetTestableApiInstance <TestApiEmpty>() as ApiBase; var arguments = new object[0]; Action exceptionTest = () => { api.GetQueryableSource <DateTime>("Namespace", "Function", arguments); }; exceptionTest.Should().Throw <NotSupportedException>(); }
public async Task CountPlusExpandShouldntThrowExceptions() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Publishers?$expand=Books"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("A Clockwork Orange"); }
public async Task GetQueryableSource_CannotEnumerateIEnumerable() { var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase; var source = api.GetQueryableSource <string>("Test"); Action exceptionTest = () => { (source as IEnumerable).GetEnumerator(); }; exceptionTest.Should().Throw <NotSupportedException>(); }
public async Task ApiModelBuilder_ShouldNotAddAmbiguousNavigationPropertyBindings() { // In this case, two entity sets Employees and People have entity type Person. // Bindings for collection navigation property Customer.Friends should NOT be added. // Bindings for singleton navigation property Customer.BestFriend should NOT be added. var model = await RestierTestHelpers.GetTestableModelAsync <ApiG, DbContext>(serviceCollection : di); model.EntityContainer.FindEntitySet("Customers").NavigationPropertyBindings.Should().BeEmpty(); model.EntityContainer.FindSingleton("Me").NavigationPropertyBindings.Should().BeEmpty(); }
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); }
public async Task ActionParameters_MissingParameter() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Post, resource : "/CheckoutBook"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeFalse(); content.Should().Contain("NullReferenceException"); //content.Should().Contain("ArgumentNullException"); }
public async Task StoreApi_CompareCurrentApiMetadataToPriorRun() { var fileName = $"{Path.Combine(relativePath, baselineFolder)}{typeof(StoreApi).Name}-ApiMetadata.txt"; File.Exists(fileName).Should().BeTrue(); var oldReport = File.ReadAllText(fileName); var newReport = await RestierTestHelpers.GetApiMetadataAsync <StoreApi, DbContext>(serviceCollection : (services) => { services.AddTestStoreApiServices(); }); oldReport.Should().BeEquivalentTo(newReport.ToString()); }
public async Task LibraryApi_CompareCurrentApiMetadataToPriorRun() { var fileName = $"{Path.Combine(relativePath, baselineFolder)}{typeof(LibraryApi).Name}-ApiMetadata.txt"; File.Exists(fileName).Should().BeTrue(); var oldReport = File.ReadAllText(fileName); var newReport = await RestierTestHelpers.GetApiMetadataAsync <LibraryApi, LibraryContext>(); oldReport.Should().BeEquivalentTo(newReport.ToString()); }
public async Task FunctionParameters_GuidParameter() { var testGuid = Guid.NewGuid(); var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : $"/SubmitTransaction(Id={testGuid})"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain(testGuid.ToString()); content.Should().Contain("Shrugged"); }
public async Task InQueries_IdInList() { var response = await RestierTestHelpers.ExecuteTestRequest <LibraryApi, LibraryContext>(HttpMethod.Get, resource : "/Books?$filter=Id in ['c2081e58-21a5-4a15-b0bd-fff03ebadd30','0697576b-d616-4057-9d28-ed359775129e']"); var content = await TestContext.LogAndReturnMessageContentAsync(response); response.IsSuccessStatusCode.Should().BeTrue(); content.Should().Contain("Jungle Book, The"); content.Should().Contain("Color Purple, The"); content.Should().NotContain("A Clockwork Orange"); }
public async Task GetQueryableSource_ComposableFunction_IsConfiguredCorrectly() { var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase; var arguments = new object[0]; var source = api.GetQueryableSource("Namespace", "Function", arguments); CheckQueryable(source, typeof(DateTime), new List <string> { "Namespace", "Function" }, arguments); }