public virtual PSTable CreatePSTable(CreatePSTableParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PSTable table = null; Action createTable = () => { table = new PSTable(CreateOrUpdateTable( parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name, parameters.RawJsonContent)) { ResourceGroupName = parameters.ResourceGroupName, DataFactoryName = parameters.DataFactoryName }; if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(table.ProvisioningState)) { string errorMessage = table.Properties == null ? string.Empty : table.Properties.ErrorMessage; throw new ProvisioningFailedException(errorMessage); } }; if (parameters.Force) { // If user decides to overwrite anyway, then there is no need to check if the table exists or not. createTable(); } else { bool tableExists = CheckTableExists(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name); parameters.ConfirmAction( !tableExists, // prompt only if the table exists string.Format( CultureInfo.InvariantCulture, Resources.TableExists, parameters.Name, parameters.DataFactoryName), string.Format( CultureInfo.InvariantCulture, Resources.TableCreating, parameters.Name, parameters.DataFactoryName), parameters.Name, createTable); } return(table); }
public void CanGetTable() { // Arrange PSTable expected = new PSTable() { TableName = tableName, DataFactoryName = DataFactoryName, ResourceGroupName = ResourceGroupName }; dataFactoriesClientMock .Setup( c => c.FilterPSTables( It.Is <TableFilterOptions>( options => options.ResourceGroupName == ResourceGroupName && options.DataFactoryName == DataFactoryName && options.Name == tableName))) .CallBase() .Verifiable(); dataFactoriesClientMock .Setup(c => c.GetTable(ResourceGroupName, DataFactoryName, tableName)) .Returns(expected) .Verifiable(); // Action cmdlet.Name = " "; Exception whiteSpace = Assert.Throws <PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = ""; Exception empty = Assert.Throws <PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = tableName; cmdlet.ExecuteCmdlet(); // Assert dataFactoriesClientMock.VerifyAll(); Assert.Contains("Value cannot be null", whiteSpace.Message); Assert.Contains("Value cannot be null", empty.Message); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); }
private bool CheckTableExists(string resourceGroupName, string dataFactoryName, string tableName) { // ToDo: implement HEAD to check if the table exists try { PSTable table = GetTable(resourceGroupName, dataFactoryName, tableName); return(true); } catch (CloudException e) { //Get throws Exception message with NotFound Status if (e.Response.StatusCode == HttpStatusCode.NotFound) { return(false); } else { throw; } } }