public void ParseToRaw_ValidRawEvent_ShouldSucceed()
        {
            // Arrange
            const string           eventId       = "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66";
            const string           licensePlate  = "1-TOM-337";
            var                    originalEvent = new NewCarRegistered(eventId, licensePlate);
            var                    rawEventBody  = JsonConvert.SerializeObject(originalEvent.Data, Formatting.Indented);
            var                    rawEvent      = new RawEvent(eventId, originalEvent.EventType, rawEventBody, originalEvent.Subject, originalEvent.DataVersion, originalEvent.EventTime);
            IEnumerable <RawEvent> events        = new List <RawEvent>
            {
                rawEvent
            };

            var serializedRawEvents = JsonConvert.SerializeObject(events);

            // Act
            var eventGridMessage = EventGridParser.Parse <RawEvent>(serializedRawEvents);

            // Assert
            Assert.NotNull(eventGridMessage);
            Assert.NotNull(eventGridMessage.Events);
            Assert.Single(eventGridMessage.Events);
            var eventPayload = eventGridMessage.Events.Single();

            Assert.Equal(eventId, eventPayload.Id);
            Assert.Equal(originalEvent.Subject, eventPayload.Subject);
            Assert.Equal(originalEvent.EventType, eventPayload.EventType);
            Assert.Equal(originalEvent.EventTime, eventPayload.EventTime);
            Assert.Equal(originalEvent.DataVersion, eventPayload.DataVersion);
            Assert.NotNull(eventPayload.Data);
            Assert.Equal(rawEventBody, eventPayload.Data.ToString());
        }
Exemplo n.º 2
0
        public void Parse_ValidNewCarRegisteredEvent_ShouldSucceed()
        {
            // Arrange
            string       eventId      = Guid.NewGuid().ToString();
            const string licensePlate = "1-TOM-337";
            const string subject      = licensePlate;

            var @event   = new NewCarRegistered(eventId, subject, licensePlate);
            var rawEvent = JsonConvert.SerializeObject(new[] { @event });

            // Act
            var eventGridBatch = EventGridParser.Parse <NewCarRegistered>(rawEvent);

            // Assert
            Assert.NotNull(eventGridBatch);
            Assert.NotNull(eventGridBatch.Events);
            var eventPayload = Assert.Single(eventGridBatch.Events);

            Assert.Equal(eventId, eventPayload.Id);
            Assert.Equal(subject, eventPayload.Subject);
            Assert.Equal(@event.EventType, eventPayload.EventType);
            Assert.Equal(@event.EventTime, eventPayload.EventTime);
            Assert.NotNull(eventPayload.Data);
            var eventInformation = eventPayload.GetPayload();

            Assert.NotNull(eventInformation);
            Assert.Equal(licensePlate, eventInformation.LicensePlate);
        }
