public async Task FieldEndpoint() { IRestEndpoint endpoint = _navigator.GetEndpointFromPath("artists/123/Name"); ResourceBody response = await endpoint.GetAsync(null); Assert.Equal(response.GetObject(), TestRepositories.ArtistName); }
public async Task MemoryCollection() { var endpointContext = new TestEndpointContext(); IRestEndpoint endpoint = endpointContext.Services.EndpointResolver.GetFromResource(endpointContext, new ArtistMemoryCollection()); var response = (CollectionBody)(await endpoint.GetAsync(null)); var firstObj = response.Items.First(); Assert.Equal(firstObj["Name"], TestRepositories.ArtistName); }
public async Task ListArtists() { IRestEndpoint endpoint = _navigator.GetEndpointFromPath("artists"); var response = (CollectionBody)(await endpoint.GetAsync(null)); RestItemData[] arr = response.Items.ToArray(); int firstId = (int)arr[0]["ID"]; Assert.True(firstId > 0); }
public async Task ItemEndpoint() { IRestEndpoint endpoint = _navigator.GetEndpointFromPath("artists/123"); ItemBody itemBody = (ItemBody)(await endpoint.GetAsync(null)); RestItemData itemData = itemBody.Item; Assert.Equal("ID", itemData.Keys.First()); int firstId = (int)itemData["ID"]; Assert.True(firstId > 0); }
public async Task <object> GetAsync() { IRestEndpoint endpoint = GetEndpoint(); if (!endpoint.EvaluatePreconditions(GetPreconditions())) { return(StatusCode(HttpStatusCode.NotModified)); } ResourceBody resourceBody = await endpoint.GetAsync(GetQuery()); ResponseBuilder.AddResource(resourceBody); return(Response.ResourceBody); // TODO headers? }
public async Task DictionaryEndpoint() { IRestEndpoint endpoint = _navigator.GetEndpointFromPath("artists/by_ID"); DictionaryBody dictionaryBody = (DictionaryBody)(await endpoint.GetAsync(null)); foreach (var pair in dictionaryBody.Items) { var itemData = pair.Value as RestItemData; int id = (int)itemData["ID"]; Assert.True(id > 0); Assert.Equal(pair.Key, id.ToString()); } }
public async Task FieldSelector_ManualNext_CorrectName() { var endpointContext = new TestEndpointContext(); var testQuery = new TestCollectionQuery { SelectFields = new[] { "Name" } }; EngineRestCollection <Artist> artistsCollection = IntegratedRestDirectory.GetArtistCollection(endpointContext.Request); IRestEndpoint endpoint = endpointContext.Services.EndpointResolver.GetFromResource(endpointContext, artistsCollection); endpoint = endpoint.Next(new AggregatorNextPath("123", endpointContext.Services.NameSwitcher)); var response = (ItemBody)(await endpoint.GetAsync(testQuery)); Assert.Equal(response.Item["Name"], TestRepositories.ArtistName); }
public async Task FieldSelector_Collection_DoesntThrow() { var endpointContext = new TestEndpointContext(); var testQuery = new TestCollectionQuery { SelectFields = new[] { "Id", "Name" } }; EngineRestCollection <Artist> artistsCollection = IntegratedRestDirectory.GetArtistCollection(endpointContext.Request); IRestEndpoint endpoint = endpointContext.Services.EndpointResolver.GetFromResource(endpointContext, artistsCollection); var resource = (CollectionBody)(await endpoint.GetAsync(testQuery)); Assert.Equal(1, resource.Items.Count()); var builder = new ResponseBuilder(new Response("/"), endpointContext.Modifiers); builder.AddResource(resource); }
private async Task <object> ExecuteWithRequeryAsync(IRequestReader reader, ResponseBuilder response) { object returnValue = await _executor.ExecuteAsync(reader, response); IRestEndpoint endpoint = _executor.Endpoint; if (returnValue is AcknowledgmentFeedback ackFeedback && ackFeedback.Acknowledgment is CreatedItemAcknowledgment created) { endpoint = endpoint.Next(new RawNextPath(created.NewIdentifier.ToString())); Debug.Assert(endpoint != null); } ResourceBody resourceBody = await endpoint.GetAsync(reader.GetQuery()); response.AddResource(resourceBody); return(returnValue); }