public async Task EventRoutes_Lifecycle() { // arrange DigitalTwinsClient client = GetClient(); // Ensure unique eventRouteId and endpointName string eventRouteId = $"someEventRouteId-{GetRandom()}"; string filter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"; var eventRoute = new EventRoute(EndpointName) { Filter = filter }; // Test CreateEventRoute Response createEventRouteResponse = await client.CreateEventRouteAsync(eventRouteId, eventRoute).ConfigureAwait(false); createEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Test GetEventRoute EventRoute getEventRouteResult = await client.GetEventRouteAsync(eventRouteId); eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); eventRouteId.Should().Be(getEventRouteResult.Id); // Test GetEventRoutes var eventRoutesListOptions = new EventRoutesListOptions(); AsyncPageable <EventRoute> eventRouteList = client.GetEventRoutesAsync(eventRoutesListOptions); bool eventRouteFoundInList = false; await foreach (EventRoute eventRouteListEntry in eventRouteList) { if (StringComparer.Ordinal.Equals(eventRouteListEntry.Id, eventRouteId)) { eventRouteFoundInList = true; eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); break; } } eventRouteFoundInList.Should().BeTrue("Newly created event route should have been present when listing all event routes"); // Test DeleteEventRoute Response deleteEventRouteResponse = await client.DeleteEventRouteAsync(eventRouteId).ConfigureAwait(false); deleteEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Verify event route was deleted by trying to get it again // act Func <Task> act = async() => await client.GetEventRouteAsync(eventRouteId).ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.NotFound); }
public async Task EventRoutes_Lifecycle() { // arrange DigitalTwinsClient client = GetClient(); // Ensure unique eventRouteId string eventRouteId = $"someEventRouteId-{GetRandom()}"; string filter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"; var eventRoute = new DigitalTwinsEventRoute(EndpointName, filter); // Test CreateEventRoute Response createEventRouteResponse = await client.CreateOrReplaceEventRouteAsync(eventRouteId, eventRoute).ConfigureAwait(false); createEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Wait certain amount of time to test if the issue is with propagation. // TODO: azabbasi: remove this logic once experiment is over. await WaitIfLiveAsync(_creationDelay); // Test GetEventRoute DigitalTwinsEventRoute getEventRouteResult = await client.GetEventRouteAsync(eventRouteId); eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); eventRouteId.Should().Be(getEventRouteResult.Id); // Test GetEventRoutes AsyncPageable <DigitalTwinsEventRoute> eventRouteList = client.GetEventRoutesAsync(); bool eventRouteFoundInList = false; await foreach (DigitalTwinsEventRoute eventRouteListEntry in eventRouteList) { if (StringComparer.Ordinal.Equals(eventRouteListEntry.Id, eventRouteId)) { eventRouteFoundInList = true; eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); break; } } eventRouteFoundInList.Should().BeTrue("Newly created event route should have been present when listing all event routes"); // Test DeleteEventRoute Response deleteEventRouteResponse = await client.DeleteEventRouteAsync(eventRouteId).ConfigureAwait(false); deleteEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Verify event route was deleted by trying to get it again // act Func <Task> act = async() => await client.GetEventRouteAsync(eventRouteId).ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.NotFound); }
public void EventRoutes_EventRouteNotExist_ThrowsNotFoundException() { // arrange DigitalTwinsClient client = GetClient(); // act Func <Task> act = async() => await client.GetEventRouteAsync("someNonExistantEventRoute").ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.NotFound); }
public async Task CreateRouteAsync(RequestContext context) { var client = new DigitalTwinsClient(new Uri($"https://{context.Host}"), new DefaultAzureCredential()); EventRoute route = null; try { route = await client.GetEventRouteAsync(RouteId); } catch (RequestFailedException e) when(e.Status == 404) { } if (route == null) { _log.LogInformation($"Creating route for {context.InstanceName}"); await client.CreateEventRouteAsync(RouteId, new EventRoute(EndpointId) { Filter = "true" }); } }