Exemplo n.º 3
0
        public void Parse_ValidSubscriptionValidationEventWithSessionId_ShouldSucceed()
        {
            // Arrange
            string       rawEvent       = EventSamples.SubscriptionValidationEvent;
            const string eventId        = "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66";
            const string topic          = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
            const string subject        = "Sample.Subject";
            const string eventType      = "Microsoft.EventGrid.SubscriptionValidationEvent";
            const string validationCode = "512d38b6-c7b8-40c8-89fe-f46f9e9622b6";
            var          eventTime      = DateTimeOffset.Parse("2017-08-06T22:09:30.740323Z");
            string       sessionId      = Guid.NewGuid().ToString();

            // Act
            var eventGridBatch = EventGridParser.ParseFromData <SubscriptionValidationEventData>(rawEvent, sessionId);

            // Assert
            Assert.NotNull(eventGridBatch);
            Assert.Equal(sessionId, eventGridBatch.SessionId);
            Assert.NotNull(eventGridBatch.Events);
            Assert.Single(eventGridBatch.Events);
            var eventPayload = eventGridBatch.Events.Single();

            Assert.Equal(eventId, eventPayload.Id);
            Assert.Equal(topic, eventPayload.Topic);
            Assert.Equal(subject, eventPayload.Subject);
            Assert.Equal(eventType, eventPayload.EventType);
            Assert.Equal(eventTime, eventPayload.EventTime);
            Assert.NotNull(eventPayload.Data);
            Assert.Equal(validationCode, eventPayload.GetPayload()?.ValidationCode);
        }
        private async Task ServiceBusMessagePump_PublishServiceBusMessage_MessageSuccessfullyProcessed(Encoding messageEncoding, string connectionStringKey)
        {
            // Arrange
            var operationId   = Guid.NewGuid().ToString();
            var transactionId = Guid.NewGuid().ToString();
            var messageSender = CreateServiceBusSender(connectionStringKey);

            var order        = OrderGenerator.Generate();
            var orderMessage = order.WrapInServiceBusMessage(operationId, transactionId, encoding: messageEncoding);

            // Act
            await messageSender.SendAsync(orderMessage);

            // Assert
            var receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(operationId);

            Assert.NotEmpty(receivedEvent);
            var deserializedEventGridMessage = EventGridParser.Parse <OrderCreatedEvent>(receivedEvent);

            Assert.NotNull(deserializedEventGridMessage);
            var orderCreatedEvent     = Assert.Single(deserializedEventGridMessage.Events);
            var orderCreatedEventData = orderCreatedEvent.GetPayload <OrderCreatedEventData>();

            Assert.NotNull(orderCreatedEventData);
            Assert.NotNull(orderCreatedEventData.CorrelationInfo);
            Assert.Equal(order.Id, orderCreatedEventData.Id);
            Assert.Equal(order.Amount, orderCreatedEventData.Amount);
            Assert.Equal(order.ArticleNumber, orderCreatedEventData.ArticleNumber);
            Assert.Equal(transactionId, orderCreatedEventData.CorrelationInfo.TransactionId);
            Assert.Equal(operationId, orderCreatedEventData.CorrelationInfo.OperationId);
            Assert.NotEmpty(orderCreatedEventData.CorrelationInfo.CycleId);
        }
        public async Task Validate_HasValidEvent_ShouldSucceed()
        {
            // Arrange
            var gridMessage = EventGridParser.ParseFromData <SubscriptionValidationEventData>(EventSamples.SubscriptionValidationEvent);

            // Act
            using (var server = TestServer.Create <InMemoryTestApiStartup>())
            {
                var response = await server.CreateRequest("/events/test")
                               .And(message =>
                {
                    message.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(EventSamples.SubscriptionValidationEvent));
                })
                               .AddHeader("x-api-key", "event-grid")
                               .AddHeader("Aeg-Event-Type", "SubscriptionValidation")
                               .PostAsync();

                // Assert
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                if (response.IsSuccessStatusCode)
                {
                    string json = await response.Content.ReadAsStringAsync();

                    JObject responseObject     = JObject.Parse(json);
                    JToken  validationResponse = responseObject["validationResponse"];
                    Assert.NotNull(validationResponse);

                    object  data      = gridMessage.Events[0]?.Data;
                    JObject eventData = JObject.FromObject(data);
                    Assert.Equal(eventData["validationCode"], validationResponse);
                }
            }
        }
Exemplo n.º 6
0
        public void Parse_BlankEventDataWithValidSessionIdSpecified_ThrowsException(string rawEvent)
        {
            // Arrange
            string sessionId = Guid.NewGuid().ToString();

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.ParseFromData <SubscriptionValidationEventData>(rawEvent, sessionId));
        }
Exemplo n.º 7
0
        public void Parse_BlankEventWithValidSessionIdSpecified_ThrowsException(string rawEvent)
        {
            // Arrange
            string sessionId = Guid.NewGuid().ToString();

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.Parse <NewCarRegistered>(rawEvent, sessionId));
        }
