Example #1
0
        private Task <StorageAccountGetResponse> CreateGetResponse(string serviceName)
        {
            Task <StorageAccountGetResponse> resultTask;
            var data = accounts.FirstOrDefault(a => a.Name == serviceName);

            if (data != null)
            {
                var storageServiceGetResponse = new StorageAccountGetResponse
                {
                    StorageAccount = new StorageAccount
                    {
                        Name       = data.Name,
                        Properties = new StorageAccountProperties
                        {
                            Endpoints =
                            {
                                new Uri(data.BlobEndpoint),
                                new Uri(data.QueueEndpoint),
                                new Uri(data.TableEndpoint)
                            }
                        }
                    }
                };
                resultTask = Tasks.FromResult(storageServiceGetResponse);
            }
            else
            {
                resultTask = Tasks.FromException <StorageAccountGetResponse>(ClientMocks.Make404Exception());
            }
            return(resultTask);
        }
Example #2
0
        public CloudServiceClientTests()
        {
            AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir;

            storageService = new MockStorageService()
                             .Add(a => SetupStorage(serviceName.ToLowerInvariant(), a))
                             .Add(a => SetupStorage(storageName.ToLowerInvariant(), a));

            services = new MockServicesHost()
                       .Add(s =>
            {
                s.Name = serviceName;
                s.AddDeployment(d =>
                {
                    d.Slot = DeploymentSlot.Production;
                    d.Name = "mydeployment";
                });
            });

            subscription = new AzureSubscription
            {
                Properties = new Dictionary <AzureSubscription.Property, string> {
                    { AzureSubscription.Property.Default, "True" }
                },
                Id   = Guid.NewGuid(),
                Name = Test.Utilities.Common.Data.Subscription1,
            };

            cloudBlobUtilityMock = new Mock <CloudBlobUtility>();
            cloudBlobUtilityMock.Setup(f => f.UploadPackageToBlob(
                                           It.IsAny <StorageManagementClient>(),
                                           It.IsAny <string>(),
                                           It.IsAny <string>(),
                                           It.IsAny <BlobRequestOptions>())).Returns(new Uri("http://www.packageurl.azure.com"));

            clientMocks = new ClientMocks(subscription.Id);

            services.InitializeMocks(clientMocks.ComputeManagementClientMock);
            storageService.InitializeMocks(clientMocks.StorageManagementClientMock);

            client = new CloudServiceClient(subscription,
                                            clientMocks.ManagementClientMock.Object,
                                            clientMocks.StorageManagementClientMock.Object,
                                            clientMocks.ComputeManagementClientMock.Object
                                            )
            {
                CloudBlobUtility = cloudBlobUtilityMock.Object
            };
        }
Example #3
0
        public void TestSetup()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;

            storageService = new MockStorageService()
                             .Add(a => SetupStorage(serviceName.ToLowerInvariant(), a))
                             .Add(a => SetupStorage(storageName.ToLowerInvariant(), a));

            services = new MockServicesHost()
                       .Add(s =>
            {
                s.Name = serviceName;
                s.AddDeployment(d =>
                {
                    d.Slot = DeploymentSlot.Production;
                    d.Name = "mydeployment";
                });
            });

            subscription = new WindowsAzureSubscription
            {
                Certificate      = It.IsAny <X509Certificate2>(),
                IsDefault        = true,
                ServiceEndpoint  = new Uri("https://www.azure.com"),
                SubscriptionId   = Guid.NewGuid().ToString(),
                SubscriptionName = Data.Subscription1,
            };

            cloudBlobUtilityMock = new Mock <CloudBlobUtility>();
            cloudBlobUtilityMock.Setup(f => f.UploadPackageToBlob(
                                           It.IsAny <StorageManagementClient>(),
                                           It.IsAny <string>(),
                                           It.IsAny <string>(),
                                           It.IsAny <BlobRequestOptions>())).Returns(new Uri("http://www.packageurl.azure.com"));

            clientMocks = new ClientMocks(subscription.SubscriptionId);

            services.InitializeMocks(clientMocks.ComputeManagementClientMock);
            storageService.InitializeMocks(clientMocks.StorageManagementClientMock);

            client = new CloudServiceClient(subscription,
                                            clientMocks.ManagementClientMock.Object,
                                            clientMocks.StorageManagementClientMock.Object,
                                            clientMocks.ComputeManagementClientMock.Object
                                            )
            {
                CloudBlobUtility = cloudBlobUtilityMock.Object
            };
        }
