Microsoft.WindowsAzure.Commands.Test.Utilities.Common.MockStorageService.InitializeMocks C# (CSharp) Method

InitializeMocks() public method

public InitializeMocks ( Mock mock ) : void
mock Mock
return void
        public void InitializeMocks(Mock<StorageManagementClient> mock)
        {
            mock.Setup(c => c.StorageAccounts.GetAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
                .Returns((string serviceName, CancellationToken cancellationToken) => CreateGetResponse(serviceName));

            mock.Setup(c => c.StorageAccounts.GetKeysAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
                .Returns((string serviceName, CancellationToken cancellationToken) => CreateGetKeysResponse(serviceName));

            mock.Setup(c => c.StorageAccounts.CreateAsync(It.IsAny<StorageAccountCreateParameters>(), It.IsAny<CancellationToken>()))
                .Callback((StorageAccountCreateParameters createParameters, CancellationToken cancellationToken) => AddService(createParameters))
                .Returns(CreateCreateResponse);
        }

Usage Example

Ejemplo n.º 1
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
            };
        }
All Usage Examples Of Microsoft.WindowsAzure.Commands.Test.Utilities.Common.MockStorageService::InitializeMocks