private async Task <CreateFirewallRuleResponse> DoHandleCreateFirewallRuleRequest(CreateFirewallRuleParams firewallRule)
        {
            var result = new CreateFirewallRuleResponse();

            // Note: currently not catching the exception. Expect the caller to this message to handle error cases by
            // showing the error string and responding with a clean failure message to the user
            try
            {
                AuthenticationService authService = ServiceProvider.GetService <AuthenticationService>();
                IUserAccount          account     = await authService.SetCurrentAccountAsync(firewallRule.Account, firewallRule.SecurityTokenMappings);

                FirewallRuleResponse response = await firewallRuleService.CreateFirewallRuleAsync(firewallRule.ServerName, firewallRule.StartIpAddress, firewallRule.EndIpAddress);

                result.Result = true;
            }
            catch (FirewallRuleException ex)
            {
                result.Result       = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
Пример #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;
            }
        }