コード例 #1
0
        public override void InitializeService(IProtocolEndpoint serviceHost)
        {
            Logger.Write(LogLevel.Verbose, "ResourceProvider initialized");
            serviceHost.SetRequestHandler(CreateFirewallRuleRequest.Type, HandleCreateFirewallRuleRequest);
            serviceHost.SetRequestHandler(CanHandleFirewallRuleRequest.Type, ProcessHandleFirewallRuleRequest);

            firewallRuleService = new FirewallRuleService()
            {
                AuthenticationManager = ServiceProvider.GetService <IAzureAuthenticationManager>(),
                ResourceManager       = ServiceProvider.GetService <IAzureResourceManager>()
            };
        }
コード例 #2
0
        private async Task <FirewallRuleResponse> VerifyCreateAsync(ServiceTestContext testContext, string serverName, bool verifyFirewallRuleCreated = true)
        {
            try
            {
                FirewallRuleService service = new FirewallRuleService();
                service.AuthenticationManager = testContext.ApplicationAuthenticationManager;
                service.ResourceManager       = testContext.AzureResourceManager;
                FirewallRuleResponse response = await service.CreateFirewallRuleAsync(serverName, testContext.StartIpAddress, testContext.EndIpAddress);

                if (verifyFirewallRuleCreated)
                {
                    testContext.AzureResourceManagerMock.Verify(x => x.CreateFirewallRuleAsync(
                                                                    It.Is <IAzureResourceManagementSession>(s => s.SubscriptionContext.Subscription.SubscriptionId == testContext.ValidSubscription.Subscription.SubscriptionId),
                                                                    It.Is <IAzureSqlServerResource>(r => r.FullyQualifiedDomainName == serverName),
                                                                    It.Is <FirewallRuleRequest>(y => y.EndIpAddress.ToString().Equals(testContext.EndIpAddress) && y.StartIpAddress.ToString().Equals(testContext.StartIpAddress))),
                                                                Times.AtLeastOnce);
                }
                else
                {
                    testContext.AzureResourceManagerMock.Verify(x => x.CreateFirewallRuleAsync(
                                                                    It.Is <IAzureResourceManagementSession>(s => s.SubscriptionContext.Subscription.SubscriptionId == testContext.ValidSubscription.Subscription.SubscriptionId),
                                                                    It.Is <IAzureSqlServerResource>(r => r.FullyQualifiedDomainName == serverName),
                                                                    It.Is <FirewallRuleRequest>(y => y.EndIpAddress.ToString().Equals(testContext.EndIpAddress) && y.StartIpAddress.ToString().Equals(testContext.StartIpAddress))),
                                                                Times.Never);
                }

                return(response);
            }
            catch (Exception ex)
            {
                if (ex is FirewallRuleException)
                {
                    Assert.True(ex.InnerException == null || !(ex.InnerException is FirewallRuleException));
                }
                throw;
            }
        }