Example #1
0
        public async Task UnboundPoolCommitAndRefreshWorks()
        {
            using (BatchClient batchClient = ClientUnitTestCommon.CreateDummyClient())
            {
                const string id          = "Bar";
                const string displayName = "Baz";
                var          startTask   = new Protocol.Models.StartTask("cmd /c dir");
                var          protoPool   = new Protocol.Models.CloudPool(
                    id: id,
                    displayName: displayName,
                    startTask: startTask);

                CloudPool pool = batchClient.PoolOperations.CreatePool(id, "Woo", new CloudServiceConfiguration("4"));

                await pool.CommitAsync(additionalBehaviors : InterceptorFactory.CreateAddPoolRequestInterceptor());

                await pool.RefreshAsync(additionalBehaviors : InterceptorFactory.CreateGetPoolRequestInterceptor(protoPool));

                Assert.Equal(id, pool.Id);
                Assert.Equal(displayName, pool.DisplayName);
                Assert.Null(pool.CloudServiceConfiguration);
                Assert.NotNull(pool.StartTask);
                Assert.Equal(startTask.CommandLine, pool.StartTask.CommandLine);
            }
        }
Example #2
0
        private static void CommonPatchPoolTest(
            Protocol.Models.CloudPool startEntity,
            Action <CloudPool> modificationFunction,
            Action <Protocol.Models.PoolPatchParameter> assertAction)
        {
            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                CloudPool pool = client.PoolOperations.GetPool(
                    string.Empty,
                    additionalBehaviors: InterceptorFactory.CreateGetPoolRequestInterceptor(startEntity));

                modificationFunction(pool);

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

                //Ensure that the job is in readable but unmodifiable state
                var id = pool.Id;
                Assert.Throws <InvalidOperationException>(() => pool.Metadata = null);
            }
        }
        public void Pool_WhenReturnedFromServer_HasExpectedBoundProperties()
        {
            const string cloudPoolId          = "id-123";
            const string cloudPoolDisplayName = "pool-display-name-test";
            MetadataItem metadataItem         = new MetadataItem("foo", "bar");

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Models.CloudPool protoPool = new Models.CloudPool(id: cloudPoolId, displayName: cloudPoolDisplayName, metadata: new[]
                {
                    new Models.MetadataItem
                    {
                        Name  = metadataItem.Name,
                        Value = metadataItem.Value
                    }
                });

                CloudPool boundPool = client.PoolOperations.GetPool(string.Empty, additionalBehaviors: InterceptorFactory.CreateGetPoolRequestInterceptor(protoPool));

                // Cannot change these bound properties.
                Assert.Throws <InvalidOperationException>(() => boundPool.DisplayName = "cannot-change-display-name");
                Assert.Throws <InvalidOperationException>(() => boundPool.Id          = "cannot-change-id");
                Assert.Throws <InvalidOperationException>(() => boundPool.TargetDedicatedComputeNodes = 1);
                Assert.Throws <InvalidOperationException>(() => boundPool.VirtualMachineSize          = "cannot-change-1");


                // Swap the value with the name and the name with the value.
                boundPool.Metadata = new[] { new MetadataItem(metadataItem.Value, metadataItem.Name) };
                Assert.Equal(metadataItem.Name, boundPool.Metadata.First().Value);
                Assert.Equal(metadataItem.Value, boundPool.Metadata.First().Name);
            }
        }