public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable, DependencyAction = Models.DependencyAction.Satisfy }; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, PreProcessingError = terminateExitOption, FileUploadError = disableExitOption } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. // These need to be compared as strings because they are different types but we are interested in the values being the same. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.Default.DependencyAction); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.FileUploadError.DependencyAction); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.UserIdentity = new UserIdentity("abc")); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }
public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable }; BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = BatchClient.Open(credentials)) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, SchedulingError = terminateExitOption, } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.RunElevated = true); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }