Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventGrid Dataplane SDK: Re-generated SDK to include new event types + updated corresponding unit tests #4691

Merged
merged 4 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -241,7 +241,7 @@ public void ConsumeContainerRegistryImageDeletedEvent()
[Fact]
public void ConsumeIoTHubDeviceCreatedEvent()
{
string requestContent = "[{ \"id\": \"56afc886-767b-d359-d59e-0da7877166b2\", \"topic\": \"/SUBSCRIPTIONS/ID/RESOURCEGROUPS/rg/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/hub1\", \"subject\": \"devices/LogicAppTestDevice\", \"eventType\": \"Microsoft.Devices.DeviceCreated\", \"eventTime\": \"2018-01-02T19:17:44.4383997Z\", \"data\": { \"twin\": { \"deviceId\": \"LogicAppTestDevice\", \"etag\": \"AAAAAAAAAAE=\", \"status\": \"enabled\", \"statusUpdateTime\": \"0001-01-01T00:00:00\", \"connectionState\": \"Disconnected\", \"lastActivityTime\": \"0001-01-01T00:00:00\", \"cloudToDeviceMessageCount\": 0, \"authenticationType\": \"sas\", \"x509Thumbprint\": { \"primaryThumbprint\": null, \"secondaryThumbprint\": null }, \"version\": 2, \"properties\": { \"desired\": { \"$metadata\": { \"$lastUpdated\": \"2018-01-02T19:17:44.4383997Z\" }, \"$version\": 1 }, \"reported\": { \"$metadata\": { \"$lastUpdated\": \"2018-01-02T19:17:44.4383997Z\" }, \"$version\": 1 } } }, \"hubName\": \"egtesthub1\", \"deviceId\": \"LogicAppTestDevice\", \"operationTimestamp\": \"2018-01-02T19:17:44.4383997Z\", \"opType\": \"DeviceCreated\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\"}]";
string requestContent = "[{ \"id\": \"2da5e9b4-4e38-04c1-cc58-9da0b37230c0\", \"topic\": \"/SUBSCRIPTIONS/BDF55CDD-8DAB-4CF4-9B2F-C21E8A780472/RESOURCEGROUPS/EGTESTRG/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/EGTESTHUB1\", \"subject\": \"devices/48e44e11-1437-4907-83b1-4a8d7e89859e\", \"eventType\": \"Microsoft.Devices.DeviceCreated\", \"eventTime\": \"2018-07-03T23:20:07.6532054Z\", \"data\": { \"twin\": { \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\", \"etag\": \"AAAAAAAAAAE=\", \"deviceEtag\": null, \"status\": \"enabled\", \"statusUpdateTime\": \"0001-01-01T00:00:00\", \"connectionState\": \"Disconnected\", \"lastActivityTime\": \"0001-01-01T00:00:00\", \"cloudToDeviceMessageCount\": 0, \"authenticationType\": \"sas\", \"x509Thumbprint\": { \"primaryThumbprint\": null, \"secondaryThumbprint\": null }, \"version\": 2, \"properties\": { \"desired\": { \"$metadata\": { \"$lastUpdated\": \"2018-07-03T23:20:07.6532054Z\" }, \"$version\": 1 }, \"reported\": { \"$metadata\": { \"$lastUpdated\": \"2018-07-03T23:20:07.6532054Z\" }, \"$version\": 1 } } }, \"hubName\": \"EGTESTHUB1\", \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Expand All @@ -254,14 +254,40 @@ public void ConsumeIoTHubDeviceCreatedEvent()
[Fact]
public void ConsumeIoTHubDeviceDeletedEvent()
{
string requestContent = "[{ \"id\": \"56afc886-767b-d359-d59e-0da7877166b2\", \"topic\": \"/SUBSCRIPTIONS/id/RESOURCEGROUPS/rg/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/hub1\", \"subject\": \"devices/LogicAppTestDevice\", \"eventType\": \"Microsoft.Devices.DeviceDeleted\", \"eventTime\": \"2018-01-02T19:17:44.4383997Z\", \"data\": { \"twin\": { \"deviceId\": \"LogicAppTestDevice\", \"etag\": \"AAAAAAAAAAE=\", \"status\": \"enabled\", \"statusUpdateTime\": \"0001-01-01T00:00:00\", \"connectionState\": \"Disconnected\", \"lastActivityTime\": \"0001-01-01T00:00:00\", \"cloudToDeviceMessageCount\": 0, \"authenticationType\": \"sas\", \"x509Thumbprint\": { \"primaryThumbprint\": null, \"secondaryThumbprint\": null }, \"version\": 2, \"properties\": { \"desired\": { \"$metadata\": { \"$lastUpdated\": \"2018-01-02T19:17:44.4383997Z\" }, \"$version\": 1 }, \"reported\": { \"$metadata\": { \"$lastUpdated\": \"2018-01-02T19:17:44.4383997Z\" }, \"$version\": 1 } } }, \"hubName\": \"egtesthub1\", \"deviceId\": \"LogicAppTestDevice\", \"operationTimestamp\": \"2018-01-02T19:17:44.4383997Z\", \"opType\": \"DeviceCreated\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\"}]";
string requestContent = "[ { \"id\": \"aaaf95c6-ed99-b307-e321-81d8e4f731a6\", \"topic\": \"/SUBSCRIPTIONS/BDF55CDD-8DAB-4CF4-9B2F-C21E8A780472/RESOURCEGROUPS/EGTESTRG/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/EGTESTHUB1\", \"subject\": \"devices/48e44e11-1437-4907-83b1-4a8d7e89859e\", \"eventType\": \"Microsoft.Devices.DeviceDeleted\", \"eventTime\": \"2018-07-03T23:21:33.2753956Z\", \"data\": { \"twin\": { \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\", \"etag\": \"AAAAAAAAAAI=\", \"deviceEtag\": null, \"status\": \"enabled\", \"statusUpdateTime\": \"0001-01-01T00:00:00\", \"connectionState\": \"Disconnected\", \"lastActivityTime\": \"0001-01-01T00:00:00\", \"cloudToDeviceMessageCount\": 0, \"authenticationType\": \"sas\", \"x509Thumbprint\": { \"primaryThumbprint\": null, \"secondaryThumbprint\": null }, \"version\": 3, \"tags\": { \"testKey\": \"testValue\" }, \"properties\": { \"desired\": { \"$metadata\": { \"$lastUpdated\": \"2018-07-03T23:20:07.6532054Z\" }, \"$version\": 1 }, \"reported\": { \"$metadata\": { \"$lastUpdated\": \"2018-07-03T23:20:07.6532054Z\" }, \"$version\": 1 } } }, \"hubName\": \"EGTESTHUB1\", \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is IotHubDeviceDeletedEventData);
IotHubDeviceDeletedEventData eventData = (IotHubDeviceDeletedEventData)events[0].Data;
Assert.Equal("AAAAAAAAAAE=", eventData.Twin.Etag);
Assert.Equal("AAAAAAAAAAI=", eventData.Twin.Etag);
}

[Fact]
public void ConsumeIoTHubDeviceConnectedEvent()
{
string requestContent = "[ { \"id\": \"fbfd8ee1-cf78-74c6-dbcf-e1c58638ccbd\", \"topic\": \"/SUBSCRIPTIONS/BDF55CDD-8DAB-4CF4-9B2F-C21E8A780472/RESOURCEGROUPS/EGTESTRG/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/EGTESTHUB1\", \"subject\": \"devices/48e44e11-1437-4907-83b1-4a8d7e89859e\", \"eventType\": \"Microsoft.Devices.DeviceConnected\", \"eventTime\": \"2018-07-03T23:20:11.6921933+00:00\", \"data\": { \"deviceConnectionStateEventInfo\": { \"sequenceNumber\": \"000000000000000001D4132452F67CE200000002000000000000000000000001\" }, \"hubName\": \"EGTESTHUB1\", \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\", \"moduleId\": \"\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is IotHubDeviceConnectedEventData);
IotHubDeviceConnectedEventData eventData = (IotHubDeviceConnectedEventData)events[0].Data;
Assert.Equal("EGTESTHUB1", eventData.HubName);
}

[Fact]
public void ConsumeIoTHubDeviceDisconnectedEvent()
{
string requestContent = "[ { \"id\": \"877f0b10-a086-98ec-27b8-6ae2dfbf5f67\", \"topic\": \"/SUBSCRIPTIONS/BDF55CDD-8DAB-4CF4-9B2F-C21E8A780472/RESOURCEGROUPS/EGTESTRG/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/EGTESTHUB1\", \"subject\": \"devices/48e44e11-1437-4907-83b1-4a8d7e89859e\", \"eventType\": \"Microsoft.Devices.DeviceDisconnected\", \"eventTime\": \"2018-07-03T23:20:52.646434+00:00\", \"data\": { \"deviceConnectionStateEventInfo\": { \"sequenceNumber\": \"000000000000000001D4132452F67CE200000002000000000000000000000002\" }, \"hubName\": \"EGTESTHUB1\", \"deviceId\": \"48e44e11-1437-4907-83b1-4a8d7e89859e\", \"moduleId\": \"\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is IotHubDeviceDisconnectedEventData);
IotHubDeviceDisconnectedEventData eventData = (IotHubDeviceDisconnectedEventData)events[0].Data;
Assert.Equal("000000000000000001D4132452F67CE200000002000000000000000000000002", eventData.DeviceConnectionStateEventInfo.SequenceNumber);
}

// EventGrid events
Expand Down Expand Up @@ -316,7 +342,7 @@ public void ConsumeMediaServicesJobStateChangedEvent()
Assert.NotNull(events);
Assert.True(events[0].Data is MediaJobStateChangeEventData);
MediaJobStateChangeEventData eventData = (MediaJobStateChangeEventData)events[0].Data;
Assert.Equal("Finished", eventData.State);
Assert.Equal(JobState.Finished, eventData.State);
}

