Microsoft.WindowsAzure.MediaServices.Client.Tests.JobTests.ShouldReceiveNotificationsForCompeletedJob C# (CSharp) Method

ShouldReceiveNotificationsForCompeletedJob() private method

private ShouldReceiveNotificationsForCompeletedJob ( ) : void
return void
        public void ShouldReceiveNotificationsForCompeletedJob()
        {
            string endPointAddress = Guid.NewGuid().ToString();
            CloudQueueClient client = CloudStorageAccount.Parse(WindowsAzureMediaServicesTestConfiguration.ClientStorageConnectionString).CreateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(endPointAddress);
            queue.CreateIfNotExists();
            string endPointName = Guid.NewGuid().ToString();
            INotificationEndPoint notificationEndPoint = _mediaContext.NotificationEndPoints.Create(endPointName, NotificationEndPointType.AzureQueue, endPointAddress);
            Assert.IsNotNull(notificationEndPoint);

            string configuration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.DefaultMp4ToSmoothConfig);
            IAsset asset = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpPackagerName);

            IJob job = _mediaContext.Jobs.Create("CreateJobWithNotificationSubscription");
            ITask task = job.Tasks.AddNew("Task1", mediaProcessor, configuration, TaskOptions.None);
            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Output", AssetCreationOptions.None);

            job.JobNotificationSubscriptions.AddNew(NotificationJobState.All, notificationEndPoint);

            job.Submit();

            Assert.IsTrue(job.JobNotificationSubscriptions.Count > 0);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
            Thread.Sleep((int)TimeSpan.FromMinutes(5).TotalMilliseconds);

            Assert.IsNotNull(queue);
            Assert.IsTrue(queue.Exists());
            IEnumerable<CloudQueueMessage> messages = queue.GetMessages(10);
            Assert.IsTrue(messages.Any());
            Assert.AreEqual(4, messages.Count(), "Expecting to have 4 notifications messages");

            IJob lastJob = _mediaContext.Jobs.Where(j => j.Id == job.Id).FirstOrDefault();
            Assert.IsNotNull(lastJob);
            Assert.IsTrue(lastJob.JobNotificationSubscriptions.Count > 0);
            IJobNotificationSubscription lastJobNotificationSubscription = lastJob.JobNotificationSubscriptions.Where(n => n.NotificationEndPoint.Id == notificationEndPoint.Id).FirstOrDefault();
            Assert.IsNotNull(lastJobNotificationSubscription);
            INotificationEndPoint lastNotificationEndPoint = lastJobNotificationSubscription.NotificationEndPoint;
            Assert.IsNotNull(lastNotificationEndPoint);
            Assert.AreEqual(endPointName, lastNotificationEndPoint.Name);
            Assert.AreEqual(endPointAddress, lastNotificationEndPoint.EndPointAddress);
        }
JobTests