예제 #1
0
        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,");
        }
예제 #2
0
        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,");
        }
예제 #3
0
        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>();
        }
예제 #4
0
        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);
        }
예제 #5
0
        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>();
        }
예제 #6
0
        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>();
        }
예제 #7
0
        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);
        }
예제 #8
0
        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>();
        }
예제 #9
0
        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");
        }
예제 #10
0
        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");
        }
예제 #11
0
        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");
        }
예제 #12
0
        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();
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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");
        }
예제 #17
0
        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);
        }
예제 #18
0
        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>();
        }
예제 #19
0
        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");
        }
예제 #20
0
        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>();
        }
예제 #21
0
파일: ExpandTests.cs 프로젝트: wwwK/RESTier
        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");
        }
예제 #22
0
        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>();
        }
예제 #23
0
        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();
        }
예제 #24
0
        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);
        }
예제 #25
0
        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");
        }
예제 #26
0
        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());
        }
예제 #27
0
        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());
        }
예제 #28
0
        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");
        }
예제 #29
0
파일: InTests.cs 프로젝트: wwwK/RESTier
        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");
        }
예제 #30
0
        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);
        }