// Resource Manager (Azure Subscription/Resource Group) events
Expand Down Expand Up @@ -398,6 +424,46 @@ public void ConsumeResourceDeleteCancelEvent()
Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", eventData.TenantId);
}

[Fact]
public void ConsumeResourceActionSuccessEvent()
{
string requestContent = "[ { \"topic\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.Resources.ResourceActionSuccess\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"authorization\":\"{azure_resource_manager_authorizations}\", \"claims\":\"{azure_resource_manager_claims}\", \"correlationId\":\"54ef1e39-6a82-44b3-abc1-bdeb6ce4d3c6\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"operationName\":\"Microsoft.EventGrid/eventSubscriptions/write\", \"status\":\"Succeeded\", \"subscriptionId\":\"{subscription-id}\", \"tenantId\":\"72f988bf-86f1-41af-91ab-2d7cd011db47\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is ResourceActionSuccessData);
ResourceActionSuccessData eventData = (ResourceActionSuccessData)events[0].Data;
Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", eventData.TenantId);
}

[Fact]
public void ConsumeResourceActionFailureEvent()
{
string requestContent = "[ { \"topic\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.Resources.ResourceActionFailure\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"authorization\":\"{azure_resource_manager_authorizations}\", \"claims\":\"{azure_resource_manager_claims}\", \"correlationId\":\"54ef1e39-6a82-44b3-abc1-bdeb6ce4d3c6\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"operationName\":\"Microsoft.EventGrid/eventSubscriptions/write\", \"status\":\"Succeeded\", \"subscriptionId\":\"{subscription-id}\", \"tenantId\":\"72f988bf-86f1-41af-91ab-2d7cd011db47\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is ResourceActionFailureData);
ResourceActionFailureData eventData = (ResourceActionFailureData)events[0].Data;
Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", eventData.TenantId);
}

