Esempio n. 1
0
        public async Task UnboundJobCommitAndRefreshWorks()
        {
            using (BatchClient batchClient = ClientUnitTestCommon.CreateDummyClient())
            {
                const string id          = "Bar";
                const string displayName = "Baz";
                var          prepTask    = new Protocol.Models.JobPreparationTask(id);

                Protocol.Models.CloudJob protoJob = new Protocol.Models.CloudJob(
                    id: id,
                    displayName: displayName,
                    jobPreparationTask: prepTask);

                CloudJob job = batchClient.JobOperations.CreateJob(id, new PoolInformation()
                {
                    PoolId = "Foo"
                });

                await job.CommitAsync(additionalBehaviors : InterceptorFactory.CreateAddJobRequestInterceptor());

                await job.RefreshAsync(additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                Assert.Equal(id, job.Id);
                Assert.Equal(displayName, job.DisplayName);
                Assert.Null(job.PoolInformation);
                Assert.NotNull(job.JobPreparationTask);
                Assert.Equal(prepTask.Id, job.JobPreparationTask.Id);
            }
        }
        public void CloudJob_WhenSendingToTheServer_HasExpectedUnboundProperties()
        {
            const string jobId              = "id-123";
            const string displayName        = "DisplayNameFoo";
            MetadataItem metadataItem       = new MetadataItem("foo", "bar");
            const int    priority           = 0;
            const string applicationId      = "testApp";
            const string applicationVersion = "beta";

            using BatchClient client = ClientUnitTestCommon.CreateDummyClient();
            CloudJob cloudJob = client.JobOperations.CreateJob(jobId, new PoolInformation {
                AutoPoolSpecification = new AutoPoolSpecification {
                    KeepAlive = false
                }
            });

            cloudJob.Id          = jobId;
            cloudJob.DisplayName = displayName;
            cloudJob.Metadata    = new List <MetadataItem> {
                metadataItem
            };
            cloudJob.Priority       = priority;
            cloudJob.JobManagerTask = new JobManagerTask
            {
                ApplicationPackageReferences = new List <ApplicationPackageReference>
                {
                    new ApplicationPackageReference {
                        ApplicationId = applicationId, Version = applicationVersion
                    }
                },
                AuthenticationTokenSettings = new AuthenticationTokenSettings()
                {
                    Access = AccessScope.Job
                }
            };

            cloudJob.OnAllTasksComplete = OnAllTasksComplete.NoAction;
            cloudJob.OnTaskFailure      = OnTaskFailure.NoAction;


            Assert.Throws <InvalidOperationException>(() => cloudJob.Url); // cannot read a Url since it's unbound at this point.
            Assert.Equal(cloudJob.Id, jobId);                              // can set an unbound object
            Assert.Equal(cloudJob.Metadata.First().Name, metadataItem.Name);
            Assert.Equal(cloudJob.Metadata.First().Value, metadataItem.Value);
            Assert.Equal(OnAllTasksComplete.NoAction, cloudJob.OnAllTasksComplete);
            Assert.Equal(OnTaskFailure.NoAction, cloudJob.OnTaskFailure);

            cloudJob.Commit(additionalBehaviors: InterceptorFactory.CreateAddJobRequestInterceptor());

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

            AuthenticationTokenSettings authenticationTokenSettings = new AuthenticationTokenSettings {
                Access = AccessScope.Job
            };

            Assert.Throws <InvalidOperationException>(() => { cloudJob.JobManagerTask.AuthenticationTokenSettings = authenticationTokenSettings; });
        }