Esempio n. 1
0
        protected BaseWorkflowExecutor(IDictionary <string, string> configSettings = null, MockQueryClient queryClient = null)
        {
            ManagementClient    = new MockManagementClient();
            QueryClient         = queryClient;
            InfrastructureAgent = new MockInfrastructureAgentWrapper();
            Coordinator         = new MockInfrastructureCoordinatorFactory(ManagementClient, configSettings, queryClient, InfrastructureAgent).Create() as WindowsAzureInfrastructureCoordinator;
            NotificationContext = new MockManagementNotificationContext();
            CompletedEvent      = new ManualResetEvent(false);

            TestExecutionTimeInSeconds = 300;
        }
        public void ConstructorTest1()
        {
            var coordinator1 = new MockInfrastructureCoordinatorFactory(new MockManagementClient()).Create();

            Verify.IsNotNull(coordinator1, "Successfully created a real coordinator tuple passing in mock objects");

            Verify.Throws <DeploymentManagementEndpointNotFoundException>(() =>
            {
                var managementClient = new WindowsAzureManagementClient();
                new MockInfrastructureCoordinatorFactory(managementClient).Create();
            },
                                                                          "Exception thrown as expected while creating management client since MR is not enabled in unit-test mode");
        }
        public void HandleCommands1()
        {
            var coordinator1 = new MockInfrastructureCoordinatorFactory(new MockManagementClient()).Create();

            {
                var result =
                    coordinator1.RunCommandAsync(false, "GetRoleInstances", TimeSpan.MaxValue,
                                                 CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetRoleInstances returned a valid string");
            }

            {
                var result = coordinator1.RunCommandAsync(false, "GetJobs", TimeSpan.MaxValue,
                                                          CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetJobs returned a valid string");
            }

            {
                var result =
                    coordinator1.RunCommandAsync(false, "GetCurrentState", TimeSpan.MaxValue,
                                                 CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetCurrentState returned a valid string");
            }

            {
                try
                {
                    // a common typo - GetCurrentStatus instead of GetCurrentState
                    var result =
                        coordinator1.RunCommandAsync(false, "GetCurrentStatus", TimeSpan.MaxValue,
                                                     CancellationToken.None).Result;
                    Verify.Fail("Exception should have been thrown due to an invalid command");
                }
                catch (AggregateException ae)
                {
                    ae.Flatten().Handle(ex =>
                    {
                        if (ex is ArgumentException)
                        {
                            Trace.ConsoleWriteLine(TraceType, "Handling expected exception: {0}", ex);
                            return(true);
                        }

                        return(false);
                    });
                }
            }
        }