public void AddTrafficManagerEndpointCloudService()
        {
            ProfileWithDefinition original = GetProfileWithDefinition();

            // Setup
            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName = DomainName,
                Type = CloudServiceType,
                Weight = Weight,
                Status = Status.ToString(),
                TrafficManagerProfile = original,
                CommandRuntime = mockCommandRuntime
            };

            // 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"
            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 TestSetup()
 {
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet = new AddAzureTrafficManagerEndpoint();
     cmdlet.CommandRuntime = mockCommandRuntime;
     clientMock = new Mock<TrafficManagerClient>();
 }
        public void AddTrafficManagerEndpointNoWeightNoLocation()
        {
            // 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(1, endpoint.Weight);
            Assert.IsNull(endpoint.Location);
        }
        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));
        }