public void CanSetGateway()
        {
            const string description = "New gateway description for test";

            var expectedOutput = new PSDataFactoryGateway
            {
                Name        = GatewayName,
                Location    = Location,
                Status      = GatewayStatus.NeedRegistration,
                Description = description
            };

            dataFactoriesClientMock.Setup(
                f => f.PatchGateway(ResourceGroupName, DataFactoryName,
                                    It.Is <PSDataFactoryGateway>
                                        (parameters => parameters.Name == GatewayName && parameters.Description == description)))
            .Returns(expectedOutput).Verifiable();

            _cmdlet.Name            = GatewayName;
            _cmdlet.DataFactoryName = DataFactoryName;
            _cmdlet.Description     = expectedOutput.Description;

            _cmdlet.ExecuteCmdlet();

            dataFactoriesClientMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
        }
Пример #2
0
        public void CanNewGateway()
        {
            var expectedOutput = new PSDataFactoryGateway
            {
                Name        = GatewayName,
                Status      = GatewayStatus.Online,
                Description = "New gateway description for test",
            };

            var fakeRequest  = new HttpRequestMessage(HttpMethod.Get, "https://www.microsoft.com");
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.NotFound);

            dataFactoriesClientMock.Setup(f => f.GetGateway(ResourceGroupName, DataFactoryName, GatewayName))
            .Returns(() =>
            {
                throw CloudException.Create(fakeRequest, String.Empty, fakeResponse, String.Empty);
            })
            .Verifiable();

            dataFactoriesClientMock.Setup(
                f => f.CreateOrUpdateGateway(ResourceGroupName, DataFactoryName, It.IsAny <PSDataFactoryGateway>()))
            .Returns(expectedOutput)
            .Verifiable();

            _cmdlet.Name            = GatewayName;
            _cmdlet.DataFactoryName = DataFactoryName;

            _cmdlet.ExecuteCmdlet();

            dataFactoriesClientMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
        }
Пример #3
0
        public void CanNewGatewayKey()
        {
            var gatewaykey = new PSDataFactoryGatewayKey("FakedKey");

            var expectedOutput = new PSDataFactoryGateway
            {
                Name        = GatewayName,
                Status      = GatewayStatus.Online,
                Description = "New gateway description for test"
            };

            var fakeRequest = new HttpRequestMessage(HttpMethod.Get, "https://www.microsoft.com");

            dataFactoriesClientMock.Setup(
                f => f.RegenerateGatewayKey(ResourceGroupName, DataFactoryName, GatewayName))
            .Returns(gatewaykey)
            .Verifiable();

            _cmdlet.GatewayName     = GatewayName;
            _cmdlet.DataFactoryName = DataFactoryName;

            _cmdlet.ExecuteCmdlet();

            dataFactoriesClientMock.VerifyAll();
            commandRuntimeMock.Verify(f => f.WriteObject(gatewaykey), Times.Once());
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ByFactoryObject)
            {
                if (DataFactory == null)
                {
                    throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryArgumentInvalid));
                }

                DataFactoryName   = DataFactory.DataFactoryName;
                ResourceGroupName = DataFactory.ResourceGroupName;
            }

            PSDataFactoryGateway gateway = null;

            try
            {
                gateway = DataFactoryClient.GetGateway(ResourceGroupName, DataFactoryName, Name);
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            if (gateway != null)
            {
                throw new PSInvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryGatewayExists, Name, DataFactoryName));
            }

            var request = new PSDataFactoryGateway
            {
                Name        = Name,
                Location    = NormalizeLocation(Location),
                Description = Description
            };

            PSDataFactoryGateway response = DataFactoryClient.CreateOrUpdateGateway(ResourceGroupName, DataFactoryName, request);

            WriteObject(response);
        }
