Ejemplo n.º 1
0
        public async Task UnboundJobScheduleCommitAndRefreshWorks()
        {
            using (BatchClient batchClient = ClientUnitTestCommon.CreateDummyClient())
            {
                const string id               = "Bar";
                const string displayName      = "Baz";
                var          jobSpecification = new Protocol.Models.JobSpecification()
                {
                    DisplayName = displayName
                };
                var protoJobSchedule = new Protocol.Models.CloudJobSchedule(
                    id: id,
                    displayName: displayName,
                    jobSpecification: jobSpecification);

                CloudJobSchedule jobSchedule = batchClient.JobScheduleOperations.CreateJobSchedule(id, new Schedule(), null);

                await jobSchedule.CommitAsync(additionalBehaviors : InterceptorFactory.CreateAddJobScheduleRequestInterceptor());

                await jobSchedule.RefreshAsync(additionalBehaviors : InterceptorFactory.CreateGetJobScheduleRequestInterceptor(protoJobSchedule));

                Assert.Equal(id, jobSchedule.Id);
                Assert.Equal(displayName, jobSchedule.DisplayName);
                Assert.Null(jobSchedule.Schedule);
                Assert.NotNull(jobSchedule.JobSpecification);
                Assert.Equal(jobSpecification.DisplayName, jobSchedule.JobSpecification.DisplayName);
            }
        }
        public void CloudJobSchedule_WhenReturnedFromServer_HasExpectedBoundProperties()
        {
            const string jobScheduleId = "id-123";
            const string displayName   = "DisplayNameFoo";
            MetadataItem metadataItem  = new MetadataItem("foo", "bar");

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                DateTime creationTime = DateTime.Now;

                var cloudJobSchedule = new Models.CloudJobSchedule
                {
                    Id          = jobScheduleId,
                    DisplayName = displayName,
                    Metadata    = new[]
                    {
                        new Models.MetadataItem {
                            Name = metadataItem.Name, Value = metadataItem.Value
                        }
                    },
                    CreationTime     = creationTime,
                    JobSpecification = new Models.JobSpecification
                    {
                        OnAllTasksComplete = Models.OnAllTasksComplete.TerminateJob,
                        OnTaskFailure      = Models.OnTaskFailure.PerformExitOptionsJobAction
                    }
                };

                CloudJobSchedule boundJobSchedule = client.JobScheduleOperations.GetJobSchedule(
                    jobScheduleId,
                    additionalBehaviors: InterceptorFactory.CreateGetJobScheduleRequestInterceptor(cloudJobSchedule));

                Assert.Equal(jobScheduleId, boundJobSchedule.Id); // reading is allowed from a jobSchedule that is returned from the server.
                Assert.Equal(creationTime, boundJobSchedule.CreationTime);
                Assert.Equal(displayName, boundJobSchedule.DisplayName);
                Assert.Equal(OnAllTasksComplete.TerminateJob, boundJobSchedule.JobSpecification.OnAllTasksComplete);
                Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, boundJobSchedule.JobSpecification.OnTaskFailure);

                Assert.Throws <InvalidOperationException>(() => boundJobSchedule.DisplayName = "cannot-change-display-name");
                Assert.Throws <InvalidOperationException>(() => boundJobSchedule.Id          = "cannot-change-id");

                boundJobSchedule.JobSpecification.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;
                boundJobSchedule.JobSpecification.OnTaskFailure      = OnTaskFailure.NoAction;

                Assert.Equal(OnAllTasksComplete.TerminateJob, boundJobSchedule.JobSpecification.OnAllTasksComplete);
                Assert.Equal(OnTaskFailure.NoAction, boundJobSchedule.JobSpecification.OnTaskFailure);
            }
        }
        public void CloudJobSchedule_WhenSendingToTheServer_HasExpectedUnboundProperties()
        {
            const string jobScheduleId = "id-123";
            const string displayName   = "DisplayNameFoo";
            MetadataItem metadataItem  = new MetadataItem("foo", "bar");

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                CloudJobSchedule jobSchedule = client.JobScheduleOperations.CreateJobSchedule();
                jobSchedule.Id          = jobScheduleId;
                jobSchedule.DisplayName = displayName;
                jobSchedule.Metadata    = new List <MetadataItem> {
                    metadataItem
                };
                jobSchedule.JobSpecification = new JobSpecification
                {
                    OnAllTasksComplete = OnAllTasksComplete.TerminateJob,
                    OnTaskFailure      = OnTaskFailure.PerformExitOptionsJobAction
                };

                Assert.Equal(jobSchedule.Id, jobScheduleId); // can set an unbound object
                Assert.Equal(jobSchedule.Metadata.First().Name, metadataItem.Name);
                Assert.Equal(jobSchedule.Metadata.First().Value, metadataItem.Value);
                Assert.Equal(OnAllTasksComplete.TerminateJob, jobSchedule.JobSpecification.OnAllTasksComplete);
                Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, jobSchedule.JobSpecification.OnTaskFailure);

                jobSchedule.Commit(additionalBehaviors: InterceptorFactory.CreateAddJobScheduleRequestInterceptor());

                // writing isn't allowed for a jobSchedule that is in an read only state.
                Assert.Throws <InvalidOperationException>(() => jobSchedule.Id          = "cannot-change-id");
                Assert.Throws <InvalidOperationException>(() => jobSchedule.DisplayName = "cannot-change-display-name");

                //Can still read though
                Assert.Equal(jobScheduleId, jobSchedule.Id);
                Assert.Equal(displayName, jobSchedule.DisplayName);

                jobSchedule.Refresh(additionalBehaviors:
                                    InterceptorFactory.CreateGetJobScheduleRequestInterceptor(
                                        new Models.CloudJobSchedule()
                {
                    JobSpecification = new Models.JobSpecification()
                }));

                jobSchedule.JobSpecification.OnAllTasksComplete = OnAllTasksComplete.NoAction;
                jobSchedule.JobSpecification.OnTaskFailure      = OnTaskFailure.NoAction;
            }
        }
