-
|
Hi! I am trying to mock parts of the Graph API to have a local entra mock for local testing. I am only implementing the endpoints that my application uses when talking to Entra, but I am struggling a bit with getting the correct behaviour from OData. Specifically I need to mock I have tried making a public class Group
{
public required string Id { get; set; }
[AutoExpand]
public IEnumerable<User> Members { get; set; } = [];
}And then have the following public class GroupsController(IUserRepository userRepository) : ODataController
{
private readonly IUserRepository _userRepository = userRepository;
[EnableQuery]
public ActionResult<IQueryable<Group>> Get()
{
var group = new Group
{
Id = "12345",
Members = _userRepository.GetUsers()
};
var groups = new List<Group> { group };
return Ok(groups);
}
[HttpGet("groups/{key}/members")]
[EnableQuery]
public ActionResult<IEnumerable<User>> GetMembers([FromRoute] string key)
{
if (key != "12345")
return NotFound();
var users = _userRepository.GetUsers();
return Ok(users);
}
[HttpGet("groups/{key}/members/graph.user")]
[EnableQuery]
public ActionResult<IEnumerable<User>> GetMembersGraphUsers([FromRoute] string key)
{
if (key != "12345")
return NotFound();
var users = _userRepository.GetUsers();
return Ok(users);
}
}This makes e.g. Edit: I have gotten it working by making the One follow-up question: Why can't I use explicit routing to specify the endpoint in this case? This works, but only if I move my [HttpGet("groups/{key}/members/Graph.User")]
[EnableQuery]
public ActionResult<IEnumerable<User>> GetMembersOfUser([FromRoute] string key)
{
if (key != "12345")
return NotFound();
var users = _userRepository.GetUsers();
return Ok(users);
}If I try to keep it in a different namespace, but with explicit routing, it does not work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hello @Irubataru The routing is based on OData conventions and specifications. If you use the template I supposed that But it doesn't seem like So creating a type To learn more about OData routing and the various conventions, check out the docs: https://learn.microsoft.com/en-us/odata/webapi-8/fundamentals/routing-overview?tabs=net60 |
Beta Was this translation helpful? Give feedback.
Hello @Irubataru
The routing is based on OData conventions and specifications. If you use the template
groups/{key}/members/graph.user, how this gets interpreted depends on the schema (IEdmModel).I supposed that
membersis a navigation property of the group entity. Themembersnavigation property, can be followed by different types of segments depending on its type. For example, if you had a function in your schema calledgraph.user(i.e. function name isuser, in thegraphnamespace), then for it be used next tomembers, it would need to defined as a bound function whose binding parameter type correspond to the type of themembersnavigation property. In this case I assume it would be a…