Пример #1
0
        private static void VerifyHttpMethod(string expectedStrMethod, PlaybackTestHandler handler, int requestIndex = 0)
        {
            HttpMethod expMethod = null;

            switch (expectedStrMethod)
            {
            case "PUT":
                expMethod = HttpMethod.Put;
                break;

            case "PATCH":
                expMethod = new HttpMethod("PATCH");
                break;

            case "POST":
                expMethod = HttpMethod.Post;
                break;

            case "DELETE":
                expMethod = HttpMethod.Delete;
                break;
            }

            Assert.Equal(expMethod, handler.Requests[requestIndex].Method);
        }
Пример #2
0
            public void NoHeader202()
            {
                var handler    = new PlaybackTestHandler(LroRules.DELETEResponses.NoHeader202());
                var fakeClient = GetClient(handler);

                Assert.Throws <ValidationException>(() => fakeClient.RedisOperations.Delete("rg", "redist", "1234"));
            }
Пример #3
0
        public void CommonErrModel_DetailsWithMultipleAdditionalInfo()
        {
            PlaybackTestHandler   testHandler = new PlaybackTestHandler(CloudErrorTestResponse.CreateUpdate_DetailsWithMultipleAdditionalInfo());
            RedisManagementClient redisClient = GetRedisClient(testHandler);

            CloudException cEx = Assert.Throws <CloudException>(() =>
                                                                redisClient.RedisOperations.CreateOrUpdate(RGroupName, ResourceName, RedisCreateUpdateParams, SubId)
                                                                );

            CloudError ce = cEx.Body;

            Assert.Equal(1, ce.Details.Count);
            List <AdditionalErrorInfo> detailsAdditionalInfoList = ce.Details[0].AdditionalInfo as List <AdditionalErrorInfo>;

            Assert.Equal(2, detailsAdditionalInfoList.Count);
            Assert.Equal("PolicyViolation", detailsAdditionalInfoList[0].Type);
            Assert.Equal("SecurityViolation", detailsAdditionalInfoList[1].Type);


            JObject jo = detailsAdditionalInfoList[0].Info;

            Assert.NotNull(jo);

            string infoVal = jo.Value <string>("policySetDefinitionDisplayName");

            Assert.Equal("Secure the environment", infoVal);
        }
Пример #4
0
            public void NoHeader201()
            {
                var handler    = new PlaybackTestHandler(LroRules.POSTResponses.NoHeader201());
                var fakeClient = GetClient(handler);

                Assert.Throws <CloudException>(() => fakeClient.RedisOperations.Post("rg", "redist", "1234"));
            }
Пример #5
0
 private static void VerifyRequestCount(string httpStrMethod, PlaybackTestHandler handler, int putCount = 0, int patchCount = 0)
 {
     if (httpStrMethod.Equals("PUT"))
     {
         Assert.Equal(putCount, handler.Requests.Count);
     }
     else if (httpStrMethod.Equals("PATCH"))
     {
         Assert.Equal(patchCount, handler.Requests.Count);
     }
 }
Пример #6
0
                public void LocationHeader202(string inlineHttpMethod)
                {
                    var handler    = new PlaybackTestHandler(LroRules.PUTResponses.Location202());
                    var fakeClient = GetClient(handler);

                    ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(Put202_LocationHeaderUrl, handler, requestIndex: 1);
                }
Пример #7
0
        public void CommonErrModel_BasicTests()
        {
            PlaybackTestHandler   testHandler = new PlaybackTestHandler(CloudErrorTestResponse.MockCreateOrUpdateWithTwoTries());
            RedisManagementClient redisClient = GetRedisClient(testHandler);

            CloudException cEx = Assert.Throws <CloudException>(() =>
                                                                redisClient.RedisOperations.CreateOrUpdate(RGroupName, ResourceName, RedisCreateUpdateParams, SubId)
                                                                );

            Assert.Equal("BadArgument", cEx.Body.Code);
        }
Пример #8
0
        public void TestCloudExceptionDeserialization()
        {
            var tokenCredentials = new TokenCredentials("123", "abc");
            var handler          = new PlaybackTestHandler(GetExceptionResponse());
            var fakeClient       = new CloudExceptionFakeServiceClient(tokenCredentials, handler);
            var ex = Assert.Throws <System.AggregateException>(() => fakeClient.CloudExceptionFakeOperations.GetOperationSync().Result);

            Assert.IsType <CloudException>(ex.InnerException);
            var cloudEx = (CloudException)ex.InnerException;

            Assert.Equal("1234", cloudEx.Body.Code);
        }