Exemplo n.º 8
0
        public void Parse_ValidEventDataWithBlankSessionIdSpecified_ThrowsException(string sessionId)
        {
            // Arrange
            string rawEvent = EventSamples.SubscriptionValidationEvent;

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.ParseFromData <SubscriptionValidationEventData>(rawEvent, sessionId));
        }
Exemplo n.º 9
0
        public void Parse_ValidEventWithBlankSessionIdSpecified_ThrowsException(string sessionId)
        {
            // Arrange
            string rawEvent = EventSamples.IoTDeviceCreateEvent;

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.Parse <EventGridEvent <IotHubDeviceCreatedEventData> >(rawEvent, sessionId));
        }
        public void Parse_NoEventSpecified_ThrowsException()
        {
            // Arrange
            string rawEvent = null;

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.Parse <SubscriptionValidation>(rawEvent));
        }
        public void Parse_EmptyEventWithValidSessionIdSpecified_ThrowsException()
        {
            // Arrange
            string rawEvent  = string.Empty;
            string sessionId = Guid.NewGuid().ToString();

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.Parse <SubscriptionValidation>(rawEvent, sessionId));
        }
        public void Parse_ValidEventWithoutSessionIdSpecified_ThrowsException()
        {
            // Arrange
            string rawEvent  = EventSamples.SubscriptionValidationEvent;
            string sessionId = null;

            // Act & Assert
            Assert.Throws <ArgumentException>(() => EventGridParser.Parse <SubscriptionValidation>(rawEvent, sessionId));
        }
Exemplo n.º 13
0
        public void Parse_ValidBlobCreatedEvent_ShouldSucceed()
        {
            // Arrange
            const string topic           = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
            const string subject         = "/blobServices/default/containers/event-container/blobs/finnishjpeg";
            const string eventType       = "Microsoft.Storage.BlobCreated";
            const string id              = "5647b67c-b01e-002d-6a47-bc01ac063360";
            const string dataVersion     = "1";
            const string metadataVersion = "1";
            const string api             = "PutBlockList";
            const string clientRequestId = "5c24a322-35c9-4b46-8ef5-245a81af7037";
            const string requestId       = "5647b67c-b01e-002d-6a47-bc01ac000000";
            const string eTag            = "0x8D58A5F0C6722F9";
            const string contentType     = "image/jpeg";
            const int    contentLength   = 29342;
            const string blobType        = "BlockBlob";
            const string url             = "https://sample.blob.core.windows.net/event-container/finnish.jpeg";
            const string sequencer       = "00000000000000000000000000000094000000000017d503";
            const string batchId         = "69cd1576-e430-4aff-8153-570934a1f6e1";
            string       rawEvent        = EventSamples.BlobCreateEvent;
            var          eventTime       = DateTimeOffset.Parse("2018-03-15T10:25:17.7535274Z");

            // Act
            var eventGridMessage = EventGridParser.ParseFromData <StorageBlobCreatedEventData>(rawEvent);

            // Assert
            Assert.NotNull(eventGridMessage);
            Assert.NotNull(eventGridMessage.Events);
            Assert.Single(eventGridMessage.Events);
            var eventGridEvent = eventGridMessage.Events.Single();

            Assert.Equal(topic, eventGridEvent.Topic);
            Assert.Equal(subject, eventGridEvent.Subject);
            Assert.Equal(eventType, eventGridEvent.EventType);
            Assert.Equal(eventTime, eventGridEvent.EventTime);
            Assert.Equal(id, eventGridEvent.Id);
            Assert.Equal(dataVersion, eventGridEvent.DataVersion);
            Assert.Equal(metadataVersion, eventGridEvent.MetadataVersion);
            Assert.NotNull(eventGridEvent.Data);
            StorageBlobCreatedEventData eventPayload = eventGridEvent.GetPayload();

            Assert.NotNull(eventPayload);
            Assert.Equal(api, eventPayload.Api);
            Assert.Equal(clientRequestId, eventPayload.ClientRequestId);
            Assert.Equal(requestId, eventPayload.RequestId);
            Assert.Equal(eTag, eventPayload.ETag);
            Assert.Equal(contentType, eventPayload.ContentType);
            Assert.Equal(contentLength, eventPayload.ContentLength);
            Assert.Equal(blobType, eventPayload.BlobType);
            Assert.Equal(url, eventPayload.Url);
            Assert.Equal(sequencer, eventPayload.Sequencer);
            Assert.NotNull(eventPayload.StorageDiagnostics);
            var storageDiagnostics = Assert.IsType <JObject>(eventPayload.StorageDiagnostics);

            Assert.Equal(batchId, storageDiagnostics["batchId"]);
        }
