Esempio n. 1
0
        public async void HandleAsync_ShouldReturnTrue_WhenTaskStateChangePayloadIsValid(string oldState, string newState, string expectedEventType)
        {
            var mediaV2ServiceMock = Mock.Of <IMediaServicesV2EncodeService>();

            Mock.Get(mediaV2ServiceMock)
            .Setup(x => x.GetOperationContextForJobAsync(It.IsAny <string>()))
            .ReturnsAsync(new JObject());
            var egPublisherMock = Mock.Of <IEventGridPublisher>();

            dynamic opcontext = new JObject();

            opcontext.TestKey = "TestValue";

            Mock.Get(egPublisherMock)
            .Setup(x => x.PublishEventToTopic(It.IsAny <EventGridEvent>()))
            .ReturnsAsync(true);

            var handler = new MediaServicesV2CallbackHandler(log, mediaV2ServiceMock, egPublisherMock);

            var notificationMessage = new MediaServicesV2NotificationMessage()
            {
                ETag           = "random",
                EventType      = MediaServicesV2NotificationEventType.TaskStateChange,
                MessageVersion = "1.1",
                TimeStamp      = DateTime.UtcNow,
                Properties     = new Dictionary <string, string>()
                {
                    { "jobId", "nb:jid:UUID:91ab2b3a-0d00-a812-94e1-f1ea63c713e1" },
                    { "taskId", "nb:tid:UUID:4c1e6189-cb33-45ca-901a-46dcd3cc5f40" },
                    { "newState", newState },
                    { "oldState", oldState },
                    { "accountName", "justatest" },
                    { "accountId", "00000000-0000-0000-0000-000000000000" },
                    { "notificationEndPointId", "nb:nepid:UUID:738eb6b5-a18d-4b7f-961d-bc33e844da13" }
                }
            };

            var actual = await handler.HandleAsync(GetEventFromNotificationMessage(notificationMessage)).ConfigureAwait(false);

            actual.ShouldBeTrue();

            Mock.Get(egPublisherMock)
            .Verify(x => x.PublishEventToTopic(It.Is <EventGridEvent>(x => x.EventType == expectedEventType)),
                    Times.Once,
                    "publish should be called with the correct eventtype");
        }
Esempio n. 2
0
        public async void HandleAsync_ShouldPublishFailureEvent_WhenPayloadIsNotFormatedCorrectly()
        {
            var mediaV2ServiceMock = Mock.Of <IMediaServicesV2EncodeService>();
            var egPublisherMock    = Mock.Of <IEventGridPublisher>();

            dynamic opcontext = new JObject();

            opcontext.TestKey = "TestValue";

            Mock.Get(egPublisherMock)
            .Setup(x => x.PublishEventToTopic(It.IsAny <EventGridEvent>()))
            .ReturnsAsync(true);

            var handler = new MediaServicesV2CallbackHandler(log, mediaV2ServiceMock, egPublisherMock);

            var notificationMessage = new MediaServicesV2NotificationMessage()
            {
                ETag           = "random",
                EventType      = MediaServicesV2NotificationEventType.TaskStateChange,
                MessageVersion = "1.1",
                TimeStamp      = DateTime.UtcNow,
                Properties     = new Dictionary <string, string>()
                {
                    { "jobId", "nb:jid:UUID:91ab2b3a-0d00-a812-94e1-f1ea63c713e1" },
                    { "taskId", "nb:tid:UUID:4c1e6189-cb33-45ca-901a-46dcd3cc5f40" },
                    { "noState", "Wrong" },
                    { "oldState", "OldState" },
                    { "accountName", "justatest" },
                    { "accountId", "00000000-0000-0000-0000-000000000000" },
                    { "notificationEndPointId", "nb:nepid:UUID:738eb6b5-a18d-4b7f-961d-bc33e844da13" }
                }
            };

            await handler.HandleAsync(GetEventFromNotificationMessage(notificationMessage)).ConfigureAwait(false);

            Mock.Get(egPublisherMock)
            .Verify(x => x.PublishEventToTopic(It.Is <EventGridEvent>(e => e.EventType == CustomEventTypes.ResponseFailure)));
        }