Ejemplo n.º 1
0
        public void TestPatchPool_UnchangedChildEntityWithNonemptyListIsIgnored()
        {
            const string poolId = "Foo";

            var protoPool = new Protocol.Models.CloudPool(
                id: poolId,
                startTask: new Protocol.Models.StartTask(
                    commandLine: "Foo",
                    resourceFiles: new List <Protocol.Models.ResourceFile>()
            {
                new Protocol.Models.ResourceFile("sas", "filepath")
            }));

            Action <CloudPool> modificationFunction = pool =>
            {
                //Do nothing
            };

            Action <Protocol.Models.PoolPatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.ApplicationPackageReferences);
                Assert.Null(patchParameters.CertificateReferences);
                Assert.Null(patchParameters.StartTask);
            };

            CommonPatchPoolTest(protoPool, modificationFunction, assertAction);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public void TestPatchPool_UnchangedEntitiesAreIgnored()
        {
            const string poolId = "Foo";

            var protoPool = new Protocol.Models.CloudPool(
                id: poolId,
                startTask: new Protocol.Models.StartTask(commandLine: "Foo"),
                metadata: new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem()
            });

            Action <CloudPool> modificationFunction = pool =>
            {
                //Do nothing
            };

            Action <Protocol.Models.PoolPatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.ApplicationPackageReferences);
                Assert.Null(patchParameters.CertificateReferences);
                Assert.Null(patchParameters.StartTask);
            };

            CommonPatchPoolTest(protoPool, modificationFunction, assertAction);
        }
        public void TestRandomBoundCloudPoolProperties()
        {
            using BatchClient client = ClientUnitTestCommon.CreateDummyClient();
            for (int i = 0; i < TestRunCount; i++)
            {
                Protocol.Models.CloudPool poolModel =
                    this.customizedObjectFactory.GenerateNew <Protocol.Models.CloudPool>();

                CloudPool boundPool = new CloudPool(client, poolModel, client.CustomBehaviors);
                ObjectComparer.CheckEqualityResult result = this.objectComparer.CheckEquality(boundPool, poolModel);
                Assert.True(result.Equal, result.Message);
            }
        }
Ejemplo n.º 5
0
        public void TestPatchPool_ThrowsOnNullPropertySet()
        {
            const string poolId    = "Foo";
            var          protoPool = new Protocol.Models.CloudPool(id: poolId);

            Action <CloudPool> modificationFunction = pool => pool.StartTask = null;
            Action <Protocol.Models.PoolPatchParameter> 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>(() => CommonPatchPoolTest(protoPool, modificationFunction, assertAction));
        }
Ejemplo n.º 6
0
        public void TestPatchPool_ChangedComplexParameterIsSerialized()
        {
            const string poolId         = "Foo";
            const string newCommandLine = "Hello";

            var protoPool = new Protocol.Models.CloudPool(id: poolId, startTask: new Protocol.Models.StartTask(commandLine: "Foo"));

            Action <CloudPool> modificationFunction = pool => pool.StartTask.CommandLine = newCommandLine;
            Action <Protocol.Models.PoolPatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.Metadata);
                Assert.Null(patchParameters.ApplicationPackageReferences);
                Assert.Null(patchParameters.CertificateReferences);

                Assert.NotNull(patchParameters.StartTask);
                Assert.Equal(newCommandLine, patchParameters.StartTask.CommandLine);
            };

            CommonPatchPoolTest(protoPool, modificationFunction, assertAction);
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        public void TestPatchPool_ChangedCollectionParameterIsSerialized()
        {
            const string poolId = "Foo";

            var protoPool = new Protocol.Models.CloudPool(
                id: poolId,
                metadata: new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem("Foo", "Bar")
            });

            Action <CloudPool> modificationFunction = pool => pool.Metadata.Add(new MetadataItem("Baz", "Qux"));
            Action <Protocol.Models.PoolPatchParameter> assertAction = patchParameters =>
            {
                Assert.Null(patchParameters.StartTask);
                Assert.Null(patchParameters.ApplicationPackageReferences);
                Assert.Null(patchParameters.CertificateReferences);

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

            CommonPatchPoolTest(protoPool, modificationFunction, assertAction);
        }
Ejemplo n.º 9
0
 public static IEnumerable <Protocol.RequestInterceptor> CreateGetPoolRequestInterceptor(Protocol.Models.CloudPool poolToReturn)
 {
     return(CreateGetRequestInterceptor <Protocol.Models.PoolGetOptions, Protocol.Models.CloudPool, Protocol.Models.PoolGetHeaders>(poolToReturn));
 }