public void ProcessSetProfileTestMonitorPort()
        {
            ProfileWithDefinition oldProfileWithDefinition = defaultProfileWithDefinition;

            cmdlet = new SetAzureTrafficManagerProfile
            {
                Name = ProfileName,
                // We only change the monitor port
                MonitorPort           = NewMonitorPort,
                TrafficManagerClient  = clientMock.Object,
                CommandRuntime        = mockCommandRuntime,
                TrafficManagerProfile = oldProfileWithDefinition
            };


            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            clientMock.Verify(
                c => c.InstantiateTrafficManagerDefinition(
                    DefaultLoadBalancingMethod.ToString(),
                    // monitor port is the new one
                    NewMonitorPort,
                    MonitorProtocol.ToString(),
                    MonitorRelativePath,
                    Ttl,
                    oldProfileWithDefinition.Endpoints),
                Times.Once());
        }
Esempio n. 2
0
        public void ProcessNewProfileTest()
        {
            // Setup
            clientMock.Setup(c => c.NewAzureTrafficManagerProfile(
                                 ProfileName,
                                 ProfileDomainName,
                                 DefaultLoadBalancingMethod.ToString(),
                                 MonitorPort,
                                 MonitorProtocol.ToString(),
                                 MonitorRelativePath,
                                 Ttl))
            .Returns(new ProfileWithDefinition
            {
                DomainName          = ProfileDomainName,
                Name                = ProfileName,
                Endpoints           = new List <TrafficManagerEndpoint>(),
                LoadBalancingMethod = DefaultLoadBalancingMethod,
                MonitorPort         = 80,
                Status              = ProfileDefinitionStatus.Enabled,
                MonitorRelativePath = MonitorRelativePath,
                TimeToLiveInSeconds = Ttl
            });


            cmdlet = new NewAzureTrafficManagerProfile
            {
                Name                = ProfileName,
                DomainName          = ProfileDomainName,
                LoadBalancingMethod = DefaultLoadBalancingMethod.ToString(),
                MonitorPort         = MonitorPort,
                MonitorProtocol     = MonitorProtocol.ToString(),
                MonitorRelativePath = MonitorRelativePath,
                Ttl = Ttl,
                TrafficManagerClient = clientMock.Object,
                CommandRuntime       = mockCommandRuntime
            };

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            Assert.IsNotNull(actual);
            Assert.AreEqual(ProfileName, actual.Name);
            Assert.AreEqual(ProfileDomainName, actual.DomainName);
            Assert.AreEqual(MonitorRelativePath, actual.MonitorRelativePath);
            Assert.AreEqual(Ttl, actual.TimeToLiveInSeconds);
            Assert.AreEqual(DefaultLoadBalancingMethod, actual.LoadBalancingMethod);
            Assert.IsTrue(actual.Endpoints.Count == 0);
        }
        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());
        }