Ejemplo n.º 4
0
        private static void CommonPatchJobScheduleTest(
            Protocol.Models.CloudJobSchedule startEntity,
            Action <CloudJobSchedule> modificationFunction,
            Action <Protocol.Models.JobSchedulePatchParameter> assertAction)
        {
            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                CloudJobSchedule jobSchedule = client.JobScheduleOperations.GetJobSchedule(
                    string.Empty,
                    additionalBehaviors: InterceptorFactory.CreateGetJobScheduleRequestInterceptor(startEntity));

                modificationFunction(jobSchedule);

                var patchInterceptor = ShimPatchJobSchedule(assertAction);
                jobSchedule.CommitChanges(additionalBehaviors: new[] { patchInterceptor });

                //Ensure that the job is in readable but unmodifiable state
                var id = jobSchedule.Id;

                Assert.Throws <InvalidOperationException>(() => jobSchedule.Metadata = null);
            }
        }
        public void CloudJobSchedule_WhenReturnedFromServer_HasExpectedBoundProperties()
        {
            const string jobScheduleId = "id-123";
            const string displayName   = "DisplayNameFoo";
            MetadataItem metadataItem  = new MetadataItem("foo", "bar");

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

            using (BatchClient client = BatchClient.Open(credentials))
            {
                DateTime creationTime = DateTime.Now;

                var cloudJobSchedule = new Models.CloudJobSchedule
                {
                    Id          = jobScheduleId,
                    DisplayName = displayName,
                    Metadata    = new[]
                    {
                        new Models.MetadataItem {
                            Name = metadataItem.Name, Value = metadataItem.Value
                        }
                    },
                    CreationTime = creationTime
                };

                CloudJobSchedule boundJobSchedule = client.JobScheduleOperations.GetJobSchedule(
                    jobScheduleId,
                    additionalBehaviors: InterceptorFactory.CreateGetJobScheduleRequestInterceptor(cloudJobSchedule));

                Assert.Equal(jobScheduleId, boundJobSchedule.Id); // reading is allowed from a jobSchedule that is returned from the server.
                Assert.Equal(creationTime, boundJobSchedule.CreationTime);
                Assert.Equal(displayName, boundJobSchedule.DisplayName);

                Assert.Throws <InvalidOperationException>(() => boundJobSchedule.DisplayName = "cannot-change-display-name");
                Assert.Throws <InvalidOperationException>(() => boundJobSchedule.Id          = "cannot-change-id");
            }
        }