Пример #9
0
        public void CommonErrModel_NonEmptyAdditionalInfo()
        {
            PlaybackTestHandler   testHandler = new PlaybackTestHandler(CloudErrorTestResponse.CreateUpdate_ErrWithNonEmptyAdditionalInfo());
            RedisManagementClient redisClient = GetRedisClient(testHandler);

            CloudException cEx = Assert.Throws <CloudException>(() =>
                                                                redisClient.RedisOperations.CreateOrUpdate(RGroupName, ResourceName, RedisCreateUpdateParams, SubId)
                                                                );

            Assert.Equal("BadArgument", cEx.Body.Code);
            Assert.Equal(1, cEx.Body.AdditionalInfo.Count);
            Assert.Equal("PolicyViolation", cEx.Body.AdditionalInfo[0].Type);
        }
Пример #10
0
            public void LocationHeader202()
            {
                var handler    = new PlaybackTestHandler(LroRules.DELETEResponses.Location202());
                var fakeClient = GetClient(handler);

                fakeClient.RedisOperations.Delete("rg", "redist", "1234");

                VerifyHttpMethod("DELETE", handler, requestIndex: 0);
                VerifyRequestUrl(DeleteOriginalResourceRequestUrl, handler, 0);
                VerifyRequestUrl(Delete202_LocationHeaderUrl, handler, requestIndex: 1);
                VerifyRequestUrl(Delete202_LocationHeaderUrl, handler, requestIndex: 2);

                Assert.Equal(4, handler.Requests.Count);
            }
Пример #11
0
            public void LocationAndAzAsyncHeader202()
            {
                var handler    = new PlaybackTestHandler(LroRules.PUTResponses.LocationAndAzAsync202());
                var fakeClient = GetClient(handler);

                fakeClient.RedisOperations.Post("rg", "redist", "1234");

                VerifyHttpMethod("POST", handler, requestIndex: 0);
                VerifyRequestUrl(PostOriginalResourceRequestUrl, handler, 0);
                VerifyRequestUrl(Post202_AzAsyncOperationHeaderUrl, handler, requestIndex: 1);
                VerifyRequestUrl(Post202_LocationHeaderUrl, handler, requestIndex: 2);

                Assert.Equal(3, handler.Requests.Count);
            }
Пример #12
0
                public void LocationAndAzAsyncHeader200(string inlineHttpMethod)
                {
                    var handler    = new PlaybackTestHandler(LroRules.PUTResponses.LocationAndAzAsync200());
                    var fakeClient = GetClient(handler);

                    ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(Put202_AzAsyncOperationHeaderUrl, handler, requestIndex: 1);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, requestIndex: 2);

                    Assert.Equal(3, handler.Requests.Count);
                }
Пример #13
0
                public void NoHeader200PassThrough(string inlineHttpMethod)
                {
                    var           handler    = new PlaybackTestHandler(LroRules.PUTResponses.NoHeader200PassThrough());
                    var           fakeClient = GetClient(handler);
                    RedisResource redisRes   = ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, requestIndex: 1);

                    //Verify we do not execute Final GET on original resource URI
                    Assert.Equal(2, handler.Requests.Count);

                    Assert.Null(redisRes.Id);
                }
Пример #14
0
                public void LocationHeader200(string inlineHttpMethod)
                {
                    var           handler    = new PlaybackTestHandler(LroRules.PUTResponses.Location200());
                    var           fakeClient = GetClient(handler);
                    RedisResource redisRes   = ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(Put202_LocationHeaderUrl, handler, requestIndex: 1);

                    //Verify we do not execute Final GET on original resource URI
                    Assert.Equal(2, handler.Requests.Count);
                    //VerifyRequestCount(inlineHttpMethod, handler, putCount: 2, patchCount: 1);

                    Assert.NotNull(redisRes.Location);
                }
Пример #15
0
 private static void VerifyRequestUrl(string expectedUrl, PlaybackTestHandler handler, int requestIndex = 0)
 {
     Assert.Equal(expectedUrl, handler.Requests[requestIndex].RequestUri.ToString());
 }