Example #1
0
        public void TestPatchJobSchedule_UnchangedPropertiesAreIgnored()
        {
            const string jobScheduleId = "Foo";

            var protoJobSchedule = new Protocol.Models.CloudJobSchedule(
                id: jobScheduleId,
                schedule: new Protocol.Models.Schedule(startWindow: TimeSpan.FromSeconds(10)),
                metadata: new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem()
            },
                jobSpecification: new Protocol.Models.JobSpecification(
                    poolInfo: new Protocol.Models.PoolInformation(poolId: "Test")));

            Action <CloudJobSchedule> modificationFunction = jobSchedule =>
            {
                //Do nothing
            };

            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.JobSpecification);
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.Schedule);
            };

            CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction);
        }
Example #2
0
        public void TestPatchJobSchedule_UnchangedChildEntityWithNonEmptyListIsIgnored()
        {
            const string jobScheduleId = "Foo";

            var protoJobSchedule = new Protocol.Models.CloudJobSchedule(
                id: jobScheduleId,
                jobSpecification: new Protocol.Models.JobSpecification(
                    poolInfo: new Protocol.Models.PoolInformation(
                        poolId: "Test",
                        autoPoolSpecification: new Protocol.Models.AutoPoolSpecification(
                            Protocol.Models.PoolLifetimeOption.Job,
                            pool: new Protocol.Models.PoolSpecification(
                                "small",
                                applicationPackageReferences: new List <Protocol.Models.ApplicationPackageReference>()
            {
                new Protocol.Models.ApplicationPackageReference("a")
            })))));

            Action <CloudJobSchedule> modificationFunction = jobSchedule =>
            {
                //Do nothing
            };

            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.JobSpecification);
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.Schedule);
            };

            CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction);
        }
Example #3
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);
            }
        }
Example #4
0
        public void TestPatchJobSchedule_ThrowsOnNullPropertySet()
        {
            const string jobScheduleId    = "Foo";
            var          protoJobSchedule = new Protocol.Models.CloudJobSchedule(id: jobScheduleId);

            Action <CloudJobSchedule> modificationFunction = jobSchedule => jobSchedule.JobSpecification = null;
            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.False(true, "Should have failed PATCH validation before issuing the request");
            };

            //This should throw because we set a property to null which is not supported by PATCH
            Assert.Throws <InvalidOperationException>(() => CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction));
        }
        public void TestRandomBoundCloudJobScheduleProperties()
        {
            using BatchClient client = ClientUnitTestCommon.CreateDummyClient();
            for (int i = 0; i < TestRunCount; i++)
            {
                Protocol.Models.CloudJobSchedule jobScheduleModel =
                    this.customizedObjectFactory.GenerateNew <Protocol.Models.CloudJobSchedule>();

                CloudJobSchedule boundJobSchedule = new CloudJobSchedule(client, jobScheduleModel, client.CustomBehaviors);

                ObjectComparer.CheckEqualityResult result = this.objectComparer.CheckEquality(boundJobSchedule, jobScheduleModel);
                Assert.True(result.Equal, result.Message);
            }
        }
Example #6
0
        public void TestPatchJobSchedule_ChangedComplexParameterIsSerialized()
        {
            const string jobScheduleId  = "Foo";
            TimeSpan     newStartWindow = TimeSpan.FromSeconds(20);

            var protoJobSchedule = new Protocol.Models.CloudJobSchedule(
                id: jobScheduleId,
                schedule: new Protocol.Models.Schedule(startWindow: TimeSpan.FromSeconds(10)));

            Action <CloudJobSchedule> modificationFunction = jobSchedule => jobSchedule.Schedule.StartWindow = newStartWindow;
            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.JobSpecification);
                Assert.Null(patchParameters.Metadata);

                Assert.NotNull(patchParameters.Schedule);
                Assert.Equal(newStartWindow, patchParameters.Schedule.StartWindow);
            };

            CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction);
        }
Example #7
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);
            }
        }
Example #8
0
        public void TestPatchJobSchedule_NewComplexParameterIsSerialized()
        {
            const string jobScheduleId = "Foo";
            const int    newPriority   = 5;

            var protoJobSchedule = new Protocol.Models.CloudJobSchedule(id: jobScheduleId);

            Action <CloudJobSchedule> modificationFunction = jobSchedule => jobSchedule.JobSpecification = new JobSpecification()
            {
                Priority = newPriority
            };
            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.Schedule);

                Assert.NotNull(patchParameters.JobSpecification);
                Assert.Equal(newPriority, patchParameters.JobSpecification.Priority);
            };

            CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction);
        }
Example #9
0
        public void TestPatchJobSchedule_ChangedCollectionParameterIsSerialized()
        {
            const string jobScheduleId = "Foo";

            var protoJobSchedule = new Protocol.Models.CloudJobSchedule(
                id: jobScheduleId,
                metadata: new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem("Foo", "Bar")
            });

            Action <CloudJobSchedule> modificationFunction = jobSchedule => jobSchedule.Metadata.Add(new MetadataItem("Baz", "Qux"));
            Action <Protocol.Models.JobSchedulePatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.JobSpecification);
                Assert.Null(patchParameters.Schedule);

                Assert.NotNull(patchParameters.Metadata);
                Assert.Equal(2, patchParameters.Metadata.Count);
            };

            CommonPatchJobScheduleTest(protoJobSchedule, modificationFunction, assertAction);
        }
Example #10
0
 public static IEnumerable <Protocol.RequestInterceptor> CreateGetJobScheduleRequestInterceptor(Protocol.Models.CloudJobSchedule jobScheduleToReturn)
 {
     return(CreateGetRequestInterceptor <Protocol.Models.JobScheduleGetOptions, Protocol.Models.CloudJobSchedule, Protocol.Models.JobScheduleGetHeaders>(jobScheduleToReturn));
 }