Exemplo n.º 14
0
        public void Parse_ValidStorageBlobCreatedCloudEvent_ShouldSucceed()
        {
            // Arrange
            const CloudEventsSpecVersion cloudEventsVersion = CloudEventsSpecVersion.V0_1;
            const string eventType = "Microsoft.Storage.BlobCreated",
                         source    = "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}#blobServices/default/containers/{storage-container}/blobs/{new-file}",
                         eventId   = "173d9985-401e-0075-2497-de268c06ff25",
                         eventTime = "2018-04-28T02:18:47.1281675Z";

            const string api             = "PutBlockList",
                         clientRequestId = "6d79dbfb-0e37-4fc4-981f-442c9ca65760",
                         requestId       = "831e1650-001e-001b-66ab-eeb76e000000",
                         etag            = "0x8D4BCC2E4835CD0",
                         contentType     = "application/octet-stream",
                         blobType        = "BlockBlob",
                         url             = "https://oc2d2817345i60006.blob.core.windows.net/oc2d2817345i200097container/oc2d2817345i20002296blob",
                         sequencer       = "00000000000004420000000000028963",
                         batchId         = "b68529f3-68cd-4744-baa4-3c0498ec19f0";

            const long contentLength = 524_288;

            string rawEvent = EventSamples.AzureBlobStorageCreatedCloudEvent;

            // Act
            EventBatch <Event> eventBatch = EventGridParser.Parse(rawEvent);

            // Assert
            Assert.NotNull(eventBatch);
            Assert.NotNull(eventBatch.Events);
            CloudEvent cloudEvent = Assert.Single(eventBatch.Events);

            Assert.NotNull(cloudEvent);
            Assert.Equal(cloudEventsVersion, cloudEvent.SpecVersion);
            Assert.Equal(eventType, cloudEvent.Type);
            Assert.Equal(source, cloudEvent.Source.OriginalString);
            Assert.Equal(eventId, cloudEvent.Id);
            Assert.Equal(eventTime, cloudEvent.Time.GetValueOrDefault().ToString("O"));

            var eventPayload = cloudEvent.GetPayload <StorageBlobCreatedEventData>();

            Assert.NotNull(eventPayload);
            Assert.Equal(api, eventPayload.Api);
            Assert.Equal(clientRequestId, eventPayload.ClientRequestId);
            Assert.Equal(requestId, eventPayload.RequestId);
            Assert.Equal(etag, eventPayload.ETag);
            Assert.Equal(contentType, eventPayload.ContentType);
            Assert.Equal(contentLength, eventPayload.ContentLength);
            Assert.Equal(blobType, eventPayload.BlobType);
            Assert.Equal(url, eventPayload.Url);
            Assert.Equal(sequencer, eventPayload.Sequencer);
            Assert.NotNull(eventPayload.StorageDiagnostics);
            var storageDiagnostics = Assert.IsType <JObject>(eventPayload.StorageDiagnostics);

            Assert.Equal(batchId, storageDiagnostics["batchId"]);
        }
        private RawEvent GetReceivedEvent(string eventId)
        {
            var receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId);
            var rawEvents     = EventGridParser.Parse <RawEvent>(receivedEvent);

            Assert.NotNull(rawEvents);
            Assert.NotNull(rawEvents.Events);
            Assert.Single(rawEvents.Events);
            var firstRawEvent = rawEvents.Events.FirstOrDefault();

            Assert.NotNull(firstRawEvent);

            return(firstRawEvent);
        }
