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()); }
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 (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); } if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(table.ProvisioningState)) { string errorMessage = table.Properties == null ? string.Empty : table.Properties.ErrorMessage; throw new ProvisioningFailedException(errorMessage); } return table; }