public async Task <ObjectInstance> GetObjectInstanceModel(string lwm2mClientID, string objectTypeID, string objectInstanceID) { ObjectInstance objectInstance = null; APIEntryPoint entryPoint = await GetAPIEntryPoint(); if (entryPoint != null) { Client client = await GetClient(lwm2mClientID, entryPoint); if (client != null) { ObjectType objectType = await GetObjectType(client, objectTypeID); if (objectType != null) { ObjectDefinition objectDefinition = await GetObjectDefinition(objectType); if (objectDefinition != null) { objectInstance = await GetObjectInstance(objectDefinition, objectType, objectInstanceID); } } } } return(objectInstance); }
private void ExpectLinks(APIEntryPoint entryPoint, LinkableResource expected) { Assert.NotNull(entryPoint); Assert.NotNull(entryPoint.Links); Assert.Equal(expected.Links.Count, entryPoint.Links.Count); int matches = 0; foreach (Link actualLink in entryPoint.Links) { Assert.NotNull(actualLink.rel); Assert.NotNull(actualLink.href); Assert.NotEmpty(actualLink.href); Assert.NotNull(actualLink.type); foreach (Link expectedLink in expected.Links) { if (actualLink.rel.Equals(expectedLink.rel)) { Assert.Equal(expectedLink.type, actualLink.type); matches++; } } } Assert.Equal(matches, entryPoint.Links.Count); }
public async void AnonymousLinks() { // Arrange string contentType = TestConfiguration.TestData.RestAPI.ContentType; LinkableResource expected = new LinkableResource(); expected.AddLink("authenticate", null, $"application/vnd.imgtec.oauthtoken+{contentType}"); expected.AddLink("versions", null, $"application/vnd.imgtec.versions+{contentType}"); // Act APIEntryPoint entryPoint = await _HttpClientFixture.GetAPIEntryPoint(); // Assert ExpectLinks(entryPoint, expected); }
public IActionResult GetEntryPoint() { IActionResult result; APIEntryPoint response = new APIEntryPoint(); string rootUrl = Request.GetRootUrl(); response.AddLink<OAuthToken>(Request, "authenticate", string.Concat(rootUrl, "/oauth/token")); if (User.Identity is OrganisationIdentity) { response.AddLink<AccessKeys>(Request, "accesskeys", string.Concat(rootUrl, "/accesskeys")); response.AddLink<Configuration>(Request, "configuration", string.Concat(rootUrl, "/configuration")); response.AddLink<Clients>(Request, "clients", string.Concat(rootUrl, "/clients")); response.AddLink<Identities>(Request, "identities", string.Concat(rootUrl, "/identities")); response.AddLink<ObjectDefinitions>(Request, "objectdefinitions", string.Concat(rootUrl, "/objecttypes/definitions")); response.AddLink<Subscriptions>(Request, "subscriptions", string.Concat(rootUrl, "/subscriptions")); response.AddLink<Metrics>(Request, "metrics", string.Concat(rootUrl, "/metrics")); } response.AddLink<Versions>(Request, "versions", string.Concat(rootUrl, "/versions")); result = Request.GetObjectResult(response); return result; }
public IActionResult GetEntryPoint() { IActionResult result; APIEntryPoint response = new APIEntryPoint(); string rootUrl = Request.GetRootUrl(); response.AddLink <OAuthToken>(Request, "authenticate", string.Concat(rootUrl, "/oauth/token")); if (User.Identity is OrganisationIdentity) { response.AddLink <AccessKeys>(Request, "accesskeys", string.Concat(rootUrl, "/accesskeys")); response.AddLink <Configuration>(Request, "configuration", string.Concat(rootUrl, "/configuration")); response.AddLink <Clients>(Request, "clients", string.Concat(rootUrl, "/clients")); response.AddLink <Identities>(Request, "identities", string.Concat(rootUrl, "/identities")); response.AddLink <ObjectDefinitions>(Request, "objectdefinitions", string.Concat(rootUrl, "/objecttypes/definitions")); response.AddLink <Subscriptions>(Request, "subscriptions", string.Concat(rootUrl, "/subscriptions")); response.AddLink <Metrics>(Request, "metrics", string.Concat(rootUrl, "/metrics")); } response.AddLink <Versions>(Request, "versions", string.Concat(rootUrl, "/versions")); result = Request.GetObjectResult(response); return(result); }
private async Task <Client> GetClient(string lwm2mClientID, APIEntryPoint entryPoint) { Link clientsLink = entryPoint.GetLink("clients"); Clients clients = await HttpClient.GetModel <Clients>(new HttpRequestMessage(HttpMethod.Get, clientsLink.href), _OAuthToken); Client matchedClient = null; if (clients != null) { foreach (Client client in clients.Items) { Link selfLink = client.GetLink("self"); string clientID = selfLink.href.Substring(selfLink.href.LastIndexOf('/') + 1); if (clientID.Equals(lwm2mClientID)) { matchedClient = client; break; } } } return(matchedClient); }
public async void AuthenticatedLinks() { // Arrange string contentType = TestConfiguration.TestData.RestAPI.ContentType; LinkableResource expected = new LinkableResource(); expected.AddLink("authenticate", null, $"application/vnd.imgtec.oauthtoken+{contentType}"); expected.AddLink("versions", null, $"application/vnd.imgtec.versions+{contentType}"); expected.AddLink("accesskeys", null, $"application/vnd.imgtec.accesskeys+{contentType}"); expected.AddLink("configuration", null, $"application/vnd.imgtec.configuration+{contentType}"); expected.AddLink("clients", null, $"application/vnd.imgtec.clients+{contentType}"); expected.AddLink("identities", null, $"application/vnd.imgtec.identities+{contentType}"); expected.AddLink("objectdefinitions", null, $"application/vnd.imgtec.objectdefinitions+{contentType}"); expected.AddLink("subscriptions", null, $"application/vnd.imgtec.subscriptions+{contentType}"); expected.AddLink("metrics", null, $"application/vnd.imgtec.metrics+{contentType}"); // Act await _HttpClientFixture.Login(); APIEntryPoint entryPoint = await _HttpClientFixture.GetAPIEntryPoint(); //Assert ExpectLinks(entryPoint, expected); }