public void TestSetup()
 {
     mockCommandRuntime    = new MockCommandRuntime();
     cmdlet                = new AddAzureTrafficManagerEndpoint();
     cmdlet.CommandRuntime = mockCommandRuntime;
     clientMock            = new Mock <TrafficManagerClient>();
 }
        public void AddTrafficManagerEndpointWebsite()
        {
            ProfileWithDefinition original = GetProfileWithDefinition();

            // Setup
            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AzureWebsiteType,
                Weight                = Weight,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime,
                Status                = "Enabled"
            };

            // Action
            cmdlet.ExecuteCmdlet();

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

            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(original, actual);

            // There is a new endpoint with the new domain name in "actual" but not in "original"
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
        }
        public void AddTrafficManagerEndpointAlreadyExistsFails()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            var existingEndpoint = new TrafficManagerEndpoint
            {
                DomainName = DomainName,
                Type       = EndpointType.Any,
                Status     = EndpointStatus.Enabled
            };

            original.Endpoints.Add(existingEndpoint);

            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AnyType,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime
            };

            // Action + Assert
            Testing.AssertThrows <Exception>(() => cmdlet.ExecuteCmdlet());
        }
        public void AddTrafficManagerEndpointNoWeightNoLocationNoMinChildEndpoints()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AnyType,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime,
                Status                = "Enabled"
            };

            // Action
            cmdlet.ExecuteCmdlet();

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

            // Assert
            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(original, actual);

            // There is a new endpoint with the new domain name in "actual" but not in "original"
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
            TrafficManagerEndpoint endpoint = actual.Endpoints.First(e => e.DomainName == DomainName);

            Assert.AreEqual(null, endpoint.Weight);
            Assert.IsNull(endpoint.Location);
            Assert.AreEqual(null, endpoint.MinChildEndpoints);
        }
        public void AddTrafficManagerEndpointTrafficManager()
        {
            ProfileWithDefinition nestedProfile   = GetProfileWithDefinition();
            ProfileWithDefinition topLevelProfile = GetProfileWithDefinition(TopLevelProfileDomainName);

            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AnyType,
                Weight                = Weight,
                TrafficManagerProfile = nestedProfile,
                CommandRuntime        = mockCommandRuntime,
                Status                = "Enabled"
            };

            var cmdletTopLevelEndpoint = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = ProfileDomainName,
                Type                  = TrafficManagerType,
                Weight                = Weight,
                MinChildEndpoints     = MinChildEndpoints,
                TrafficManagerProfile = topLevelProfile,
                CommandRuntime        = mockCommandRuntime,
                Status                = "Enabled"
            };

            // Action
            cmdlet.ExecuteCmdlet();
            cmdletTopLevelEndpoint.ExecuteCmdlet();

            var actualNestedProfile   = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;
            var actualTopLevelProfile = mockCommandRuntime.OutputPipeline[1] as ProfileWithDefinition;

            // Assert
            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(nestedProfile, actualNestedProfile);
            AssertAllProfilePropertiesDontChangeExceptEndpoints(topLevelProfile, actualTopLevelProfile);

            // There is a new endpoint with the new domain name in "actual" but not in "nestedProfile"
            Assert.IsTrue(actualNestedProfile.Endpoints.Any(e => e.DomainName == DomainName));
            Assert.IsTrue(actualTopLevelProfile.Endpoints.Any(e => e.DomainName == ProfileDomainName));
        }