Exemplo n.º 16
0
        public void ParseAsEventGridEvent_ValidStorageBlobCreatedCloudEvent_ShouldFail()
        {
            // Arrange
            string rawEvent = EventSamples.AzureBlobStorageCreatedCloudEvent;

            // Act
            EventBatch <Event> eventBatch = EventGridParser.Parse(rawEvent);

            // Assert
            Assert.NotNull(eventBatch);
            Event @event = Assert.Single(eventBatch.Events);

            Assert.NotNull(@event);
            Assert.Throws <InvalidOperationException>(() => @event.AsEventGridEvent());
        }
        /// <summary>
        /// Simulate the message processing of the message pump using the Service Bus.
        /// </summary>
        public async Task SimulateMessageProcessingAsync()
        {
            if (_serviceBusEventConsumerHost is null)
            {
                throw new InvalidOperationException(
                          "Cannot simulate the message pump because the service is not yet started; please start this service before simulating");
            }

            var operationId   = Guid.NewGuid().ToString();
            var transactionId = Guid.NewGuid().ToString();

            string connectionString = _configuration.GetServiceBusConnectionString(_entity);
            var    serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
            var    messageSender = new MessageSender(serviceBusConnectionStringBuilder);

            try
            {
                Order   order        = OrderGenerator.Generate();
                Message orderMessage = order.WrapInServiceBusMessage(operationId, transactionId);
                await messageSender.SendAsync(orderMessage);

                string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(operationId);
                Assert.NotEmpty(receivedEvent);

                EventGridEventBatch <OrderCreatedEvent> eventBatch = EventGridParser.Parse <OrderCreatedEvent>(receivedEvent);
                Assert.NotNull(eventBatch);
                OrderCreatedEvent orderCreatedEvent = Assert.Single(eventBatch.Events);
                Assert.NotNull(orderCreatedEvent);

                var orderCreatedEventData = orderCreatedEvent.GetPayload <OrderCreatedEventData>();
                Assert.NotNull(orderCreatedEventData);
                Assert.NotNull(orderCreatedEventData.CorrelationInfo);
                Assert.Equal(order.Id, orderCreatedEventData.Id);
                Assert.Equal(order.Amount, orderCreatedEventData.Amount);
                Assert.Equal(order.ArticleNumber, orderCreatedEventData.ArticleNumber);
                Assert.Equal(transactionId, orderCreatedEventData.CorrelationInfo.TransactionId);
                Assert.Equal(operationId, orderCreatedEventData.CorrelationInfo.OperationId);
                Assert.NotEmpty(orderCreatedEventData.CorrelationInfo.CycleId);
            }
            finally
            {
                await messageSender.CloseAsync();
            }
        }
        private static void AssertReceivedEvent(string eventId, string eventType, string eventSubject, string licensePlate, string receivedEvent)
        {
            Assert.NotEqual(string.Empty, receivedEvent);

            EventGridMessage <NewCarRegistered> deserializedEventGridMessage = EventGridParser.Parse <NewCarRegistered>(receivedEvent);

            Assert.NotNull(deserializedEventGridMessage);
            Assert.NotEmpty(deserializedEventGridMessage.SessionId);
            Assert.NotNull(deserializedEventGridMessage.Events);

            NewCarRegistered deserializedEvent = Assert.Single(deserializedEventGridMessage.Events);

            Assert.NotNull(deserializedEvent);
            Assert.Equal(eventId, deserializedEvent.Id);
            Assert.Equal(eventSubject, deserializedEvent.Subject);
            Assert.Equal(eventType, deserializedEvent.EventType);

            Assert.NotNull(deserializedEvent.Data);
            Assert.Equal(licensePlate, deserializedEvent.Data.LicensePlate);
        }
        private async Task <HttpResponseMessage> HandleSubscriptionValidationEvent(HttpActionContext actionContext)
        {
            // Parsing the incoming message to a typed EventGrid message
            var rawRequest = await actionContext.Request.Content.ReadAsStringAsync();

            var gridMessage = EventGridParser.Parse <SubscriptionValidation>(rawRequest);

            if (gridMessage.Events == null || gridMessage.Events.Any() == false)
            {
                throw new Exception(message: "No subscription events were found");
            }

            if (gridMessage.Events.Count > 1)
            {
                throw new Exception(message: "More than one subscription event was found");
            }

            var subscriptionEvent = gridMessage.Events.Single();

            var validationCode = subscriptionEvent.Data?.ValidationCode;

            if (validationCode == null)
            {
                return(null);
            }

            // This is a subscription validation message, echo the validationCode
            var responseMessage = actionContext.Request.CreateResponse(
                HttpStatusCode.OK,
                new { validationResponse = validationCode },
                new JsonMediaTypeFormatter()
                );

            //TODO : add logging
            //Log.Logger.Information("Echoing back the validation code {validationCode}", validationCode.ToString());

            return(responseMessage);
        }