[Fact]
public void ConsumeResourceActionCancelEvent()
{
string requestContent = "[ { \"topic\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.Resources.ResourceActionCancel\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"authorization\":\"{azure_resource_manager_authorizations}\", \"claims\":\"{azure_resource_manager_claims}\", \"correlationId\":\"54ef1e39-6a82-44b3-abc1-bdeb6ce4d3c6\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"operationName\":\"Microsoft.EventGrid/eventSubscriptions/write\", \"status\":\"Succeeded\", \"subscriptionId\":\"{subscription-id}\", \"tenantId\":\"72f988bf-86f1-41af-91ab-2d7cd011db47\" }, \"dataVersion\": \"\", \"metadataVersion\": \"1\" }]";

var events = this.eventGridSubscriber.DeserializeEventGridEvents(requestContent);

Assert.NotNull(events);
Assert.True(events[0].Data is ResourceActionCancelData);
ResourceActionCancelData eventData = (ResourceActionCancelData)events[0].Data;
Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", eventData.TenantId);
}


// ServiceBus events
[Fact]
public void ConsumeServiceBusActiveMessagesAvailableWithNoListenersEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class EventTypes
// Device events
public const string IoTHubDeviceCreatedEvent = "Microsoft.Devices.DeviceCreated";
public const string IoTHubDeviceDeletedEvent = "Microsoft.Devices.DeviceDeleted";
public const string IoTHubDeviceConnectedEvent = "Microsoft.Devices.DeviceConnected";
public const string IoTHubDeviceDisconnectedEvent = "Microsoft.Devices.DeviceDisconnected";

