public void DescribeEndpoint3()
        {
            var mock = new Mock <DescribeEndpointServiceImpl>();

            var status = 200;

            var response = new HttpResponse();
            var content  = Encoding.GetEncoding("UTF-8").GetBytes(
                "{\"Code\":\"Success\",\"Message\":\"ThisIsMessage\",\"RequestId\":\"ThisIsRequestId\",\"AccessKeyId\":\"MockAccessKeyId\",\"AccessKeySecret\":\"\",\"SecurityToken\":\"\",\"Expiration\":\"" +
                DateTimeMock.getNowDateTimeString() + "\"}");

            response.ContentType = FormatType.JSON;
            response.Content     = content;
            response.Status      = status;
            response.Encoding    = "UTF-8";

            mock.Setup(foo => foo.GetResponse(
                           It.IsAny <HttpRequest>()
                           )).Returns(response);

            var instance = mock.Object;

            var credential     = new Credential();
            var locationConfig = new LocationConfig();

            var result = instance.DescribeEndpoint(
                "regionId", "serviceCode", "endpointType", credential, locationConfig
                );

            Assert.Null(result);
        }
        public void Fetch2()
        {
            // When Request Throw Exception
            var mock = new Mock <ECSMetadataServiceCredentialsFetcher>
            {
                CallBase = true
            };

            var response = new HttpResponse();
            var content  = Encoding.GetEncoding("UTF-8").GetBytes(
                "{\"Code\":\"Success\",\"Message\":\"ThisIsMessage\",\"RequestId\":\"ThisIsRequestId\",\"AccessKeyId\":\"MockAccessKeyId\",\"AccessKeySecret\":\"\",\"SecurityToken\":\"\",\"Expiration\":\"" +
                DateTimeMock.getNowDateTimeString() + "\"}");

            response.ContentType = FormatType.JSON;
            response.Content     = content;
            response.Status      = 200;

            var e = new Exception();

            mock.Setup(foo => foo.GetResponse(
                           It.IsAny <HttpRequest>()
                           )).Throws(e);

            var instance = mock.Object;

            Assert.Throws <ClientException>(
                () =>
            {
                var credentials = instance.Fetch();
                ;
            }
                );
        }
        public void Fetch3()
        {
            // When Some Data is null => Code is null
            var mock = new Mock <ECSMetadataServiceCredentialsFetcher>()
            {
                CallBase = true
            };

            HttpResponse response = new HttpResponse();

            byte[] content = Encoding.GetEncoding("UTF-8").GetBytes("{\"Message\":\"ThisIsMessage\",\"RequestId\":\"ThisIsRequestId\",\"AccessKeyId\":\"MockAccessKeyId\",\"AccessKeySecret\":\"\",\"SecurityToken\":\"\",\"Expiration\":\"" + DateTimeMock.getNowDateTimeString() + "\"}");
            response.ContentType = FormatType.JSON;
            response.Content     = content;
            response.Status      = 200;

            Exception e = new Exception();

            mock.Setup(foo => foo.GetResponse(
                           It.IsAny <HttpRequest>()
                           )).Returns(response);

            ECSMetadataServiceCredentialsFetcher instance = mock.Object;

            Assert.Throws <ClientException>(
                () =>
            {
                InstanceProfileCredentials credentials = instance.Fetch();;
            }
                );
        }
        public void Fetch1()
        {
            // When Success
            var mock = new Mock <ECSMetadataServiceCredentialsFetcher>()
            {
                CallBase = true
            };

            HttpResponse response = new HttpResponse();

            byte[] content = Encoding.GetEncoding("UTF-8").GetBytes("{\"Code\":\"Success\",\"Message\":\"ThisIsMessage\",\"RequestId\":\"ThisIsRequestId\",\"AccessKeyId\":\"MockAccessKeyId\",\"AccessKeySecret\":\"\",\"SecurityToken\":\"\",\"Expiration\":\"" + DateTimeMock.getNowDateTimeString() + "\"}");
            response.ContentType = FormatType.JSON;
            response.Content     = content;
            response.Status      = 200;

            mock.Setup(foo => foo.GetResponse(
                           It.IsAny <HttpRequest>()
                           )).Returns(response);

            ECSMetadataServiceCredentialsFetcher instance = mock.Object;

            EcsRamRoleCredential credentials = instance.Fetch();;

            Assert.Equal("MockAccessKeyId", credentials.GetAccessKeyId());
        }