Exemplo n.º 20
0
        private static void AssertReceivedNewCarRegisteredEvent(string eventId, string eventType, string eventSubject, string licensePlate, string receivedEvent)
        {
            Assert.NotEqual(String.Empty, receivedEvent);

            EventBatch <NewCarRegistered> deserializedEventGridMessage = EventGridParser.Parse <NewCarRegistered>(receivedEvent);

            Assert.NotNull(deserializedEventGridMessage);
            Assert.NotEmpty(deserializedEventGridMessage.SessionId);
            Assert.NotNull(deserializedEventGridMessage.Events);

            NewCarRegistered deserializedEvent = Assert.Single(deserializedEventGridMessage.Events);

            Assert.NotNull(deserializedEvent);
            Assert.Equal(eventId, deserializedEvent.Id);
            Assert.Equal(eventSubject, deserializedEvent.Subject);
            Assert.Equal(eventType, deserializedEvent.EventType);

            Assert.NotNull(deserializedEvent.Data);
            CarEventData eventData = deserializedEvent.GetPayload();

            Assert.NotNull(eventData);
            Assert.Equal(JsonConvert.DeserializeObject <CarEventData>(deserializedEvent.Data.ToString()), eventData);
            Assert.Equal(licensePlate, eventData.LicensePlate);
        }
        public void Parse_ValidDeviceCreatedEvent_ShouldSucceed()
        {
            // Arrange
            string       rawEvent                  = EventSamples.IoTDeviceCreateEvent;
            const string id                        = "38a23a83-f9c2-493f-e6fb-4b57c7c43d28";
            const string topic                     = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
            const string subject                   = "devices/grid-test-01";
            const string eventType                 = "Microsoft.Devices.DeviceCreated";
            const string eventTime                 = "2018-03-16T05:47:28.1359543Z";
            const string stamp                     = "03/16/2018 05:47:28";
            const string dataVersion               = "1";
            const string metadataVersion           = "1";
            const string hubName                   = "savanh-eventgrid-iothub";
            const string deviceId                  = "grid-test-01";
            const string etag                      = "AAAAAAAAAAE=";
            const string status                    = "enabled";
            const string connectionState           = "Disconnected";
            const int    cloudToDeviceMessageCount = 0;
            const string authenticationType        = "sas";
            const string primaryThumbprint         = "xyz";
            const string secondaryThumbprint       = "abc";
            const int    twinVersion               = 2;
            const int    twinPropertyVersion       = 1;

            // Act
            var eventGridMessage = EventGridParser.ParseFromData <IotHubDeviceCreatedEventData>(rawEvent);

            // Assert
            Assert.NotNull(eventGridMessage);
            Assert.NotNull(eventGridMessage.Events);
            Assert.Single(eventGridMessage.Events);
            var eventGridEvent = eventGridMessage.Events.Single();

            Assert.Equal(id, eventGridEvent.Id);
            Assert.Equal(topic, eventGridEvent.Topic);
            Assert.Equal(subject, eventGridEvent.Subject);
            Assert.Equal(eventType, eventGridEvent.EventType);
            Assert.Equal(DateTimeOffset.Parse(eventTime), eventGridEvent.EventTime);
            Assert.Equal(dataVersion, eventGridEvent.DataVersion);
            Assert.Equal(metadataVersion, eventGridEvent.MetadataVersion);
            var eventGridEventData = eventGridEvent.Data;

            Assert.NotNull(eventGridEventData);
            IotHubDeviceCreatedEventData eventPayload = eventGridEvent.GetPayload();

            Assert.NotNull(eventPayload);
            Assert.Equal(hubName, eventPayload.HubName);
            Assert.Equal(deviceId, eventPayload.DeviceId);
            var twin = eventPayload.Twin;

            Assert.NotNull(twin);
            Assert.Equal(deviceId, twin.DeviceId);
            Assert.Equal(etag, twin.Etag);
            Assert.Equal(status, twin.Status);
            Assert.Equal(stamp, twin.StatusUpdateTime);
            Assert.Equal(connectionState, twin.ConnectionState);
            Assert.Equal(stamp, twin.LastActivityTime);
            Assert.Equal(cloudToDeviceMessageCount, twin.CloudToDeviceMessageCount);
            Assert.Equal(authenticationType, twin.AuthenticationType);
            Assert.NotNull(twin.X509Thumbprint);
            Assert.Equal(primaryThumbprint, twin.X509Thumbprint.PrimaryThumbprint);
            Assert.Equal(secondaryThumbprint, twin.X509Thumbprint.SecondaryThumbprint);
            Assert.Equal(twinVersion, twin.Version);
            Assert.NotNull(twin.Properties);
            Assert.NotNull(twin.Properties.Desired);
            Assert.NotNull(twin.Properties.Desired.Metadata);
            Assert.Equal(twinPropertyVersion, twin.Properties.Desired.Version);
            Assert.NotNull(twin.Properties.Desired.Metadata.LastUpdated);
            var rawDesiredLastUpdated = twin.Properties.Desired.Metadata.LastUpdated;

            Assert.NotNull(rawDesiredLastUpdated);
            Assert.Equal(stamp, rawDesiredLastUpdated);
            Assert.NotNull(twin.Properties.Reported);
            Assert.NotNull(twin.Properties.Reported.Metadata);
            Assert.Equal(twinPropertyVersion, twin.Properties.Reported.Version);
            Assert.NotNull(twin.Properties.Reported.Metadata.LastUpdated);
            var rawReportedLastUpdated = twin.Properties.Reported.Metadata.LastUpdated;

            Assert.NotNull(rawReportedLastUpdated);
            Assert.Equal(stamp, rawReportedLastUpdated);
        }
Exemplo n.º 22
0
 public void Parse_WithNullRawJsonEventBody_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => EventGridParser.Parse(rawJsonBody: null));
 }
Exemplo n.º 23
0
 public void Parse_BlankEventSpecified_ThrowsException(string rawEvent)
 {
     // Act & Assert
     Assert.Throws <ArgumentException>(() => EventGridParser.Parse <NewCarRegistered>(rawEvent));
 }
Exemplo n.º 24
0
 public void Parse_BlankEventDataSpecified_ThrowsException(string rawEvent)
 {
     // Act & Assert
     Assert.Throws <ArgumentException>(() => EventGridParser.ParseFromData <SubscriptionValidationEventData>(rawEvent));
 }
Exemplo n.º 25
0
 public void Parse_WithNullSessionId_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => EventGridParser.Parse(rawJsonBody: "not empty", sessionId: null));
 }
Exemplo n.º 26
0
 public void Parse_WithSessionIdAndNullRawJsonEventBody_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => EventGridParser.Parse(rawJsonBody: null, sessionId: "not empty"));
 }