// EventGrid events
public const string EventGridSubscriptionValidationEvent = "Microsoft.EventGrid.SubscriptionValidationEvent";
Expand All @@ -37,6 +39,9 @@ public class EventTypes
public const string ResourceDeleteSuccessEvent = "Microsoft.Resources.ResourceDeleteSuccess";
public const string ResourceDeleteFailureEvent = "Microsoft.Resources.ResourceDeleteFailure";
public const string ResourceDeleteCancelEvent = "Microsoft.Resources.ResourceDeleteCancel";
public const string ResourceActionSuccessEvent = "Microsoft.Resources.ResourceActionSuccess";
public const string ResourceActionFailureEvent = "Microsoft.Resources.ResourceActionFailure";
public const string ResourceActionCancelEvent = "Microsoft.Resources.ResourceActionCancel";

// ServiceBus events
public const string ServiceBusActiveMessagesAvailableWithNoListenersEvent = "Microsoft.ServiceBus.ActiveMessagesAvailableWithNoListeners";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal static class SystemEventTypeMappings
// IoTHub Device events
{ EventTypes.IoTHubDeviceCreatedEvent, typeof(IotHubDeviceCreatedEventData) },
{ EventTypes.IoTHubDeviceDeletedEvent, typeof(IotHubDeviceDeletedEventData) },
{ EventTypes.IoTHubDeviceConnectedEvent, typeof(IotHubDeviceConnectedEventData) },
{ EventTypes.IoTHubDeviceDisconnectedEvent, typeof(IotHubDeviceDisconnectedEventData) },

// EventGrid events
{ EventTypes.EventGridSubscriptionValidationEvent, typeof(SubscriptionValidationEventData) },
Expand All @@ -43,6 +45,9 @@ internal static class SystemEventTypeMappings
{ EventTypes.ResourceDeleteSuccessEvent, typeof(ResourceDeleteSuccessData) },
{ EventTypes.ResourceDeleteFailureEvent, typeof(ResourceDeleteFailureData) },
{ EventTypes.ResourceDeleteCancelEvent, typeof(ResourceDeleteCancelData) },
{ EventTypes.ResourceActionSuccessEvent, typeof(ResourceActionSuccessData) },
{ EventTypes.ResourceActionFailureEvent, typeof(ResourceActionFailureData) },
{ EventTypes.ResourceActionCancelEvent, typeof(ResourceActionCancelData) },

// ServiceBus events
{ EventTypes.ServiceBusActiveMessagesAvailableWithNoListenersEvent, typeof(ServiceBusActiveMessagesAvailableWithNoListenersEventData) },
Expand Down
Loading