public void ProcessSetProfileTestAllArgs()
        {
            // Setup
            ProfileWithDefinition oldProfileWithDefinition = defaultProfileWithDefinition;

            var newProfileWithDefinition = new ProfileWithDefinition
            {
                DomainName = ProfileDomainName,
                Name = ProfileName,
                Endpoints = new List<TrafficManagerEndpoint>(),
                LoadBalancingMethod = NewLoadBalancingMethod,
                MonitorPort = NewMonitorPort,
                Status = ProfileDefinitionStatus.Enabled,
                MonitorRelativePath = NewMonitorRelativePath,
                MonitorProtocol = NewMonitorProtocol,
                TimeToLiveInSeconds = NewTtl
            };


            var newMonitor = new DefinitionMonitor
                {
                    HttpOptions = new DefinitionMonitorHTTPOptions
                        {
                            ExpectedStatusCode = MonitorExpectedStatusCode,
                            RelativePath = NewMonitorRelativePath,
                            Verb = Verb
                        }
                };

            var updateDefinitionCreateParameters = new DefinitionCreateParameters
                {
                    DnsOptions = new DefinitionDnsOptions
                        {
                            TimeToLiveInSeconds = NewTtl
                        },
                    Policy = new DefinitionPolicyCreateParameters
                        {
                            LoadBalancingMethod = NewLoadBalancingMethod,
                            Endpoints = new DefinitionEndpointCreateParameters[0]
                        },
                    Monitors = new[] { newMonitor }
                };

            clientMock
                .Setup(c => c.AssignDefinitionToProfile(ProfileName, It.IsAny<DefinitionCreateParameters>()))
                .Returns(newProfileWithDefinition);

            clientMock
                .Setup(c => c.InstantiateTrafficManagerDefinition(
                NewLoadBalancingMethod.ToString(),
                NewMonitorPort,
                NewMonitorProtocol.ToString(),
                NewMonitorRelativePath,
                NewTtl,
                oldProfileWithDefinition.Endpoints))
                .Returns(updateDefinitionCreateParameters);

            cmdlet = new SetAzureTrafficManagerProfile
                {
                    Name = ProfileName,
                    LoadBalancingMethod = NewLoadBalancingMethod.ToString(),
                    MonitorPort = NewMonitorPort,
                    MonitorProtocol = NewMonitorProtocol.ToString(),
                    MonitorRelativePath = NewMonitorRelativePath,
                    Ttl = NewTtl,
                    TrafficManagerClient = clientMock.Object,
                    CommandRuntime = mockCommandRuntime,
                    TrafficManagerProfile = oldProfileWithDefinition
                };


            // Action
            cmdlet.ExecuteCmdlet();
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(newProfileWithDefinition.Name, actual.Name);
            Assert.AreEqual(newProfileWithDefinition.DomainName, actual.DomainName);
            Assert.AreEqual(newProfileWithDefinition.LoadBalancingMethod, actual.LoadBalancingMethod);
            Assert.AreEqual(newProfileWithDefinition.MonitorPort, actual.MonitorPort);
            Assert.AreEqual(newProfileWithDefinition.MonitorProtocol, actual.MonitorProtocol);
            Assert.AreEqual(newProfileWithDefinition.MonitorRelativePath, actual.MonitorRelativePath);
            Assert.AreEqual(newProfileWithDefinition.TimeToLiveInSeconds, actual.TimeToLiveInSeconds);

            // Most important assert; the cmdlet is passing the right parameters
            clientMock.Verify(c => c.InstantiateTrafficManagerDefinition(
                NewLoadBalancingMethod.ToString(),
                NewMonitorPort,
                NewMonitorProtocol.ToString(),
                NewMonitorRelativePath,
                NewTtl,
                oldProfileWithDefinition.Endpoints), Times.Once());
        }
 public ProfileWithDefinition() : base(new Profile())
 {
     this.endpoints = null;
     this.definition = new Definition()
     {
         Policy = new DefinitionPolicyResponse()
     };
     DefinitionMonitor monitor = new DefinitionMonitor()
     {
         HttpOptions = new DefinitionMonitorHTTPOptions(),
     };
     this.definition.Monitors.Add(monitor);
     this.definition.DnsOptions = new DefinitionDnsOptions();
 }
        public void CreateADefinitionAndEnableTheProfile(
            string profileName,
            LoadBalancingMethod loadBalancingMethod,
            IList<DefinitionEndpointCreateParameters> endpoints)
        {
            DefinitionCreateParameters definitionParameter = new DefinitionCreateParameters();
            DefinitionMonitor monitor = new DefinitionMonitor();
            DefinitionDnsOptions dnsOption = new DefinitionDnsOptions();
            DefinitionPolicyCreateParameters policyParameter = new DefinitionPolicyCreateParameters();
            DefinitionMonitorHTTPOptions monitorHttpOption = new DefinitionMonitorHTTPOptions();

            definitionParameter.DnsOptions = dnsOption;
            definitionParameter.Policy = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            dnsOption.TimeToLiveInSeconds = 30;

            monitorHttpOption.RelativePath = "/randomFile.aspx";
            monitorHttpOption.Verb = "GET";
            monitorHttpOption.ExpectedStatusCode = (int)HttpStatusCode.OK;

            monitor.Protocol = DefinitionMonitorProtocol.Http;
            //Set fixed values required by services   
            monitor.IntervalInSeconds = 30;
            monitor.TimeoutInSeconds = 10;
            monitor.ToleratedNumberOfFailures = 3;
            monitor.Port = 80;

            policyParameter.LoadBalancingMethod = loadBalancingMethod;
            policyParameter.Endpoints = endpoints;

            TrafficManagerClient.Definitions.Create(profileName, definitionParameter);
        }
        public DefinitionCreateParameters InstantiateTrafficManagerDefinition(
            string loadBalancingMethod,
            int monitorPort,
            string monitorProtocol,
            string monitorRelativePath,
            int ttl,
            IList<TrafficManagerEndpoint> endpoints)
        {
            // Create the definition
            var definitionParameter = new DefinitionCreateParameters();
            var dnsOptions = new DefinitionDnsOptions();
            var monitor = new DefinitionMonitor();
            var policyParameter = new DefinitionPolicyCreateParameters();
            var monitorHttpOption = new DefinitionMonitorHTTPOptions();

            dnsOptions.TimeToLiveInSeconds = ttl;

            monitorHttpOption.RelativePath = monitorRelativePath;
            monitorHttpOption.Verb = Constants.monitorHttpOptionVerb;
            monitorHttpOption.ExpectedStatusCode = Constants.monitorHttpOptionExpectedStatusCode;

            monitor.Protocol =
                (DefinitionMonitorProtocol)Enum.Parse(typeof(DefinitionMonitorProtocol), monitorProtocol);
            monitor.IntervalInSeconds = Constants.monitorIntervalInSeconds;
            monitor.TimeoutInSeconds = Constants.monitorTimeoutInSeconds;
            monitor.ToleratedNumberOfFailures = Constants.monitorToleratedNumberOfFailures;
            monitor.Port = monitorPort;
            policyParameter.LoadBalancingMethod =
                (LoadBalancingMethod)Enum.Parse(typeof(LoadBalancingMethod), loadBalancingMethod);

            policyParameter.Endpoints = new List<DefinitionEndpointCreateParameters>();
            foreach (TrafficManagerEndpoint endpoint in endpoints)
            {
                var endpointParam = new DefinitionEndpointCreateParameters
                    {
                        DomainName = endpoint.DomainName,
                        Location = endpoint.Location,
                        Status = endpoint.Status,
                        Type = endpoint.Type,
                        Weight = endpoint.Weight
                    };

                policyParameter.Endpoints.Add(endpointParam);
            }

            definitionParameter.DnsOptions = dnsOptions;
            definitionParameter.Policy = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            return definitionParameter;
        }