public void CanGetDataset() { // Arrange PSDataset expected = new PSDataset() { DatasetName = datasetName, DataFactoryName = DataFactoryName, ResourceGroupName = ResourceGroupName }; dataFactoriesClientMock .Setup( c => c.FilterPSDatasets( It.Is<DatasetFilterOptions>( options => options.ResourceGroupName == ResourceGroupName && options.DataFactoryName == DataFactoryName && options.Name == datasetName))) .CallBase() .Verifiable(); dataFactoriesClientMock .Setup(c => c.GetDataset(ResourceGroupName, DataFactoryName, datasetName)) .Returns(expected) .Verifiable(); // Action cmdlet.Name = " "; Exception whiteSpace = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = ""; Exception empty = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = datasetName; 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 PSDataset CreatePSDataset(CreatePSDatasetParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PSDataset dataset = null; Action createDataset = () => { dataset = new PSDataset(this.CreateOrUpdateDataset( parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name, parameters.RawJsonContent)) { ResourceGroupName = parameters.ResourceGroupName, DataFactoryName = parameters.DataFactoryName }; if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(dataset.ProvisioningState)) { string errorMessage = dataset.Properties == null ? string.Empty : dataset.Properties.ErrorMessage; throw new ProvisioningFailedException(errorMessage); } }; parameters.ConfirmAction( parameters.Force, // prompt only if the dataset exists string.Format( CultureInfo.InvariantCulture, Resources.DatasetExists, parameters.Name, parameters.DataFactoryName), string.Format( CultureInfo.InvariantCulture, Resources.DatasetCreating, parameters.Name, parameters.DataFactoryName), parameters.Name, createDataset, () => this.CheckDatasetExists(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name)); return dataset; }