Пример #5
0
        public void CanThrowWhenCreateExistingGateway()
        {
            var expectedOutput = new PSDataFactoryGateway
            {
                Name        = GatewayName,
                Status      = GatewayStatus.Online,
                Description = "New gateway description for test"
            };

            dataFactoriesClientMock.Setup(f => f.GetGateway(ResourceGroupName, DataFactoryName, GatewayName))
            .Returns(expectedOutput)
            .Verifiable();

            _cmdlet.Name            = GatewayName;
            _cmdlet.DataFactoryName = DataFactoryName;

            Assert.Throws <PSInvalidOperationException>(() => _cmdlet.ExecuteCmdlet());

            dataFactoriesClientMock.Verify(f => f.CreateOrUpdateGateway(ResourceGroupName, DataFactoryName, It.IsAny <PSDataFactoryGateway>()),
                                           Times.Never());
        }
Пример #6
0
        public void CanGetGateway()
        {
            var expectedOutput = new PSDataFactoryGateway
            {
                Name   = GatewayName,
                Status = GatewayStatus.NeedRegistration
            };

            dataFactoriesClientMock.Setup(f => f.GetGateway(ResourceGroupName, DataFactoryName, GatewayName))
            .Returns(expectedOutput).Verifiable();

            _cmdlet.Name            = GatewayName;
            _cmdlet.DataFactoryName = DataFactoryName;

            _cmdlet.ExecuteCmdlet();

            // Assert
            dataFactoriesClientMock.VerifyAll();

            commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ByFactoryObject)
            {
                if (DataFactory == null)
                {
                    throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryArgumentInvalid));
                }

                DataFactoryName   = DataFactory.DataFactoryName;
                ResourceGroupName = DataFactory.ResourceGroupName;
            }

            PSDataFactoryGateway gateway = new PSDataFactoryGateway
            {
                Description = Description,
                Name        = Name
            };

            PSDataFactoryGateway response = DataFactoryClient.PatchGateway(ResourceGroupName, DataFactoryName, gateway);

            WriteObject(response);
        }
Пример #8
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ByFactoryObject)
            {
                if (DataFactory == null)
                {
                    throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryArgumentInvalid));
                }

                DataFactoryName   = DataFactory.DataFactoryName;
                ResourceGroupName = DataFactory.ResourceGroupName;
            }

            if (String.IsNullOrWhiteSpace(Name))
            {
                IEnumerable <PSDataFactoryGateway> gateways = DataFactoryClient.ListGateways(ResourceGroupName, DataFactoryName);
                WriteObject(gateways, true);
            }
            else
            {
                PSDataFactoryGateway gateway = DataFactoryClient.GetGateway(ResourceGroupName, DataFactoryName, Name);
                WriteObject(gateway);
            }
        }
Пример #9
0
        public virtual PSDataFactoryGateway PatchGateway(string resourceGroupName, string dataFactoryName, PSDataFactoryGateway gateway)
        {
            if (gateway == null)
            {
                throw new ArgumentNullException("gateway");
            }

            var response = DataPipelineManagementClient.Gateways.Update(
                resourceGroupName, dataFactoryName, new GatewayCreateOrUpdateParameters {
                Gateway = gateway.ToGatewayDefinition()
            });

            return(new PSDataFactoryGateway(response.Gateway));
        }
Пример #10
0
        public virtual PSDataFactoryGateway CreateOrUpdateGateway(string resourceGroupName, string dataFactoryName, PSDataFactoryGateway gateway)
        {
            if (gateway == null)
            {
                throw new ArgumentNullException("gateway");
            }

            var response = DataPipelineManagementClient.Gateways.CreateOrUpdate(
                resourceGroupName, dataFactoryName, new GatewayCreateOrUpdateParameters {
                Gateway = gateway.ToGatewayDefinition()
            });

            Gateway createdGateway = response.Gateway;

            if (createdGateway.Properties != null &&
                !DataFactoryCommonUtilities.IsSucceededProvisioningState(createdGateway.Properties.ProvisioningState))
            {
                // ToDo: service side should set the error message for provisioning failures.
                throw new ProvisioningFailedException(Resources.GatewayProvisioningFailed);
            }

            return(new PSDataFactoryGateway(createdGateway));
        }