Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c170bc5
Fixed Select Wilcard on Action and Function
May 13, 2022
c283b6c
Added spacing between tests
Nthemba May 16, 2022
e06ddbb
Update test/Microsoft.AspNetCore.OData.Tests/Query/ODataQueryContextT…
Nthemba May 16, 2022
b5cb5c2
Update test/Microsoft.AspNetCore.OData.Tests/Query/ODataQueryContextT…
Nthemba May 16, 2022
e858741
Added e2e test on select * on Function
May 17, 2022
8ff9896
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba May 19, 2022
04003ed
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba May 19, 2022
88dd812
Apply suggestions from code review
Nthemba May 19, 2022
e88c26c
Apply suggestions from code review
Nthemba May 19, 2022
d77a3f7
Moved EDMModel to startup class
May 19, 2022
2191c5a
Update test/Microsoft.AspNetCore.OData.Tests/Query/ODataQueryContextT…
Nthemba May 23, 2022
873d3e2
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba May 23, 2022
cfb3a8b
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba May 23, 2022
57cef21
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba Jun 8, 2022
f917a17
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba Jun 8, 2022
f190852
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba Jun 8, 2022
47e24b7
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba Jun 8, 2022
6a00f10
Update test/Microsoft.AspNetCore.OData.E2E.Tests/Query/SelectWilCardO…
Nthemba Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal static (IEdmProperty, IEdmStructuredType, string) GetPropertyAndStructu
{
if (structuredType == null)
{
structuredType = operationSegment.EdmType as IEdmStructuredType;
structuredType = operationSegment.EdmType.AsElementType() as IEdmStructuredType;
Comment thread
habbes marked this conversation as resolved.
}

string name = operationSegment.Operations.First().FullName() + typeCast;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// <copyright file="SelectWildCardOnFunctionTests.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Microsoft.AspNetCore.OData.TestCommon;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.AspNetCore.OData.E2E.Tests.Query.SelectWilCardOnFunction
{
public sealed class SelectWildCardOnFunctionTests : WebODataTestBase<SelectWildCardOnFunctionTests.Startup>
{
public class Startup : TestStartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.ConfigureControllers(typeof(CustomersController));

IEdmModel model = GetEdmModel();
services.AddControllers().AddOData(opt =>
{
opt.Select();
opt.RouteOptions.EnableNonParenthesisForEmptyParameterFunction = true;
opt.AddRouteComponents("odata", model);
});
}

public static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Customer>("Customers").EntityType
.Collection.Function("GetAllCustomers")
.ReturnsCollectionFromEntitySet<Customer>("Customers");

return builder.GetEdmModel();
}
}

public SelectWildCardOnFunctionTests(WebODataTestFixture<Startup> fixture)
: base(fixture)
{
}

/// <summary>
/// For Select query with wildcard on Function
/// </summary>
/// <returns></returns>
[Fact]
public async Task SelectWildCardOnFunction_Success()
{
//Arrange
string queryUrl = "odata/Customers/GetAllCustomers?$select=*";
Comment thread
Nthemba marked this conversation as resolved.

using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, queryUrl))
{
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=none"));

//Act
using (HttpResponseMessage response = await this.Client.SendAsync(request))
{
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

List<Customer> customers = JToken.Parse(await response.Content.ReadAsStringAsync())["value"].ToObject<List<Customer>>();
foreach(Customer c in customers)
{
Assert.Equal("custId1", c.Id);
Assert.Equal("John", c.Name);
Assert.Equal("Active", c.Status);
}
}
}
}
}

public class Customer
{
public string Id { get; set; }
public string Name { get; set; }
public string Status { get; set; }
}

public class CustomersController : ODataController
{
[HttpGet]
public IEnumerable<Customer> GetAllCustomers()
{
return new List<Customer>()
{
new Customer
{
Id = "custId1",
Name = "John",
Status = "Active"
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Tests.Commons;
using Microsoft.AspNetCore.OData.Tests.Models;
Expand Down Expand Up @@ -91,6 +93,40 @@ public void CtorODataQueryContext_TakingClrTypeAndPath_SetsProperties()
Assert.Same(typeof(Customer), context.ElementClrType);
}

[Fact]
Comment thread
Nthemba marked this conversation as resolved.
public void CtorODataQueryContext_TakingOperationAndPath_SetsProperties()
{
// Arrange
ODataModelBuilder odataModel = new ODataModelBuilder().Add_Customer_EntityType();
string setName = typeof(Customer).Name;
odataModel.EntitySet<Customer>(setName);
odataModel.EntitySet<Customer>("Customers").EntityType
.Collection.Function("GetAllCustomers")
.ReturnsCollectionFromEntitySet<Customer>("GetAllCustomer");
IEdmModel model = odataModel.GetEdmModel();
IEnumerable<OperationConfiguration> operationConfiguration = odataModel.Operations;

string qualifiedName = null;
foreach(var op in operationConfiguration)
{
qualifiedName = op.FullyQualifiedName;
}

IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(setName);
IEdmEntityType entityType = entitySet.EntityType();
IEnumerable<IEdmOperation> operations = model.FindDeclaredOperations(qualifiedName);

ODataPath path = new ODataPath(new EntitySetSegment(entitySet), new OperationSegment(operations, entitySet));

// Act
ODataQueryContext context = new ODataQueryContext(model, typeof(Customer), path);

// Assert
Comment thread
Nthemba marked this conversation as resolved.
Assert.Same(model, context.Model);
Assert.Same(entityType, context.TargetStructuredType);
Assert.Same(typeof(Customer), context.ElementClrType);
}

[Fact]
public void CtorODataQueryContext_TakingEdmType_ThrowsArgumentNull_Model()
{
Expand Down