Example #4
0
        public void AddUserAgentTest()
        {
            WindowsAzureSubscription subscription = new WindowsAzureSubscription
            {
                Certificate      = It.IsAny <X509Certificate2>(),
                IsDefault        = true,
                ServiceEndpoint  = new Uri("https://www.azure.com"),
                SubscriptionId   = Guid.NewGuid().ToString(),
                SubscriptionName = Data.Subscription1,
            };

            WindowsAzureEnvironment environment        = WindowsAzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
            ClientMocks             clientMocks        = new ClientMocks(subscription.SubscriptionId);
            SubscriptionClient      subscriptionClient = clientMocks.SubscriptionClientMock.Object;
            SubscriptionClient      actual             = environment.AddUserAgent(subscriptionClient);

            // verify the UserAgent is set in the subscription client
            Assert.IsTrue(actual.UserAgent.Contains(ApiConstants.UserAgentValue), "Missing proper UserAgent string.");
        }
Example #5
0
        private Task <StorageAccountGetKeysResponse> CreateGetKeysResponse(string serviceName)
        {
            Task <StorageAccountGetKeysResponse> resultTask;
            var data = accounts.FirstOrDefault(a => a.Name == serviceName);

            if (data != null)
            {
                var response = new StorageAccountGetKeysResponse
                {
                    PrimaryKey   = data.PrimaryKey,
                    SecondaryKey = data.SecondaryKey,
                    StatusCode   = HttpStatusCode.OK
                };
                resultTask = Tasks.FromResult(response);
            }
            else
            {
                resultTask = Tasks.FromException <StorageAccountGetKeysResponse>(ClientMocks.Make404Exception());
            }
            return(resultTask);
        }
        public void TestSetup()
        {
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;

            storageService = new MockStorageService()
                .Add(a => SetupStorage(serviceName.ToLowerInvariant(), a))
                .Add(a => SetupStorage(storageName.ToLowerInvariant(), a));

            services = new MockServicesHost()
                .Add(s =>
                {
                    s.Name = serviceName;
                    s.AddDeployment(d =>
                    {
                        d.Slot = DeploymentSlot.Production;
                        d.Name = "mydeployment";
                    });
                });

            subscription = new WindowsAzureSubscription
            {
                Certificate = It.IsAny<X509Certificate2>(),
                IsDefault = true,
                ServiceEndpoint = new Uri("https://www.azure.com"),
                SubscriptionId = Guid.NewGuid().ToString(),
                SubscriptionName = Data.Subscription1,
            };

            cloudBlobUtilityMock = new Mock<CloudBlobUtility>();
            cloudBlobUtilityMock.Setup(f => f.UploadPackageToBlob(
                It.IsAny<StorageManagementClient>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<BlobRequestOptions>())).Returns(new Uri("http://www.packageurl.azure.com"));

            clientMocks = new ClientMocks(subscription.SubscriptionId);

            services.InitializeMocks(clientMocks.ComputeManagementClientMock);
            storageService.InitializeMocks(clientMocks.StorageManagementClientMock);

            client = new CloudServiceClient(subscription,
                clientMocks.ManagementClientMock.Object,
                clientMocks.StorageManagementClientMock.Object,
                clientMocks.ComputeManagementClientMock.Object
                )
            {
                CloudBlobUtility = cloudBlobUtilityMock.Object
            };
        }
        public CloudServiceClientTests()
        {
            AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir;

            storageService = new MockStorageService()
                .Add(a => SetupStorage(serviceName.ToLowerInvariant(), a))
                .Add(a => SetupStorage(storageName.ToLowerInvariant(), a));

            services = new MockServicesHost()
                .Add(s =>
                {
                    s.Name = serviceName;
                    s.AddDeployment(d =>
                    {
                        d.Slot = DeploymentSlot.Production;
                        d.Name = "mydeployment";
                    });
                });

            subscription = new AzureSubscription
            {
                Properties = new Dictionary<AzureSubscription.Property,string> {{AzureSubscription.Property.Default, "True"}},
                Id = Guid.NewGuid(),
                Name = Test.Utilities.Common.Data.Subscription1,
            };

            cloudBlobUtilityMock = new Mock<CloudBlobUtility>();
            cloudBlobUtilityMock.Setup(f => f.UploadPackageToBlob(
                It.IsAny<StorageManagementClient>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<BlobRequestOptions>())).Returns(new Uri("http://www.packageurl.azure.com"));

            clientMocks = new ClientMocks(subscription.Id);

            services.InitializeMocks(clientMocks.ComputeManagementClientMock);
            storageService.InitializeMocks(clientMocks.StorageManagementClientMock);

            client = new CloudServiceClient(subscription,
                clientMocks.ManagementClientMock.Object,
                clientMocks.StorageManagementClientMock.Object,
                clientMocks.ComputeManagementClientMock.Object
                )
            {
                CloudBlobUtility = cloudBlobUtilityMock.Object
            };
        }