From cb9371b0be7e700ae2d90d8e6507ca3f78f19551 Mon Sep 17 00:00:00 2001 From: Chaz Beck Date: Mon, 6 May 2019 17:55:09 -0700 Subject: [PATCH 1/5] Initial changes needed for adapting v3 of PBI SDK --- .../Commands.Common.Test/TestUtilities.cs | 12 ++ src/Common/Common.Api/Common.Api.csproj | 6 +- src/Common/Common.Api/Datasets/Dataset.cs | 31 ++--- .../Common.Api/Datasets/DatasetsClient.cs | 63 ++++++---- src/Common/Common.Api/Datasets/Datasource.cs | 4 +- .../Common.Api/Datasets/IDatasetsClient.cs | 4 +- .../Common.Api/Datasets/Relationship.cs | 20 +-- .../Common.Api/Helpers/EnumTypeConverter.cs | 114 ++++++++++++++++++ src/Common/Common.Api/Reports/Dashboard.cs | 2 +- .../Common.Api/Reports/IReportsClient.cs | 10 +- src/Common/Common.Api/Reports/Import.cs | 2 +- .../Reports/ImportConflictHandlerModeEnum.cs | 9 +- .../Reports/PositionConflictAction.cs | 13 ++ src/Common/Common.Api/Reports/Report.cs | 4 +- .../Common.Api/Reports/ReportsClient.cs | 59 ++++----- src/Common/Common.Api/Reports/Tile.cs | 6 +- .../Workspaces/IWorkspacesClient.cs | 14 +-- .../Common.Api/Workspaces/PrincipalType.cs | 14 +++ src/Common/Common.Api/Workspaces/Workspace.cs | 8 +- .../Common.Api/Workspaces/WorkspaceUser.cs | 31 ++++- .../Workspaces/WorkspaceUserAccessRight.cs | 1 + .../Common.Api/Workspaces/WorkspacesClient.cs | 28 ++--- .../Commands.Data.Test/AddPowerBIRowTests.cs | 4 +- .../GetPowerBIDatasourceTests.cs | 40 +++++- .../RemovePowerBIRowTests.cs | 4 +- .../Data/Commands.Data/AddPowerBIRow.cs | 13 +- .../Commands.Data/GetPowerBIDatasource.cs | 8 +- .../Data/Commands.Data/RemovePowerBIRow.cs | 13 +- .../CopyPowerBIReportTests.cs | 16 +-- .../CopyPowerBITileTests.cs | 6 +- .../Commands.Reports/CopyPowerBIReport.cs | 10 +- .../Commands.Reports/CopyPowerBITile.cs | 14 +-- .../help/Copy-PowerBIReport.md | 14 +-- .../Commands.Reports/help/Copy-PowerBITile.md | 32 ++--- .../AddPowerBIWorkspaceUserTests.cs | 34 ++---- .../GetPowerBIWorkspaceTests.cs | 74 ++++++------ .../RemovePowerBIWorkspaceUserTests.cs | 24 ++-- .../RestorePowerBIWorkspaceTests.cs | 16 +-- .../SetPowerBIWorkspaceTests.cs | 12 +- .../AddPowerBIWorkspaceUser.cs | 21 +++- .../GetPowerBIWorkspace.cs | 2 +- .../RemovePowerBIWorkspaceUser.cs | 10 +- .../RestorePowerBIWorkspace.cs | 5 +- .../SetPowerBIWorkspace.cs | 3 +- .../help/Add-PowerBIWorkspaceUser.md | 20 ++- 45 files changed, 532 insertions(+), 318 deletions(-) create mode 100644 src/Common/Common.Api/Helpers/EnumTypeConverter.cs create mode 100644 src/Common/Common.Api/Reports/PositionConflictAction.cs create mode 100644 src/Common/Common.Api/Workspaces/PrincipalType.cs diff --git a/src/Common/Commands.Common.Test/TestUtilities.cs b/src/Common/Commands.Common.Test/TestUtilities.cs index 6c69a73a..b7bfc134 100644 --- a/src/Common/Commands.Common.Test/TestUtilities.cs +++ b/src/Common/Commands.Common.Test/TestUtilities.cs @@ -30,6 +30,18 @@ public static void AssertExpectedUnitTestResults(object expectedResponse, Mock client, TestPowerBICmdletInitFactory initFactory) + { + Assert.IsFalse(initFactory.Logger.ErrorRecords.Any()); + var results = initFactory.Logger.Output?.ToList(); + if(results != null) + { + Assert.AreEqual(0, results.Count, "No output results were expected"); + } + + client.VerifyAll(); + } + public static string GetRandomString() { return Path.GetRandomFileName().Replace(".", ""); diff --git a/src/Common/Common.Api/Common.Api.csproj b/src/Common/Common.Api/Common.Api.csproj index b2e6c4b8..11c7057d 100644 --- a/src/Common/Common.Api/Common.Api.csproj +++ b/src/Common/Common.Api/Common.Api.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -8,8 +8,8 @@ - - + + diff --git a/src/Common/Common.Api/Datasets/Dataset.cs b/src/Common/Common.Api/Datasets/Dataset.cs index f64de0fd..286d4f3b 100644 --- a/src/Common/Common.Api/Datasets/Dataset.cs +++ b/src/Common/Common.Api/Datasets/Dataset.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.PowerBI.Common.Api.Helpers; namespace Microsoft.PowerBI.Common.Api.Datasets { @@ -14,7 +15,7 @@ public class Dataset public Guid Id { get; set; } public string Name { get; set; } public string ConfiguredBy { get; set; } - public string DefaultRetentionPolicy { get; set; } + public DefaultRetentionPolicy? DefaultRetentionPolicy { get; set; } public bool AddRowsApiEnabled { get; set; } public IEnumerable Tables { get; set; } public string WebUrl { get; set; } @@ -35,46 +36,40 @@ public static implicit operator Dataset(PowerBI.Api.V2.Models.Dataset dataset) return new Dataset { - Id = new Guid(dataset.Id), + Id = dataset.Id, Name = dataset.Name, ConfiguredBy = dataset.ConfiguredBy, - DefaultRetentionPolicy = dataset.DefaultRetentionPolicy, AddRowsApiEnabled = dataset.AddRowsAPIEnabled.GetValueOrDefault(), - Tables = dataset.Tables?.Select(t => (Table)t), WebUrl = dataset.WebUrl, - Relationships = dataset.Relationships?.Select(r => (Relationship)r), - Datasources = dataset.Datasources?.Select(d => (Datasource)d), - DefaultMode = ConvertDefaultMode(dataset.DefaultMode), IsRefreshable = dataset.IsRefreshable.GetValueOrDefault(), IsEffectiveIdentityRequired = dataset.IsEffectiveIdentityRequired.GetValueOrDefault(), IsOnPremGatewayRequired = dataset.IsOnPremGatewayRequired.GetValueOrDefault() }; } - public static PowerBI.Api.V2.Models.Dataset ConvertToDatasetV2Model(Dataset dataset) + public static PowerBI.Api.V2.Models.CreateDatasetRequest ConvertToDatasetRequest(Dataset dataset) { if (dataset == null) { return null; } - return new PowerBI.Api.V2.Models.Dataset + return new PowerBI.Api.V2.Models.CreateDatasetRequest { - Id = dataset.Id == Guid.Empty ? null : dataset.Id.ToString(), Name = dataset.Name, Tables = dataset.Tables?.Select(t => (PowerBI.Api.V2.Models.Table)t).ToList(), + Datasources = dataset.Datasources?.Select(d => (PowerBI.Api.V2.Models.Datasource)d).ToList(), + Relationships = dataset.Relationships?.Select(r => (PowerBI.Api.V2.Models.Relationship)r).ToList(), + DefaultMode = EnumTypeConverter.ConvertTo(dataset.DefaultMode) }; } - private static DatasetMode? ConvertDefaultMode(string defaultMode) - { - if(string.IsNullOrEmpty(defaultMode)) - { - return null; - } + } - return (DatasetMode)Enum.Parse(typeof(DatasetMode), defaultMode, true); - } + public enum DefaultRetentionPolicy + { + None, + BasicFIFO } public enum DatasetMode diff --git a/src/Common/Common.Api/Datasets/DatasetsClient.cs b/src/Common/Common.Api/Datasets/DatasetsClient.cs index 73678398..3f13238c 100644 --- a/src/Common/Common.Api/Datasets/DatasetsClient.cs +++ b/src/Common/Common.Api/Datasets/DatasetsClient.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Management.Automation; using Microsoft.PowerBI.Api.V2; +using Microsoft.PowerBI.Common.Api.Helpers; namespace Microsoft.PowerBI.Common.Api.Datasets { @@ -21,8 +22,8 @@ public DatasetsClient(IPowerBIClient client) : base(client) public object AddDataset(Dataset dataset, Guid? workspaceId = default) { var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.PostDatasetInGroup(groupId: workspaceId.Value.ToString(), dataset: Dataset.ConvertToDatasetV2Model(dataset)) : - this.Client.Datasets.PostDataset(dataset: Dataset.ConvertToDatasetV2Model(dataset)); + this.Client.Datasets.PostDatasetInGroup(groupId: workspaceId.Value, dataset: Dataset.ConvertToDatasetRequest(dataset), EnumTypeConverter.ConvertTo(dataset.DefaultRetentionPolicy)) : + this.Client.Datasets.PostDataset(dataset: Dataset.ConvertToDatasetRequest(dataset), EnumTypeConverter.ConvertTo(dataset.DefaultRetentionPolicy)); return result; } @@ -34,7 +35,7 @@ public IEnumerable GetDatasets() public IEnumerable GetDatasetsForWorkspace(Guid workspaceId) { - return this.Client.Datasets.GetDatasets(groupId: workspaceId.ToString()).Value?.Select(x => (Dataset)x); + return this.Client.Datasets.GetDatasets(groupId: workspaceId).Value?.Select(x => (Dataset)x); } public IEnumerable GetDatasetsAsAdmin(string filter = null, int? top = null, int? skip = null) @@ -44,40 +45,48 @@ public IEnumerable GetDatasetsAsAdmin(string filter = null, int? top = public IEnumerable GetDatasetsAsAdminForWorkspace(Guid workspaceId, string filter = null, int? top = null, int? skip = null) { - return this.Client.Datasets.GetDatasetsAsAdmin(groupId: workspaceId.ToString(), filter: filter, top: top, skip: skip).Value?.Select(x => (Dataset)x); + return this.Client.Datasets.GetDatasetsAsAdmin(groupId: workspaceId, filter: filter, top: top, skip: skip).Value?.Select(x => (Dataset)x); } public IEnumerable GetDatasources(Guid datasetId, Guid? workspaceId = default) { var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.GetDatasources(groupId: workspaceId.Value.ToString(), datasetKey: datasetId.ToString()) : - this.Client.Datasets.GetDatasources(datasetKey: datasetId.ToString()); + this.Client.Datasets.GetDatasources(groupId: workspaceId.Value, datasetId: datasetId) : + this.Client.Datasets.GetDatasources(datasetId: datasetId); return result.Value?.Select(x => (Datasource)x); } public IEnumerable GetDatasourcesAsAdmin(Guid datasetId) { - return this.Client.Datasets.GetDatasourcesAsAdmin(datasetId.ToString()).Value?.Select(x => (Datasource)x); + return this.Client.Datasets.GetDatasourcesAsAdmin(datasetId).Value?.Select(x => (Datasource)x); } public IEnumerable
GetTables(Guid datasetId, Guid? workspaceId = default) { var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.GetTables(groupId: workspaceId.Value.ToString(), datasetKey: datasetId.ToString()) : - this.Client.Datasets.GetTables(datasetKey: datasetId.ToString()); + this.Client.Datasets.GetTables(groupId: workspaceId.Value, datasetId: datasetId) : + this.Client.Datasets.GetTables(datasetId: datasetId); return result.Value?.Select(x => (Table)x); } public Table UpdateTable(Table table, Guid datasetId, Guid? workspaceId = null) { var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.PutTableInGroup(groupId: workspaceId.Value.ToString(), datasetKey: datasetId.ToString(), tableName: table.Name, (Microsoft.PowerBI.Api.V2.Models.Table)table) : - this.Client.Datasets.PutTable(datasetKey: datasetId.ToString(), tableName: table.Name, (Microsoft.PowerBI.Api.V2.Models.Table)table); - return result as Table; + this.Client.Datasets.PutTableInGroup(groupId: workspaceId.Value, datasetId: datasetId, tableName: table.Name, (Microsoft.PowerBI.Api.V2.Models.Table)table) : + this.Client.Datasets.PutTable(datasetId: datasetId, tableName: table.Name, (Microsoft.PowerBI.Api.V2.Models.Table)table); + + if (result != null) + { + return (Table)result; + } + else + { + return null; + } } - public object AddRows(string datasetId, string tableName, List rows, Guid? workspaceId = default) + public void AddRows(Guid datasetId, string tableName, List rows, Guid? workspaceId = null) { var hashRows = new List(); foreach (var row in rows) @@ -99,21 +108,27 @@ public object AddRows(string datasetId, string tableName, List rows, G } hashRows.Add(hashtable); } - var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.PostRowsInGroup(groupId: workspaceId.Value.ToString(), datasetKey: datasetId, tableName: tableName, requestMessage: hashRows) : - this.Client.Datasets.PostRows(datasetKey: datasetId, tableName: tableName, requestMessage: hashRows); - return result; + if(workspaceId.HasValue && workspaceId.Value != Guid.Empty) + { + this.Client.Datasets.PostRowsInGroup(groupId: workspaceId.Value, datasetId: datasetId, tableName: tableName, requestMessage: hashRows); + } + else + { + this.Client.Datasets.PostRows(datasetId: datasetId, tableName: tableName, requestMessage: hashRows); + } } - public object DeleteRows(string datasetId, string tableName, Guid? workspaceId = default) + public void DeleteRows(Guid datasetId, string tableName, Guid? workspaceId = default) { - - var result = workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Datasets.DeleteRowsInGroup(groupId: workspaceId.Value.ToString(), datasetKey: datasetId, tableName: tableName) : - this.Client.Datasets.DeleteRows(datasetKey: datasetId, tableName: tableName); - - return result; + if(workspaceId.HasValue && workspaceId.Value != default) + { + this.Client.Datasets.DeleteRowsInGroup(groupId: workspaceId.Value, datasetId: datasetId, tableName: tableName); + } + else + { + this.Client.Datasets.DeleteRows(datasetId: datasetId, tableName: tableName); + } } } } diff --git a/src/Common/Common.Api/Datasets/Datasource.cs b/src/Common/Common.Api/Datasets/Datasource.cs index 6c786920..9724fa83 100644 --- a/src/Common/Common.Api/Datasets/Datasource.cs +++ b/src/Common/Common.Api/Datasets/Datasource.cs @@ -13,8 +13,8 @@ public class Datasource public string ConnectionString { get; set; } public string DatasourceType { get; set; } public DatasourceConnectionDetails ConnectionDetails { get; set; } - public string GatewayId { get; set; } - public string DatasourceId { get; set; } + public Guid? GatewayId { get; set; } + public Guid? DatasourceId { get; set; } public static implicit operator Datasource(PowerBI.Api.V2.Models.Datasource datasource) { diff --git a/src/Common/Common.Api/Datasets/IDatasetsClient.cs b/src/Common/Common.Api/Datasets/IDatasetsClient.cs index 50375a15..6164e311 100644 --- a/src/Common/Common.Api/Datasets/IDatasetsClient.cs +++ b/src/Common/Common.Api/Datasets/IDatasetsClient.cs @@ -31,7 +31,7 @@ public interface IDatasetsClient Table UpdateTable(Table table, Guid datasetId, Guid? workspaceId = default); - object AddRows(string datasetId, string tableName, List rows, Guid? workspaceId = default); - object DeleteRows(string datasetId, string tableName, Guid? workspaceId = default); + void AddRows(Guid datasetId, string tableName, List rows, Guid? workspaceId = default); + void DeleteRows(Guid datasetId, string tableName, Guid? workspaceId = default); } } diff --git a/src/Common/Common.Api/Datasets/Relationship.cs b/src/Common/Common.Api/Datasets/Relationship.cs index 1e574aa2..96507982 100644 --- a/src/Common/Common.Api/Datasets/Relationship.cs +++ b/src/Common/Common.Api/Datasets/Relationship.cs @@ -4,13 +4,14 @@ */ using System; +using Microsoft.PowerBI.Common.Api.Helpers; namespace Microsoft.PowerBI.Common.Api.Datasets { public class Relationship { public string Name { get; set; } - public CrossFilteringBehaviorEnum CrossFilteringBehavior { get; set; } + public CrossFilteringBehaviorEnum? CrossFilteringBehavior { get; set; } public string FromTable { get; set; } public string FromColumn { get; set; } public string ToTable { get; set; } @@ -26,7 +27,7 @@ public static implicit operator Relationship(PowerBI.Api.V2.Models.Relationship return new Relationship { Name = relationship.Name, - CrossFilteringBehavior = ConvertCrossFilteringBehavior(relationship.CrossFilteringBehavior), + CrossFilteringBehavior = EnumTypeConverter.ConvertTo(relationship.CrossFilteringBehavior), FromTable = relationship.FromTable, FromColumn = relationship.FromColumn, ToTable = relationship.ToTable, @@ -44,30 +45,19 @@ public static implicit operator PowerBI.Api.V2.Models.Relationship(Relationship return new PowerBI.Api.V2.Models.Relationship { Name = relationship.Name, - CrossFilteringBehavior = (PowerBI.Api.V2.Models.CrossFilteringBehaviorEnum)Enum.Parse(typeof(PowerBI.Api.V2.Models.CrossFilteringBehaviorEnum), relationship.CrossFilteringBehavior.ToString(), true), + CrossFilteringBehavior = EnumTypeConverter.ConvertTo(relationship.CrossFilteringBehavior), FromTable = relationship.FromTable, FromColumn = relationship.FromColumn, ToTable = relationship.ToTable, ToColumn = relationship.ToColumn }; } - - private static CrossFilteringBehaviorEnum ConvertCrossFilteringBehavior(PowerBI.Api.V2.Models.CrossFilteringBehaviorEnum? crossFilteringBehavior) - { - if(crossFilteringBehavior == null) - { - return CrossFilteringBehaviorEnum.NotAvailable; - } - - return (CrossFilteringBehaviorEnum)Enum.Parse(typeof(CrossFilteringBehaviorEnum), crossFilteringBehavior.Value.ToString(), true); - } } public enum CrossFilteringBehaviorEnum { OneDirection, BothDirections, - Automatic, - NotAvailable + Automatic } } diff --git a/src/Common/Common.Api/Helpers/EnumTypeConverter.cs b/src/Common/Common.Api/Helpers/EnumTypeConverter.cs new file mode 100644 index 00000000..1a353075 --- /dev/null +++ b/src/Common/Common.Api/Helpers/EnumTypeConverter.cs @@ -0,0 +1,114 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +using System; + +namespace Microsoft.PowerBI.Common.Api.Helpers +{ + public static class EnumTypeConverter + { + public static T ConvertTo(V value) + where T : struct, IConvertible + where V : struct, IConvertible + { + if(!typeof(T).IsEnum) + { + throw new ArgumentException("T must be an Enum"); + } + + if (!typeof(V).IsEnum) + { + throw new ArgumentException("V must be an Enum"); + } + + string valueAsString = value.ToString(); + return (T)Enum.Parse(typeof(T), valueAsString); + } + + public static T ConvertTo(V value, T returnIfParseFails) + where T : struct, IConvertible + where V : struct, IConvertible + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException("T must be an Enum"); + } + + if (!typeof(V).IsEnum) + { + throw new ArgumentException("V must be an Enum"); + } + + string valueAsString = value.ToString(); + if(Enum.TryParse(valueAsString, out T result)) + { + return result; + } + + return returnIfParseFails; + } + + public static Nullable ConvertTo(Nullable value) + where T : struct, IConvertible + where V : struct, IConvertible + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException("T must be an Enum"); + } + + if (!typeof(V).IsEnum) + { + throw new ArgumentException("V must be an Enum"); + } + + if(!value.HasValue) + { + return null; + } + + string valueAsString = value.ToString(); + if(string.IsNullOrEmpty(valueAsString)) + { + return null; + } + + return (T)Enum.Parse(typeof(T), valueAsString); + } + + public static Nullable ConvertTo(Nullable value, Nullable returnIfParseFails) + where T : struct, IConvertible + where V : struct, IConvertible + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException("T must be an Enum"); + } + + if (!typeof(V).IsEnum) + { + throw new ArgumentException("V must be an Enum"); + } + + if (!value.HasValue) + { + return null; + } + + string valueAsString = value.ToString(); + if (string.IsNullOrEmpty(valueAsString)) + { + return null; + } + + if(Enum.TryParse(valueAsString, out T result)) + { + return result; + } + + return returnIfParseFails; + } + } +} diff --git a/src/Common/Common.Api/Reports/Dashboard.cs b/src/Common/Common.Api/Reports/Dashboard.cs index 4676db51..65c9b713 100644 --- a/src/Common/Common.Api/Reports/Dashboard.cs +++ b/src/Common/Common.Api/Reports/Dashboard.cs @@ -18,7 +18,7 @@ public static implicit operator Dashboard(PowerBI.Api.V2.Models.Dashboard dashbo { return new Dashboard() { - Id = new Guid(dashboard.Id), + Id = dashboard.Id, Name = dashboard.DisplayName, IsReadOnly = dashboard.IsReadOnly, EmbedUrl = dashboard.EmbedUrl diff --git a/src/Common/Common.Api/Reports/IReportsClient.cs b/src/Common/Common.Api/Reports/IReportsClient.cs index 43c411d1..74dcda64 100644 --- a/src/Common/Common.Api/Reports/IReportsClient.cs +++ b/src/Common/Common.Api/Reports/IReportsClient.cs @@ -45,18 +45,18 @@ public interface IReportsClient IEnumerable GetImportsForWorkspace(Guid workspaceId); - Guid PostImport(string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum nameConflict); + Guid PostImport(string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum? nameConflict); - Guid PostImportForWorkspace(Guid workspaceId, string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum nameConflict); + Guid PostImportForWorkspace(Guid workspaceId, string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum? nameConflict); Report PostReport(string reportName, string filePath, ImportConflictHandlerModeEnum nameConflict, int timeout); - Report PostReportForWorkspace(Guid workspaceId, string reportName, string filePath, ImportConflictHandlerModeEnum nameConflict, int timeout); + Report PostReportForWorkspace(Guid workspaceId, string reportName, string filePath, ImportConflictHandlerModeEnum? nameConflict, int timeout); - Report CopyReport(string reportName, string sourceWorkspaceId, string sourceReportId, string targetWorkspaceId, string targetDatasetId); + Report CopyReport(string reportName, Guid? sourceWorkspaceId, Guid sourceReportId, Guid? targetWorkspaceId, Guid? targetDatasetId); Dashboard AddDashboard(string dashboardName, Guid workspaceId); - Tile CopyTile(Guid workspaceId, string dashboardKey, string tileKey, string targetDashboardId, string targetWorkspaceId, string targetReportId, string targetModelId, string positionConflictAction); + Tile CopyTile(Guid workspaceId, Guid dashboardKey, Guid tileKey, Guid targetDashboardId, Guid? targetWorkspaceId, Guid? targetReportId, Guid? targetModelId, PositionConflictAction? positionConflictAction); } } diff --git a/src/Common/Common.Api/Reports/Import.cs b/src/Common/Common.Api/Reports/Import.cs index 5dfc7efe..692d4fad 100644 --- a/src/Common/Common.Api/Reports/Import.cs +++ b/src/Common/Common.Api/Reports/Import.cs @@ -24,7 +24,7 @@ public static implicit operator Import(PowerBI.Api.V2.Models.Import import) { return new Import { - Id = new Guid(import.Id), + Id = import.Id, Name = import.Name, ImportState = import.ImportState, Reports = import.Reports?.Select(x => (Report)x), diff --git a/src/Common/Common.Api/Reports/ImportConflictHandlerModeEnum.cs b/src/Common/Common.Api/Reports/ImportConflictHandlerModeEnum.cs index 4d38b2ae..5d429b3b 100644 --- a/src/Common/Common.Api/Reports/ImportConflictHandlerModeEnum.cs +++ b/src/Common/Common.Api/Reports/ImportConflictHandlerModeEnum.cs @@ -1,4 +1,10 @@ - +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +using System; + namespace Microsoft.PowerBI.Common.Api.Reports { @@ -9,5 +15,4 @@ public enum ImportConflictHandlerModeEnum Overwrite, CreateOrOverwrite } - } \ No newline at end of file diff --git a/src/Common/Common.Api/Reports/PositionConflictAction.cs b/src/Common/Common.Api/Reports/PositionConflictAction.cs new file mode 100644 index 00000000..5c1e2f0e --- /dev/null +++ b/src/Common/Common.Api/Reports/PositionConflictAction.cs @@ -0,0 +1,13 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +namespace Microsoft.PowerBI.Common.Api.Reports +{ + public enum PositionConflictAction + { + Tail, + Abort + } +} diff --git a/src/Common/Common.Api/Reports/Report.cs b/src/Common/Common.Api/Reports/Report.cs index eb7a869f..7531bac9 100644 --- a/src/Common/Common.Api/Reports/Report.cs +++ b/src/Common/Common.Api/Reports/Report.cs @@ -17,13 +17,13 @@ public class Report public string EmbedUrl { get; set; } - public string DatasetId { get; set; } + public Guid? DatasetId { get; set; } public static implicit operator Report(PowerBI.Api.V2.Models.Report report) { return new Report { - Id = new Guid(report.Id), + Id = report.Id, Name = report.Name, WebUrl = report.WebUrl, EmbedUrl = report.EmbedUrl, diff --git a/src/Common/Common.Api/Reports/ReportsClient.cs b/src/Common/Common.Api/Reports/ReportsClient.cs index 3b6a5a16..e38e199f 100644 --- a/src/Common/Common.Api/Reports/ReportsClient.cs +++ b/src/Common/Common.Api/Reports/ReportsClient.cs @@ -9,6 +9,7 @@ using System.Linq; using Microsoft.PowerBI.Api.V2; using Microsoft.PowerBI.Api.V2.Models; +using Microsoft.PowerBI.Common.Api.Helpers; namespace Microsoft.PowerBI.Common.Api.Reports { @@ -25,24 +26,24 @@ public IEnumerable GetReports() public IEnumerable GetReportsAsAdmin(string filter = null, int? top = null, int? skip = null) { - return this.Client.Reports.GetReportsAsAdmin(filter: filter, top: top, skip: skip).Value?.Select(x => (Report)x); + return this.Client.Reports.GetReportsAsAdmin(Guid.Empty, filter: filter, top: top, skip: skip).Value?.Select(x => (Report)x); } public IEnumerable GetReportsAsAdminForWorkspace(Guid workspaceId, string filter = null, int? top = null, int? skip = null) { - return this.Client.Reports.GetReportsAsAdmin(groupId: workspaceId.ToString(), filter: filter, top: top, skip: skip).Value?.Select(x => (Report)x); + return this.Client.Reports.GetReportsAsAdmin(groupId: workspaceId, filter: filter, top: top, skip: skip).Value?.Select(x => (Report)x); } public IEnumerable GetReportsForWorkspace(Guid workspaceId) { - return this.Client.Reports.GetReports(groupId: workspaceId.ToString()).Value?.Select(x => (Report)x); + return this.Client.Reports.GetReports(groupId: workspaceId).Value?.Select(x => (Report)x); } public Stream ExportReport(Guid reportId, Guid? workspaceId = default) { return workspaceId.HasValue && workspaceId.Value != default ? - this.Client.Reports.ExportReport(groupId: workspaceId.Value.ToString(), reportKey: reportId.ToString()) : - this.Client.Reports.ExportReport(reportKey: reportId.ToString()); + this.Client.Reports.ExportReport(groupId: workspaceId.Value, reportId: reportId) : + this.Client.Reports.ExportReport(reportId: reportId); } public IEnumerable GetDashboards() @@ -57,37 +58,37 @@ public IEnumerable GetDashboardsAsAdmin(string filter = default, int? public IEnumerable GetDashboardsForWorkspace(Guid workspaceId) { - return this.Client.Dashboards.GetDashboards(groupId: workspaceId.ToString()).Value?.Select(x => (Dashboard)x); + return this.Client.Dashboards.GetDashboards(groupId: workspaceId).Value?.Select(x => (Dashboard)x); } public IEnumerable GetDashboardsAsAdminForWorkspace(Guid workspaceId, string filter = default, int? top = default, int? skip = default) { - return this.Client.Dashboards.GetDashboardsAsAdmin(groupId: workspaceId.ToString(), filter: filter, top: top, skip: skip).Value?.Select(x => (Dashboard)x); + return this.Client.Dashboards.GetDashboardsAsAdmin(groupId: workspaceId, filter: filter, top: top, skip: skip).Value?.Select(x => (Dashboard)x); } public IEnumerable GetTiles(Guid dashboardId) { - return this.Client.Dashboards.GetTiles(dashboardKey: dashboardId.ToString()).Value?.Select(x => (Tile)x); + return this.Client.Dashboards.GetTiles(dashboardId: dashboardId).Value?.Select(x => (Tile)x); } public IEnumerable GetTilesAsAdmin(Guid dashboardId) { - return this.Client.Dashboards.GetTilesAsAdmin(dashboardKey: dashboardId.ToString()).Value?.Select(x => (Tile)x); + return this.Client.Dashboards.GetTilesAsAdmin(dashboardId: dashboardId).Value?.Select(x => (Tile)x); } public IEnumerable GetTilesForWorkspace(Guid workspaceId, Guid dashboardId) { - return this.Client.Dashboards.GetTiles(groupId: workspaceId.ToString(), dashboardKey: dashboardId.ToString()).Value?.Select(x => (Tile)x); + return this.Client.Dashboards.GetTiles(groupId: workspaceId, dashboardId: dashboardId).Value?.Select(x => (Tile)x); } public Import GetImport(Guid importId) { - return this.Client.Imports.GetImportById(importId: importId.ToString()); + return this.Client.Imports.GetImport(importId: importId); } public Import GetImportForWorkspace(Guid workspaceId, Guid importId) { - return this.Client.Imports.GetImportByIdInGroup(groupId: workspaceId.ToString(), importId: importId.ToString()); + return this.Client.Imports.GetImportInGroup(groupId: workspaceId, importId: importId); } public IEnumerable GetImports() @@ -102,33 +103,33 @@ public IEnumerable GetImportsAsAdmin(string expand = default, string fil public IEnumerable GetImportsForWorkspace(Guid workspaceId) { - return this.Client.Imports.GetImports(groupId: workspaceId.ToString()).Value?.Select(x => (Import)x); + return this.Client.Imports.GetImports(groupId: workspaceId).Value?.Select(x => (Import)x); } - public Guid PostImport(string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum nameConflict) + public Guid PostImport(string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum? nameConflict) { using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { var response = this.Client.Imports.PostImportWithFile( fileStream: fileStream, datasetDisplayName: datasetDisplayName, - nameConflict: nameConflict.ToString() + nameConflict: EnumTypeConverter.ConvertTo(nameConflict) ); - return Guid.Parse(response.Id); + return response.Id; } } - public Guid PostImportForWorkspace(Guid workspaceId, string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum nameConflict) + public Guid PostImportForWorkspace(Guid workspaceId, string datasetDisplayName, string filePath, ImportConflictHandlerModeEnum? nameConflict) { using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { var response = this.Client.Imports.PostImportWithFileInGroup( - groupId: workspaceId.ToString(), + groupId: workspaceId, fileStream: fileStream, datasetDisplayName: datasetDisplayName, - nameConflict: nameConflict.ToString() + nameConflict: EnumTypeConverter.ConvertTo(nameConflict) ); - return Guid.Parse(response.Id); + return response.Id; } } @@ -169,7 +170,7 @@ public Report PostReport(string reportName, string filePath, ImportConflictHandl return import.Reports.Single(); } - public Report PostReportForWorkspace(Guid workspaceId, string reportName, string filePath, ImportConflictHandlerModeEnum nameConflict, int timeout) + public Report PostReportForWorkspace(Guid workspaceId, string reportName, string filePath, ImportConflictHandlerModeEnum? nameConflict, int timeout) { var importId = this.PostImportForWorkspace(workspaceId, reportName, filePath, nameConflict); @@ -206,7 +207,7 @@ public Report PostReportForWorkspace(Guid workspaceId, string reportName, string return import.Reports.Single(); } - public Report CopyReport(string reportName, string sourceWorkspaceId, string sourceReportId, string targetWorkspaceId, string targetDatasetId) + public Report CopyReport(string reportName, Guid? sourceWorkspaceId, Guid sourceReportId, Guid? targetWorkspaceId, Guid? targetDatasetId) { var requestBody = new CloneReportRequest() { @@ -215,9 +216,9 @@ public Report CopyReport(string reportName, string sourceWorkspaceId, string sou TargetWorkspaceId = targetWorkspaceId }; - return string.IsNullOrWhiteSpace(sourceWorkspaceId) ? - this.Client.Reports.CloneReport(sourceReportId, requestBody) : - this.Client.Reports.CloneReport(sourceWorkspaceId, sourceReportId, requestBody); + return sourceWorkspaceId.HasValue ? + this.Client.Reports.CloneReport(reportId: sourceReportId, requestBody) : + this.Client.Reports.CloneReport(groupId: sourceWorkspaceId.Value, reportId: sourceReportId, requestBody); } public Dashboard AddDashboard(string dashboardName, Guid workspaceId) @@ -229,14 +230,14 @@ public Dashboard AddDashboard(string dashboardName, Guid workspaceId) return workspaceId.Equals(Guid.Empty) ? this.Client.Dashboards.AddDashboard(requestBody) : - this.Client.Dashboards.AddDashboard(workspaceId.ToString(), requestBody); + this.Client.Dashboards.AddDashboard(groupId: workspaceId, requestBody); } - public Tile CopyTile(Guid workspaceId, string dashboardKey, string tileKey, string targetDashboardId, string targetWorkspaceId, string targetReportId, string targetModelId, string positionConflictAction) + public Tile CopyTile(Guid workspaceId, Guid dashboardKey, Guid tileKey, Guid targetDashboardId, Guid? targetWorkspaceId, Guid? targetReportId, Guid? targetModelId, PositionConflictAction? positionConflictAction) { var requestParameters = new CloneTileRequest() { - PositionConflictAction = positionConflictAction, + PositionConflictAction = EnumTypeConverter.ConvertTo(positionConflictAction), TargetDashboardId = targetDashboardId, TargetModelId = targetModelId, TargetReportId = targetReportId, @@ -245,7 +246,7 @@ public Tile CopyTile(Guid workspaceId, string dashboardKey, string tileKey, stri return workspaceId.Equals(Guid.Empty) ? this.Client.Dashboards.CloneTile(dashboardKey, tileKey, requestParameters) : - this.Client.Dashboards.CloneTile(workspaceId.ToString(), dashboardKey, tileKey, requestParameters); + this.Client.Dashboards.CloneTile(groupId: workspaceId, dashboardKey, tileKey, requestParameters); } } } diff --git a/src/Common/Common.Api/Reports/Tile.cs b/src/Common/Common.Api/Reports/Tile.cs index 1121529a..9c39c91d 100644 --- a/src/Common/Common.Api/Reports/Tile.cs +++ b/src/Common/Common.Api/Reports/Tile.cs @@ -15,14 +15,14 @@ public class Tile public int? ColumnSpan { get; set; } public string EmbedUrl { get; set; } public string EmbedData { get; set; } - public string ReportId { get; set; } - public string DatasetId { get; set; } + public Guid? ReportId { get; set; } + public Guid? DatasetId { get; set; } public static implicit operator Tile(PowerBI.Api.V2.Models.Tile tile) { return new Tile() { - Id = new Guid(tile.Id), + Id = tile.Id, Title = tile.Title, RowSpan = tile.RowSpan, ColumnSpan = tile.ColSpan, diff --git a/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs b/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs index 3eca8428..fe667b3f 100644 --- a/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs +++ b/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs @@ -10,21 +10,21 @@ namespace Microsoft.PowerBI.Common.Api.Workspaces { public interface IWorkspacesClient { - object AddWorkspaceUser(Guid workspaceId, WorkspaceUser userAccessRight); + void AddWorkspaceUser(Guid workspaceId, WorkspaceUser userAccessRight); - object AddWorkspaceUserAsAdmin(Guid workspaceId, WorkspaceUser userAccessRight); + void AddWorkspaceUserAsAdmin(Guid workspaceId, WorkspaceUser userAccessRight); IEnumerable GetWorkspaces(string filter = default, int? top = default, int? skip = default); - IEnumerable GetWorkspacesAsAdmin(string expand = default, string filter = default, int? top = default, int? skip = default); + IEnumerable GetWorkspacesAsAdmin(int top, string expand = default, string filter = default, int? skip = default); - object UpdateWorkspaceAsAdmin(Guid workspaceId, Workspace updatedProperties); + void UpdateWorkspaceAsAdmin(Guid workspaceId, Workspace updatedProperties); - object RestoreDeletedWorkspaceAsAdmin(Guid workspaceId, WorkspaceRestoreRequest restoreRequest); + void RestoreDeletedWorkspaceAsAdmin(Guid workspaceId, WorkspaceRestoreRequest restoreRequest); - object RemoveWorkspaceUser(Guid workspaceId, string userPrincipalName); + void RemoveWorkspaceUser(Guid workspaceId, string userPrincipalName); - object RemoveWorkspaceUserAsAdmin(Guid workspaceId, string userPrincipalName); + void RemoveWorkspaceUserAsAdmin(Guid workspaceId, string userPrincipalName); object NewWorkspaceAsUser(string workspaceName); diff --git a/src/Common/Common.Api/Workspaces/PrincipalType.cs b/src/Common/Common.Api/Workspaces/PrincipalType.cs new file mode 100644 index 00000000..e29dc852 --- /dev/null +++ b/src/Common/Common.Api/Workspaces/PrincipalType.cs @@ -0,0 +1,14 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +namespace Microsoft.PowerBI.Common.Api.Workspaces +{ + public enum PrincipalType + { + User, + Group, + App + } +} diff --git a/src/Common/Common.Api/Workspaces/Workspace.cs b/src/Common/Common.Api/Workspaces/Workspace.cs index eb909499..4a2ced29 100644 --- a/src/Common/Common.Api/Workspaces/Workspace.cs +++ b/src/Common/Common.Api/Workspaces/Workspace.cs @@ -20,7 +20,7 @@ public class Workspace public bool? IsOnDedicatedCapacity { get; set; } - public string CapacityId { get; set; } + public Guid? CapacityId { get; set; } public string Description { get; set; } @@ -47,7 +47,7 @@ public static implicit operator Workspace(Group group) { return new Workspace { - Id = new Guid(group.Id), + Id = group.Id, Name = group.Name, IsReadOnly = group.IsReadOnly, IsOnDedicatedCapacity = group.IsOnDedicatedCapacity, @@ -63,7 +63,7 @@ public static implicit operator Group(Workspace workspace) { return new Group { - Id = workspace.Id.ToString(), + Id = workspace.Id, Name = workspace.Name, IsReadOnly = workspace.IsReadOnly, IsOnDedicatedCapacity = workspace.IsOnDedicatedCapacity, @@ -71,7 +71,7 @@ public static implicit operator Group(Workspace workspace) Description = workspace.Description, Type = workspace.Type, State = workspace.State, - Users = workspace.Users?.Select(x => (GroupUserAccessRight)x).ToList() + Users = workspace.Users?.Select(x => (Microsoft.PowerBI.Api.V2.Models.GroupUser)x).ToList() }; } } diff --git a/src/Common/Common.Api/Workspaces/WorkspaceUser.cs b/src/Common/Common.Api/Workspaces/WorkspaceUser.cs index e753261a..eb25e226 100644 --- a/src/Common/Common.Api/Workspaces/WorkspaceUser.cs +++ b/src/Common/Common.Api/Workspaces/WorkspaceUser.cs @@ -4,23 +4,44 @@ */ using Microsoft.PowerBI.Api.V2.Models; +using Microsoft.PowerBI.Common.Api.Helpers; namespace Microsoft.PowerBI.Common.Api.Workspaces { public class WorkspaceUser { - public string AccessRight { get; set; } + public WorkspaceUserAccessRight AccessRight { get; set; } public string UserPrincipalName { get; set; } - public static implicit operator WorkspaceUser(GroupUserAccessRight groupUserAccessRight) + public string DisplayName { get; set; } + + public string Identifier { get; set; } + + public PrincipalType? PrincipalType { get; set; } + + public static implicit operator WorkspaceUser(Microsoft.PowerBI.Api.V2.Models.GroupUser groupUser) { - return new WorkspaceUser { AccessRight = groupUserAccessRight.GroupUserAccessRightProperty, UserPrincipalName = groupUserAccessRight.EmailAddress }; + return new WorkspaceUser + { + AccessRight = EnumTypeConverter.ConvertTo(groupUser.GroupUserAccessRight), + UserPrincipalName = groupUser.EmailAddress, + DisplayName = groupUser.DisplayName, + Identifier = groupUser.Identifier, + PrincipalType = EnumTypeConverter.ConvertTo(groupUser.PrincipalType) + }; } - public static implicit operator GroupUserAccessRight(WorkspaceUser workspaceUser) + public static implicit operator Microsoft.PowerBI.Api.V2.Models.GroupUser(WorkspaceUser workspaceUser) { - return new GroupUserAccessRight { GroupUserAccessRightProperty = workspaceUser.AccessRight, EmailAddress = workspaceUser.UserPrincipalName }; + return new Microsoft.PowerBI.Api.V2.Models.GroupUser + { + GroupUserAccessRight = EnumTypeConverter.ConvertTo(workspaceUser.AccessRight), + EmailAddress = workspaceUser.UserPrincipalName, + DisplayName = workspaceUser.DisplayName, + Identifier = workspaceUser.Identifier, + PrincipalType = EnumTypeConverter.ConvertTo(workspaceUser.PrincipalType) + }; } } } diff --git a/src/Common/Common.Api/Workspaces/WorkspaceUserAccessRight.cs b/src/Common/Common.Api/Workspaces/WorkspaceUserAccessRight.cs index 6facbe09..0489c390 100644 --- a/src/Common/Common.Api/Workspaces/WorkspaceUserAccessRight.cs +++ b/src/Common/Common.Api/Workspaces/WorkspaceUserAccessRight.cs @@ -7,6 +7,7 @@ namespace Microsoft.PowerBI.Common.Api.Workspaces { public enum WorkspaceUserAccessRight { + None, Member, Admin, Contributor diff --git a/src/Common/Common.Api/Workspaces/WorkspacesClient.cs b/src/Common/Common.Api/Workspaces/WorkspacesClient.cs index 4ac2b4bb..035bcdc1 100644 --- a/src/Common/Common.Api/Workspaces/WorkspacesClient.cs +++ b/src/Common/Common.Api/Workspaces/WorkspacesClient.cs @@ -16,14 +16,14 @@ public WorkspacesClient(IPowerBIClient client) : base(client) { } - public object AddWorkspaceUser(Guid workspaceId, WorkspaceUser userAccessRight) + public void AddWorkspaceUser(Guid workspaceId, WorkspaceUser userAccessRight) { - return this.Client.Groups.AddGroupUser(workspaceId.ToString(), userAccessRight); + this.Client.Groups.AddGroupUser(workspaceId, userAccessRight); } - public object AddWorkspaceUserAsAdmin(Guid workspaceId, WorkspaceUser userAccessRight) + public void AddWorkspaceUserAsAdmin(Guid workspaceId, WorkspaceUser userAccessRight) { - return this.Client.Groups.AddUserAsAdmin(workspaceId.ToString(), userAccessRight); + this.Client.Groups.AddUserAsAdmin(workspaceId, userAccessRight); } public IEnumerable GetWorkspaces(string filter = null, int? top = null, int? skip = null) @@ -31,29 +31,29 @@ public IEnumerable GetWorkspaces(string filter = null, int? top = nul return this.Client.Groups.GetGroups(filter, top, skip).Value.Select(x => (Workspace)x); } - public IEnumerable GetWorkspacesAsAdmin(string expand = null, string filter = null, int? top = null, int? skip = null) + public IEnumerable GetWorkspacesAsAdmin(int top, string expand = null, string filter = null, int? skip = null) { - return this.Client.Groups.GetGroupsAsAdmin(expand, filter, top, skip).Value.Select(x => (Workspace)x); + return this.Client.Groups.GetGroupsAsAdmin(top, expand, filter, skip).Value.Select(x => (Workspace)x); } - public object RemoveWorkspaceUser(Guid workspaceId, string userPrincipalName) + public void RemoveWorkspaceUser(Guid workspaceId, string userPrincipalName) { - return this.Client.Groups.DeleteUserInGroup(workspaceId.ToString(), userPrincipalName); + this.Client.Groups.DeleteUserInGroup(workspaceId, userPrincipalName); } - public object RemoveWorkspaceUserAsAdmin(Guid workspaceId, string userPrincipalName) + public void RemoveWorkspaceUserAsAdmin(Guid workspaceId, string userPrincipalName) { - return this.Client.Groups.DeleteUserAsAdmin(workspaceId.ToString(), userPrincipalName); + this.Client.Groups.DeleteUserAsAdmin(workspaceId, userPrincipalName); } - public object RestoreDeletedWorkspaceAsAdmin(Guid workspaceId, WorkspaceRestoreRequest restoreRequest) + public void RestoreDeletedWorkspaceAsAdmin(Guid workspaceId, WorkspaceRestoreRequest restoreRequest) { - return this.Client.Groups.RestoreDeletedGroupAsAdmin(workspaceId.ToString(), restoreRequest); + this.Client.Groups.RestoreDeletedGroupAsAdmin(workspaceId, restoreRequest); } - public object UpdateWorkspaceAsAdmin(Guid workspaceId, Workspace updatedProperties) + public void UpdateWorkspaceAsAdmin(Guid workspaceId, Workspace updatedProperties) { - return this.Client.Groups.UpdateGroupAsAdmin(workspaceId.ToString(), updatedProperties); + this.Client.Groups.UpdateGroupAsAdmin(workspaceId, updatedProperties); } public object NewWorkspaceAsUser(string workspaceName) diff --git a/src/Modules/Data/Commands.Data.Test/AddPowerBIRowTests.cs b/src/Modules/Data/Commands.Data.Test/AddPowerBIRowTests.cs index 1b02b790..113ce6b2 100644 --- a/src/Modules/Data/Commands.Data.Test/AddPowerBIRowTests.cs +++ b/src/Modules/Data/Commands.Data.Test/AddPowerBIRowTests.cs @@ -159,7 +159,7 @@ public void AddPowerBIRows_DatasetIdParameterSetName() rows.Add(row1); rows.Add(row2); var client = new Mock(); - client.Setup(x => x.Datasets.AddRows(datasetId.ToString(), table.Name, rows, null)).Returns(null); + client.Setup(x => x.Datasets.AddRows(datasetId, table.Name, rows, null)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new AddPowerBIRow(initFactory); @@ -171,7 +171,7 @@ public void AddPowerBIRows_DatasetIdParameterSetName() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(null, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } } } diff --git a/src/Modules/Data/Commands.Data.Test/GetPowerBIDatasourceTests.cs b/src/Modules/Data/Commands.Data.Test/GetPowerBIDatasourceTests.cs index 85f057cb..12661912 100644 --- a/src/Modules/Data/Commands.Data.Test/GetPowerBIDatasourceTests.cs +++ b/src/Modules/Data/Commands.Data.Test/GetPowerBIDatasourceTests.cs @@ -143,7 +143,15 @@ public void GetPowerBIDatasourceIndividualScope_ListParameterSet() { // Arrange var datasetId = Guid.NewGuid(); - var expectedDatasources = new List { new Datasource { DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString() } }; + var expectedDatasources = new List + { + new Datasource + { + DatasourceId = Guid.NewGuid(), + Name = "TestDatasource", + GatewayId = Guid.NewGuid() + } + }; var client = new Mock(); client.Setup(x => x.Datasets.GetDatasources(datasetId, null)).Returns(expectedDatasources); var initFactory = new TestPowerBICmdletInitFactory(client.Object); @@ -167,7 +175,15 @@ public void GetPowerBIDatasourceIndividualScopeAndWorkspaceId_ListParameterSet() // Arrange var datasetId = Guid.NewGuid(); var workspaceId = Guid.NewGuid(); - var expectedDatasources = new List { new Datasource { DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString() } }; + var expectedDatasources = new List + { + new Datasource + { + DatasourceId = Guid.NewGuid(), + Name = "TestDatasource", + GatewayId = Guid.NewGuid() + } + }; var client = new Mock(); client.Setup(x => x.Datasets.GetDatasources(datasetId, workspaceId)).Returns(expectedDatasources); var initFactory = new TestPowerBICmdletInitFactory(client.Object); @@ -191,7 +207,15 @@ public void GetPowerBIDatasourceOrganizationScope_ListParameterSet() { // Arrange var datasetId = Guid.NewGuid(); - var expectedDatasources = new List { new Datasource { DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString() } }; + var expectedDatasources = new List + { + new Datasource + { + DatasourceId = Guid.NewGuid(), + Name = "TestDatasource", + GatewayId = Guid.NewGuid() + } + }; var client = new Mock(); client.Setup(x => x.Datasets.GetDatasourcesAsAdmin(datasetId)).Returns(expectedDatasources); var initFactory = new TestPowerBICmdletInitFactory(client.Object); @@ -214,7 +238,15 @@ public void GetPowerBIDatasourceIndividualScope_ObjectAndListParameterSet() { // Arrange var testDataset = new Dataset { Id = Guid.NewGuid(), Name = "TestDataset" }; - var expectedDatasources = new List { new Datasource { DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString() } }; + var expectedDatasources = new List + { + new Datasource + { + DatasourceId = Guid.NewGuid(), + Name = "TestDatasource", + GatewayId = Guid.NewGuid() + } + }; var client = new Mock(); client.Setup(x => x.Datasets.GetDatasources(testDataset.Id, null)).Returns(expectedDatasources); var initFactory = new TestPowerBICmdletInitFactory(client.Object); diff --git a/src/Modules/Data/Commands.Data.Test/RemovePowerBIRowTests.cs b/src/Modules/Data/Commands.Data.Test/RemovePowerBIRowTests.cs index f0b1f3e5..0d0f4502 100644 --- a/src/Modules/Data/Commands.Data.Test/RemovePowerBIRowTests.cs +++ b/src/Modules/Data/Commands.Data.Test/RemovePowerBIRowTests.cs @@ -64,7 +64,7 @@ public void RemovePowerBIRows_DatasetIdParameterSetName() var table = new Table { Name = "TestTable" }; var client = new Mock(); - client.Setup(x => x.Datasets.DeleteRows(datasetId.ToString(), table.Name, null)).Returns(null); + client.Setup(x => x.Datasets.DeleteRows(datasetId, table.Name, null)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RemovePowerBIRow(initFactory); @@ -75,7 +75,7 @@ public void RemovePowerBIRows_DatasetIdParameterSetName() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(null, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } } } diff --git a/src/Modules/Data/Commands.Data/AddPowerBIRow.cs b/src/Modules/Data/Commands.Data/AddPowerBIRow.cs index ac655944..0eb248d0 100644 --- a/src/Modules/Data/Commands.Data/AddPowerBIRow.cs +++ b/src/Modules/Data/Commands.Data/AddPowerBIRow.cs @@ -64,30 +64,27 @@ protected override void BeginProcessing() public override void ExecuteCmdlet() { - if(this.Workspace != null) + if (this.Workspace != null) { this.WorkspaceId = this.Workspace.Id; } - if(this.Dataset != null) + if (this.Dataset != null) { this.DatasetId = this.Dataset.Id; } - object result; using (var client = this.CreateClient()) { - if(this.WorkspaceId != default) + if (this.WorkspaceId != default) { - result = client.Datasets.AddRows(this.DatasetId.ToString(), this.TableName, this.Rows, this.WorkspaceId); + client.Datasets.AddRows(this.DatasetId, this.TableName, this.Rows, this.WorkspaceId); } else { - result = client.Datasets.AddRows(this.DatasetId.ToString(), this.TableName, this.Rows); + client.Datasets.AddRows(this.DatasetId, this.TableName, this.Rows); } } - - this.Logger.WriteObject(result, true); } } } diff --git a/src/Modules/Data/Commands.Data/GetPowerBIDatasource.cs b/src/Modules/Data/Commands.Data/GetPowerBIDatasource.cs index e0a557ef..5806f2e7 100644 --- a/src/Modules/Data/Commands.Data/GetPowerBIDatasource.cs +++ b/src/Modules/Data/Commands.Data/GetPowerBIDatasource.cs @@ -77,7 +77,7 @@ protected override void BeginProcessing() public override void ExecuteCmdlet() { - if(this.Dataset != null) + if (this.Dataset != null) { this.DatasetId = this.Dataset.Id; } @@ -97,12 +97,12 @@ public override void ExecuteCmdlet() } } - if(this.Id != default) + if (this.Id != default) { - datasources = datasources.Where(d => this.Id == new Guid(d.DatasourceId)); + datasources = datasources.Where(d => this.Id == d.DatasourceId); } - if(!string.IsNullOrEmpty(this.Name)) + if (!string.IsNullOrEmpty(this.Name)) { datasources = datasources.Where(d => d.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)); } diff --git a/src/Modules/Data/Commands.Data/RemovePowerBIRow.cs b/src/Modules/Data/Commands.Data/RemovePowerBIRow.cs index 81606eec..c7c17282 100644 --- a/src/Modules/Data/Commands.Data/RemovePowerBIRow.cs +++ b/src/Modules/Data/Commands.Data/RemovePowerBIRow.cs @@ -59,30 +59,27 @@ protected override void BeginProcessing() public override void ExecuteCmdlet() { - if(this.Workspace != null) + if (this.Workspace != null) { this.WorkspaceId = this.Workspace.Id; } - if(this.Dataset != null) + if (this.Dataset != null) { this.DatasetId = this.Dataset.Id; } - object result; using (var client = this.CreateClient()) { - if(this.WorkspaceId != default) + if (this.WorkspaceId != default) { - result = client.Datasets.DeleteRows(this.DatasetId.ToString(), this.TableName, this.WorkspaceId); + client.Datasets.DeleteRows(this.DatasetId, this.TableName, this.WorkspaceId); } else { - result = client.Datasets.DeleteRows(this.DatasetId.ToString(), this.TableName); + client.Datasets.DeleteRows(this.DatasetId, this.TableName); } } - - this.Logger.WriteObject(result, true); } } } diff --git a/src/Modules/Reports/Commands.Reports.Test/CopyPowerBIReportTests.cs b/src/Modules/Reports/Commands.Reports.Test/CopyPowerBIReportTests.cs index 845f9b8a..9c518411 100644 --- a/src/Modules/Reports/Commands.Reports.Test/CopyPowerBIReportTests.cs +++ b/src/Modules/Reports/Commands.Reports.Test/CopyPowerBIReportTests.cs @@ -101,16 +101,16 @@ public void CopyPowerBIReportTest() var expectedResponse = new Report(); var client = new Mock(); client.Setup(x => x.Reports - .CopyReport(reportName, Guid.Empty.ToString(), reportId.ToString(), Guid.Empty.ToString(), Guid.Empty.ToString())) + .CopyReport(reportName, Guid.Empty, reportId, Guid.Empty, Guid.Empty)) .Returns(expectedResponse); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new CopyPowerBIReport(initFactory) { Name = reportName, Id = reportId, - WorkspaceId = Guid.Empty.ToString(), - TargetWorkspaceId = Guid.Empty.ToString(), - TargetDatasetId = Guid.Empty.ToString() + WorkspaceId = Guid.Empty, + TargetWorkspaceId = Guid.Empty, + TargetDatasetId = Guid.Empty }; // Act @@ -130,15 +130,15 @@ public void CopyPowerBIReportObjectTest() var expectedResponse = new Report(); var client = new Mock(); client.Setup(x => x.Reports - .CopyReport(reportName, Guid.Empty.ToString(), reportId.ToString(), Guid.Empty.ToString(), Guid.Empty.ToString())) + .CopyReport(reportName, Guid.Empty, reportId, Guid.Empty, Guid.Empty)) .Returns(expectedResponse); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new CopyPowerBIReport(initFactory) { Report = report, - WorkspaceId = Guid.Empty.ToString(), - TargetWorkspaceId = Guid.Empty.ToString(), - TargetDatasetId = Guid.Empty.ToString() + WorkspaceId = Guid.Empty, + TargetWorkspaceId = Guid.Empty, + TargetDatasetId = Guid.Empty }; // Act diff --git a/src/Modules/Reports/Commands.Reports.Test/CopyPowerBITileTests.cs b/src/Modules/Reports/Commands.Reports.Test/CopyPowerBITileTests.cs index 0b47ffce..9b3271c6 100644 --- a/src/Modules/Reports/Commands.Reports.Test/CopyPowerBITileTests.cs +++ b/src/Modules/Reports/Commands.Reports.Test/CopyPowerBITileTests.cs @@ -77,9 +77,9 @@ public void EndToEndCopyTileWithoutLogin() public void CopyPowerBITileTest() { // Arrange - var dashboardId = Guid.NewGuid().ToString(); - var targetDashboardId = Guid.NewGuid().ToString(); - var tileId = Guid.NewGuid().ToString(); + var dashboardId = Guid.NewGuid(); + var targetDashboardId = Guid.NewGuid(); + var tileId = Guid.NewGuid(); var expectedResponse = new Tile(); var client = new Mock(); client.Setup(x => x.Reports diff --git a/src/Modules/Reports/Commands.Reports/CopyPowerBIReport.cs b/src/Modules/Reports/Commands.Reports/CopyPowerBIReport.cs index 59fb73e9..1ebf83bc 100644 --- a/src/Modules/Reports/Commands.Reports/CopyPowerBIReport.cs +++ b/src/Modules/Reports/Commands.Reports/CopyPowerBIReport.cs @@ -53,7 +53,7 @@ public CopyPowerBIReport(IPowerBIClientCmdletInitFactory init) : base(init) { } // Optional. If omitted, the report is copied from 'My Workspace'. [Alias("GroupId")] [Parameter(Mandatory = false)] - public string WorkspaceId { get; set; } + public Guid? WorkspaceId { get; set; } // Optional. If omitted, the report is copied from 'My Workspace'. [Alias("Group")] @@ -64,12 +64,12 @@ public CopyPowerBIReport(IPowerBIClientCmdletInitFactory init) : base(init) { } // Empty Guid (00000000-0000-0000-0000-000000000000) indicates 'My Workspace'. [Alias("TargetGroupId")] [Parameter(Mandatory = false)] - public string TargetWorkspaceId { get; set; } + public Guid? TargetWorkspaceId { get; set; } // Optional. If omitted, the new report will be associated with the same dataset as the source report. [Alias("TargetModelId")] [Parameter(Mandatory = false)] - public string TargetDatasetId { get; set; } + public Guid? TargetDatasetId { get; set; } #endregion public override void ExecuteCmdlet() @@ -85,7 +85,7 @@ public override void ExecuteCmdlet() if (this.Workspace != null) { - this.WorkspaceId = this.Workspace.Id.ToString(); + this.WorkspaceId = this.Workspace.Id; } using (var client = this.CreateClient()) @@ -93,7 +93,7 @@ public override void ExecuteCmdlet() var result = client.Reports.CopyReport( this.Name, this.WorkspaceId, - this.Id.ToString(), + this.Id, this.TargetWorkspaceId, this.TargetDatasetId); this.Logger.WriteObject(result, true); diff --git a/src/Modules/Reports/Commands.Reports/CopyPowerBITile.cs b/src/Modules/Reports/Commands.Reports/CopyPowerBITile.cs index ef467d70..8af82a82 100644 --- a/src/Modules/Reports/Commands.Reports/CopyPowerBITile.cs +++ b/src/Modules/Reports/Commands.Reports/CopyPowerBITile.cs @@ -50,39 +50,39 @@ public CopyPowerBITile(IPowerBIClientCmdletInitFactory init) : base(init) { } [Parameter(Mandatory = true, ParameterSetName = WorkspaceObjectParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = WorkspaceIdParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = MyWorkspaceParameterSetName)] - public string DashboardId { get; set; } + public Guid DashboardId { get; set; } //The id of the tile that should be copied [Alias("TileKey")] [Parameter(Mandatory = true, ParameterSetName = WorkspaceObjectParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = WorkspaceIdParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = MyWorkspaceParameterSetName)] - public string TileId { get; set; } + public Guid TileId { get; set; } //The id of the dashboard where tile copy should be added. [Parameter(Mandatory = true, ParameterSetName = WorkspaceObjectParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = WorkspaceIdParameterSetName)] [Parameter(Mandatory = true, ParameterSetName = MyWorkspaceParameterSetName)] - public string TargetDashboardId { get; set; } + public Guid TargetDashboardId { get; set; } //Optional parameter for specifying the target workspace id. Empty Guid (00000000-0000-0000-0000-000000000000) indicates 'My Workspace'. //Empty string indicates tile will be copied within the same workspace. [Alias("TargetGroupId")] [Parameter(Mandatory = false)] - public string TargetWorkspaceId { get; set; } + public Guid? TargetWorkspaceId { get; set; } //Optional parameter when cloning a tile linked to a report, to rebind the new tile to a different report. [Parameter(Mandatory = false)] - public string TargetReportId { get; set; } + public Guid? TargetReportId { get; set; } //Optional parameter when cloning a tile linked to a dataset, to rebind the new tile to a different dataset. [Alias("TargetModelId")] [Parameter(Mandatory = false)] - public string TargetDatasetId { get; set; } + public Guid? TargetDatasetId { get; set; } //Optional parameter for specifying the action in case of position conflict. The default is 'Tail'. [Parameter(Mandatory = false)] - public string PositionConflictAction { get; set; } + public PositionConflictAction? PositionConflictAction { get; set; } #endregion public override void ExecuteCmdlet() { diff --git a/src/Modules/Reports/Commands.Reports/help/Copy-PowerBIReport.md b/src/Modules/Reports/Commands.Reports/help/Copy-PowerBIReport.md index f04192e1..216b41c9 100644 --- a/src/Modules/Reports/Commands.Reports/help/Copy-PowerBIReport.md +++ b/src/Modules/Reports/Commands.Reports/help/Copy-PowerBIReport.md @@ -14,14 +14,14 @@ Creates a copy of the specified Power BI report. ### Id (Default) ``` -Copy-PowerBIReport -Name -Id [-WorkspaceId ] [-Workspace ] - [-TargetWorkspaceId ] [-TargetDatasetId ] [] +Copy-PowerBIReport -Name -Id [-WorkspaceId ] [-Workspace ] + [-TargetWorkspaceId ] [-TargetDatasetId ] [] ``` ### WorkspaceObject ``` -Copy-PowerBIReport [-Name ] -Report [-WorkspaceId ] [-Workspace ] - [-TargetWorkspaceId ] [-TargetDatasetId ] [] +Copy-PowerBIReport [-Name ] -Report [-WorkspaceId ] [-Workspace ] + [-TargetWorkspaceId ] [-TargetDatasetId ] [] ``` ## DESCRIPTION @@ -113,7 +113,7 @@ Accept wildcard characters: False Optional parameter for specifying the target associated dataset ID. If empty, the new report will be associated with the same dataset as the source report. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: TargetModelId @@ -128,7 +128,7 @@ Accept wildcard characters: False The ID of the target workspace. Empty Guid (00000000-0000-0000-0000-000000000000) indicates 'My Workspace'. Empty string indicates new report will be copied within the same workspace as the source report. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: TargetGroupId @@ -158,7 +158,7 @@ Accept wildcard characters: False The ID of the workspace where the original report is located. If empty, source workspace is 'My Workspace'. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: GroupId diff --git a/src/Modules/Reports/Commands.Reports/help/Copy-PowerBITile.md b/src/Modules/Reports/Commands.Reports/help/Copy-PowerBITile.md index 679c55c6..54c234ce 100644 --- a/src/Modules/Reports/Commands.Reports/help/Copy-PowerBITile.md +++ b/src/Modules/Reports/Commands.Reports/help/Copy-PowerBITile.md @@ -14,23 +14,23 @@ Creates a copy of the specified Power BI tile and adds it to a Power BI dashboar ### MyWorkspace (Default) ``` -Copy-PowerBITile -DashboardId -TileId -TargetDashboardId - [-TargetWorkspaceId ] [-TargetReportId ] [-TargetDatasetId ] - [-PositionConflictAction ] [] +Copy-PowerBITile -DashboardId -TileId -TargetDashboardId [-TargetWorkspaceId ] + [-TargetReportId ] [-TargetDatasetId ] [-PositionConflictAction ] + [] ``` ### WorkspaceId ``` -Copy-PowerBITile -WorkspaceId -DashboardId -TileId -TargetDashboardId - [-TargetWorkspaceId ] [-TargetReportId ] [-TargetDatasetId ] - [-PositionConflictAction ] [] +Copy-PowerBITile -WorkspaceId -DashboardId -TileId -TargetDashboardId + [-TargetWorkspaceId ] [-TargetReportId ] [-TargetDatasetId ] + [-PositionConflictAction ] [] ``` ### WorkspaceObject ``` -Copy-PowerBITile -Workspace -DashboardId -TileId -TargetDashboardId - [-TargetWorkspaceId ] [-TargetReportId ] [-TargetDatasetId ] - [-PositionConflictAction ] [] +Copy-PowerBITile -Workspace -DashboardId -TileId -TargetDashboardId + [-TargetWorkspaceId ] [-TargetReportId ] [-TargetDatasetId ] + [-PositionConflictAction ] [] ``` ## DESCRIPTION @@ -54,7 +54,7 @@ Creates a copy of the tile with the ID "e297e105-be30-4482-8531-152cdf289ac6" fr The ID of the dashboard where source tile is located. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: DashboardKey @@ -69,7 +69,7 @@ Accept wildcard characters: False Optional parameter for specifying the action in case of position conflict. The default is 'Tail'. ```yaml -Type: String +Type: PositionConflictAction Parameter Sets: (All) Aliases: @@ -84,7 +84,7 @@ Accept wildcard characters: False The ID of the dashboard where tile copy should be added. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: @@ -99,7 +99,7 @@ Accept wildcard characters: False Optional parameter to rebind the copied tile to a different dataset. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: TargetModelId @@ -114,7 +114,7 @@ Accept wildcard characters: False Optional parameter to rebind the copied tile to a different report. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: @@ -129,7 +129,7 @@ Accept wildcard characters: False Optional parameter for specifying the target workspace ID. Empty Guid (00000000-0000-0000-0000-000000000000) indicates 'My Workspace'. Empty string indicates tile will be copied within the same workspace. ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: TargetGroupId @@ -144,7 +144,7 @@ Accept wildcard characters: False The ID of the tile that should be copied ```yaml -Type: String +Type: Guid Parameter Sets: (All) Aliases: TileKey diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/AddPowerBIWorkspaceUserTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/AddPowerBIWorkspaceUserTests.cs index e2c8010f..fe04e1c7 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/AddPowerBIWorkspaceUserTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/AddPowerBIWorkspaceUserTests.cs @@ -52,7 +52,7 @@ public void EndToEndAddPowerBIWorkspaceUserOrganizationScope() var updatedWorkspace = WorkspacesTestUtilities.GetWorkspace(ps, PowerBIUserScope.Organization, workspace.Id); Assert.IsTrue(updatedWorkspace.Users .Any(x => x.UserPrincipalName.Equals(emailAddress, StringComparison.OrdinalIgnoreCase) - && x.AccessRight == WorkspaceUserAccessRight.Member.ToString())); + && x.AccessRight == WorkspaceUserAccessRight.Member)); } } @@ -119,12 +119,10 @@ public void AddPowerBIWorkspaceUserOrganizationScope_WorkspaceParameterSet() { // Arrange var workspace = new Workspace { Id = Guid.NewGuid() }; - var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var expectedResponse = new object(); + var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member }; var client = new Mock(); client.Setup(x => x.Workspaces - .AddWorkspaceUserAsAdmin(workspace.Id, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))) - .Returns(expectedResponse); + .AddWorkspaceUserAsAdmin(workspace.Id, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new AddPowerBIWorkspaceUser(initFactory) { @@ -139,7 +137,7 @@ public void AddPowerBIWorkspaceUserOrganizationScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -147,12 +145,10 @@ public void AddPowerBIWorkspaceUserOrganizationScope_IdParameterSet() { // Arrange var workspaceId = Guid.NewGuid(); - var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var expectedResponse = new object(); + var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member }; var client = new Mock(); client.Setup(x => x.Workspaces - .AddWorkspaceUserAsAdmin(workspaceId, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))) - .Returns(expectedResponse); + .AddWorkspaceUserAsAdmin(workspaceId, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new AddPowerBIWorkspaceUser(initFactory) { @@ -167,7 +163,7 @@ public void AddPowerBIWorkspaceUserOrganizationScope_IdParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -175,12 +171,10 @@ public void AddPowerBIWorkspaceUserIndividualScope_WorkspaceParameterSet() { // Arrange var workspace = new Workspace { Id = Guid.NewGuid() }; - var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var expectedResponse = new object(); + var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member }; var client = new Mock(); client.Setup(x => x.Workspaces - .AddWorkspaceUser(workspace.Id, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))) - .Returns(expectedResponse); + .AddWorkspaceUser(workspace.Id, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new AddPowerBIWorkspaceUser(initFactory) { @@ -195,7 +189,7 @@ public void AddPowerBIWorkspaceUserIndividualScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -203,12 +197,10 @@ public void AddPowerBIWorkspaceUserIndividualScope_IdParameterSet() { // Arrange var workspaceId = Guid.NewGuid(); - var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var expectedResponse = new object(); + var user = new WorkspaceUser { UserPrincipalName = "john@contoso.com", AccessRight = WorkspaceUserAccessRight.Member }; var client = new Mock(); client.Setup(x => x.Workspaces - .AddWorkspaceUser(workspaceId, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))) - .Returns(expectedResponse); + .AddWorkspaceUser(workspaceId, It.Is(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new AddPowerBIWorkspaceUser(initFactory) { @@ -223,7 +215,7 @@ public void AddPowerBIWorkspaceUserIndividualScope_IdParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/GetPowerBIWorkspaceTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/GetPowerBIWorkspaceTests.cs index c437b301..f05734a9 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/GetPowerBIWorkspaceTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/GetPowerBIWorkspaceTests.cs @@ -448,7 +448,7 @@ public void GetWorkspacesOrganizationScope() // Arrange var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -470,7 +470,7 @@ public void GetWorkspacesAllDeleted() var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", State = WorkspaceState.Active }, expectedWorkspace}; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -491,16 +491,16 @@ public void GetWorkspacesAllOrphaned() { // Arrange var deletedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", State = WorkspaceState.Deleted }; - var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor.ToString() }; + var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member }; + var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor }; var orphanedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user1, user2 } }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; var normalWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }; var allWorkspaces = new List { normalWorkspace, orphanedWorkspace, deletedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -521,11 +521,11 @@ public void GetWorkspacesAllOrphanedWithNullUsers() { // Arrange var expectedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin}; var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }, expectedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -546,11 +546,11 @@ public void GetWorkspacesAllOrphanedWithEmptyUsers() { // Arrange var expectedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List() }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }, expectedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -570,15 +570,15 @@ public void GetWorkspacesAllOrphanedWithEmptyUsers() public void GetWorkspacesAllOrphanedWithNonAdminUsers() { // Arrange - var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor.ToString() }; + var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member }; + var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor }; var expectedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user1, user2 } }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }, expectedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -598,9 +598,9 @@ public void GetWorkspacesAllOrphanedWithNonAdminUsers() public void GetWorkspacesAllAndUser() { // Arrange - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; - var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; + var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member }; + var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor }; var orphanedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user1, user2 } }; var deletedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Deleted }; var normalWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }; @@ -608,7 +608,7 @@ public void GetWorkspacesAllAndUser() var allWorkspaces = new List { normalWorkspace, deletedWorkspace, orphanedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -628,16 +628,16 @@ public void GetWorkspacesAllAndUser() public void GetWorkspacesAllOrphanedAndUser() { // Arrange - var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor.ToString() }; + var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member }; + var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor }; var expectedOrphanedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user1, user2 } }; var expectedDeletedWorkspace = new Workspace { Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Deleted }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }, expectedDeletedWorkspace, expectedOrphanedWorkspace }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -658,16 +658,16 @@ public void GetWorkspacesAllOrphanedAndUser() public void GetWorkspacesAllOrphanedWithGroup() { // Arrange - var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member.ToString() }; - var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor.ToString() }; + var user1 = new WorkspaceUser { UserPrincipalName = "randomUser1@pbi.com", AccessRight = WorkspaceUserAccessRight.Member }; + var user2 = new WorkspaceUser { UserPrincipalName = "randomUser2@pbi.com", AccessRight = WorkspaceUserAccessRight.Contributor }; var expectedOrphanedWorkspaceOne = new Workspace { Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user1, user2 } }; var expectedOrphanedWorkspaceTwo = new Workspace { Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", Type = WorkspaceType.Group, State = WorkspaceState.Active, Users = new List { user1 } }; - var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin.ToString() }; + var user = new WorkspaceUser { UserPrincipalName = "randomUser@pbi.com", AccessRight = WorkspaceUserAccessRight.Admin }; var allWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List { user } }, expectedOrphanedWorkspaceOne, expectedOrphanedWorkspaceTwo }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny(), It.IsAny())).Returns(allWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", null, It.IsAny())).Returns(allWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -694,9 +694,9 @@ public void GetWorkspacesAllParameterLoopTest() } var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny(), 5000, 0)).Returns(expectedWorkspaces.Take(5000)); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny(), 5000, 5000)).Returns(expectedWorkspaces.GetRange(5000, 5000)); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny(), 5000, 10000)).Returns(expectedWorkspaces.Skip(10000)); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(5000, "users", It.IsAny(), 0)).Returns(expectedWorkspaces.Take(5000)); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(5000, "users", It.IsAny(), 5000)).Returns(expectedWorkspaces.GetRange(5000, 5000)); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(5000, "users", It.IsAny(), 10000)).Returns(expectedWorkspaces.Skip(10000)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -708,7 +708,7 @@ public void GetWorkspacesAllParameterLoopTest() cmdlet.InvokePowerBICmdlet(); // Assert - client.Verify(m => m.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(3)); + client.Verify(m => m.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", It.IsAny(), It.IsAny()), Times.Exactly(3)); AssertExpectedUnitTestResults(expectedWorkspaces, initFactory); } @@ -721,7 +721,7 @@ public void GetWorkspacesOrganizationScopeSupportsFilterTopSkip() var skip = 5; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, first, skip)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(first, "users", filter, skip)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -746,7 +746,7 @@ public void GetWorkspacesOrganizationScopeSupportsId() var filter = $"id eq '{id}'"; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -769,7 +769,7 @@ public void GetWorkspacesOrganizationScopeSupportsName() var filter = $"tolower(name) eq '{name.ToLower()}'"; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = name } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -793,7 +793,7 @@ public void GetWorkspacesOrganizationScopeSupportsUser() var filter = $"users/any(u: tolower(u/emailAddress) eq '{user.ToLower()}')"; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -814,7 +814,7 @@ public void GetWorkspacesOrganizationScopeSupportsDeleted() var filter = string.Format("state eq '{0}'", WorkspaceState.Deleted); var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -836,7 +836,7 @@ public void GetWorkspacesOrganizationScopeSupportsOrphaned() var filter = $"(state ne '{WorkspaceState.Deleted}') and ((not users/any()) or (not users/any(u: u/groupUserAccessRight eq Microsoft.PowerBI.ServiceContracts.Api.GroupUserAccessRight'Admin')))"; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny(), null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { @@ -951,7 +951,7 @@ public void GetWorkspacesIndividualScopeDoesNotSupportUser() var filter = $"users/any(u: tolower(u/emailAddress) eq '{user.ToLower()}')"; var expectedWorkspaces = new List { new Workspace { Id = Guid.NewGuid(), Name = "TestWorkspace" } }; var client = new Mock(); - client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, null, null)).Returns(expectedWorkspaces); + client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin(It.IsAny(), "users", filter, null)).Returns(expectedWorkspaces); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetPowerBIWorkspace(initFactory) { diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/RemovePowerBIWorkspaceUserTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/RemovePowerBIWorkspaceUserTests.cs index 64de1de2..62daf0a6 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/RemovePowerBIWorkspaceUserTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/RemovePowerBIWorkspaceUserTests.cs @@ -115,11 +115,9 @@ public void RemovePowerBIWorkspaceUserOrganizationScope_WorkspaceParameterSet() // Arrange var workspace = new Workspace { Id = Guid.NewGuid() }; var userPrincipalName = "john@contoso.com"; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RemoveWorkspaceUserAsAdmin(workspace.Id, userPrincipalName)) - .Returns(expectedResponse); + .RemoveWorkspaceUserAsAdmin(workspace.Id, userPrincipalName)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RemovePowerBIWorkspaceUser(initFactory) { @@ -133,7 +131,7 @@ public void RemovePowerBIWorkspaceUserOrganizationScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -142,11 +140,9 @@ public void RemovePowerBIWorkspaceUserOrganizationScope_IdParameterSet() // Arrange var workspaceId = Guid.NewGuid(); var userPrincipalName = "john@contoso.com"; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RemoveWorkspaceUserAsAdmin(workspaceId, userPrincipalName)) - .Returns(expectedResponse); + .RemoveWorkspaceUserAsAdmin(workspaceId, userPrincipalName)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RemovePowerBIWorkspaceUser(initFactory) { @@ -160,7 +156,7 @@ public void RemovePowerBIWorkspaceUserOrganizationScope_IdParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -169,11 +165,9 @@ public void RemovePowerBIWorkspaceUserIndividualScope_WorkspaceParameterSet() // Arrange var workspace = new Workspace { Id = Guid.NewGuid() }; var userPrincipalName = "john@contoso.com"; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RemoveWorkspaceUser(workspace.Id, userPrincipalName)) - .Returns(expectedResponse); + .RemoveWorkspaceUser(workspace.Id, userPrincipalName)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RemovePowerBIWorkspaceUser(initFactory) { @@ -187,7 +181,7 @@ public void RemovePowerBIWorkspaceUserIndividualScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -196,11 +190,9 @@ public void RemovePowerBIWorkspaceUserIndividualScope_IdParameterSet() // Arrange var workspaceId = Guid.NewGuid(); var userPrincipalName = "john@contoso.com"; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RemoveWorkspaceUser(workspaceId, userPrincipalName)) - .Returns(expectedResponse); + .RemoveWorkspaceUser(workspaceId, userPrincipalName)); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RemovePowerBIWorkspaceUser(initFactory) { @@ -214,7 +206,7 @@ public void RemovePowerBIWorkspaceUserIndividualScope_IdParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } } } \ No newline at end of file diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/RestorePowerBIWorkspaceTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/RestorePowerBIWorkspaceTests.cs index e69b0356..6a17af6b 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/RestorePowerBIWorkspaceTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/RestorePowerBIWorkspaceTests.cs @@ -57,7 +57,7 @@ public void EndToEndRestoreWorkspaceOrganizationScopePropertiesParameterSet() Assert.AreEqual(updatedName, updatedWorkspace.Name); Assert.IsTrue(updatedWorkspace.Users .Any(x => x.UserPrincipalName.Equals(emailAddress, StringComparison.OrdinalIgnoreCase) - && x.AccessRight == WorkspaceUserAccessRight.Admin.ToString())); + && x.AccessRight == WorkspaceUserAccessRight.Admin)); } } @@ -96,7 +96,7 @@ public void EndToEndRestoreWorkspaceOrganizationScopeWorkspaceParameterSet() Assert.AreEqual(updatedName, updatedWorkspace.Name); Assert.IsTrue(updatedWorkspace.Users .Any(x => x.UserPrincipalName.Equals(emailAddress, StringComparison.OrdinalIgnoreCase) - && x.AccessRight == WorkspaceUserAccessRight.Admin.ToString())); + && x.AccessRight == WorkspaceUserAccessRight.Admin)); } } @@ -179,11 +179,9 @@ public void RestorePowerBIWorkspaceOrganizationScope_WorkspaceParameterSet() // Arrange var workspace = new Workspace { Id = Guid.NewGuid() }; var restoreRequest = new WorkspaceRestoreRequest { RestoredName = "Undeleted", AdminUserPrincipalName = "john@contoso.com" }; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RestoreDeletedWorkspaceAsAdmin(workspace.Id, It.Is(r => r.RestoredName == restoreRequest.RestoredName && r.AdminUserPrincipalName == restoreRequest.AdminUserPrincipalName))) - .Returns(expectedResponse); + .RestoreDeletedWorkspaceAsAdmin(workspace.Id, It.Is(r => r.RestoredName == restoreRequest.RestoredName && r.AdminUserPrincipalName == restoreRequest.AdminUserPrincipalName))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RestorePowerBIWorkspace(initFactory) { @@ -198,7 +196,7 @@ public void RestorePowerBIWorkspaceOrganizationScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -207,11 +205,9 @@ public void RestorePowerBIWorkspaceOrganizationScope_IdParameterSet() // Arrange var workspaceId = Guid.NewGuid(); var restoreRequest = new WorkspaceRestoreRequest { RestoredName = "Undeleted", AdminUserPrincipalName = "john@contoso.com" }; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .RestoreDeletedWorkspaceAsAdmin(workspaceId, It.Is(r => r.RestoredName == restoreRequest.RestoredName && r.AdminUserPrincipalName == restoreRequest.AdminUserPrincipalName))) - .Returns(expectedResponse); + .RestoreDeletedWorkspaceAsAdmin(workspaceId, It.Is(r => r.RestoredName == restoreRequest.RestoredName && r.AdminUserPrincipalName == restoreRequest.AdminUserPrincipalName))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new RestorePowerBIWorkspace(initFactory) { @@ -226,7 +222,7 @@ public void RestorePowerBIWorkspaceOrganizationScope_IdParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/SetPowerBIWorkspaceTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/SetPowerBIWorkspaceTests.cs index 483b00ab..49e2895c 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/SetPowerBIWorkspaceTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/SetPowerBIWorkspaceTests.cs @@ -189,11 +189,9 @@ public void SetPowerBIWorkspaceOrganizationScope_PropertiesParameterSet() { // Arrange var workspace = new Workspace { Id = Guid.NewGuid(), Name = "UpdatedName", Description = "UpdatedDescription" }; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .UpdateWorkspaceAsAdmin(workspace.Id, It.Is(w => w.Name == workspace.Name && w.Description == workspace.Description))) - .Returns(expectedResponse); + .UpdateWorkspaceAsAdmin(workspace.Id, It.Is(w => w.Name == workspace.Name && w.Description == workspace.Description))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SetPowerBIWorkspace(initFactory) { @@ -208,7 +206,7 @@ public void SetPowerBIWorkspaceOrganizationScope_PropertiesParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] @@ -216,11 +214,9 @@ public void SetPowerBIWorkspaceOrganizationScope_WorkspaceParameterSet() { // Arrange var workspace = new Workspace { Id = Guid.NewGuid(), Name = "UpdatedName", Description = "UpdatedDescription" }; - var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .UpdateWorkspaceAsAdmin(workspace.Id, It.Is(w => w.Name == workspace.Name && w.Description == workspace.Description))) - .Returns(expectedResponse); + .UpdateWorkspaceAsAdmin(workspace.Id, It.Is(w => w.Name == workspace.Name && w.Description == workspace.Description))); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SetPowerBIWorkspace(initFactory) { @@ -233,7 +229,7 @@ public void SetPowerBIWorkspaceOrganizationScope_WorkspaceParameterSet() cmdlet.InvokePowerBICmdlet(); // Assert - TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); + TestUtilities.AssertExpectedNoOutputForUnitTestResults(client, initFactory); } [TestMethod] diff --git a/src/Modules/Workspaces/Commands.Workspaces/AddPowerBIWorkspaceUser.cs b/src/Modules/Workspaces/Commands.Workspaces/AddPowerBIWorkspaceUser.cs index 05c699da..ec386b9b 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/AddPowerBIWorkspaceUser.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/AddPowerBIWorkspaceUser.cs @@ -43,6 +43,10 @@ public AddPowerBIWorkspaceUser(IPowerBIClientCmdletInitFactory init) : base(init [Alias("UserAccessRight")] public WorkspaceUserAccessRight AccessRight { get; set; } + [Parameter(Mandatory = false)] + [Alias("PrincipalType")] + public PrincipalType? UserType { get; set; } + [Parameter(Mandatory = true, ParameterSetName = WorkspaceParameterSetName)] [Alias("Group")] public Workspace Workspace { get; set; } @@ -62,14 +66,23 @@ protected override void BeginProcessing() public override void ExecuteCmdlet() { var workspaceId = this.ParameterSet.Equals(IdParameterSetName) ? this.Id : this.Workspace.Id; - var userAccessRight = new WorkspaceUser { AccessRight = this.AccessRight.ToString(), UserPrincipalName = this.UserPrincipalName }; + var userAccessRight = new WorkspaceUser + { + AccessRight = this.AccessRight, + UserPrincipalName = this.UserPrincipalName, + PrincipalType = this.UserType + }; using (var client = this.CreateClient()) { - var result = this.Scope.Equals(PowerBIUserScope.Individual) ? - client.Workspaces.AddWorkspaceUser(workspaceId, userAccessRight) : + if(this.Scope.Equals(PowerBIUserScope.Individual)) + { + client.Workspaces.AddWorkspaceUser(workspaceId, userAccessRight); + } + else + { client.Workspaces.AddWorkspaceUserAsAdmin(workspaceId, userAccessRight); - this.Logger.WriteObject(result, true); + } } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs b/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs index cf318199..e5ccc34c 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs @@ -154,7 +154,7 @@ private void GetWorkspaces() var workspaces = this.Scope == PowerBIUserScope.Individual ? client.Workspaces.GetWorkspaces(filter: this.Filter, top: this.First, skip: this.Skip) : - client.Workspaces.GetWorkspacesAsAdmin(expand: "users", filter: this.Filter, top: this.First, skip: this.Skip); + client.Workspaces.GetWorkspacesAsAdmin(top: this.First.GetValueOrDefault(), expand: "users", filter: this.Filter, skip: this.Skip); if (defaultingFirst && workspaces.Count() == 100) { diff --git a/src/Modules/Workspaces/Commands.Workspaces/RemovePowerBIWorkspaceUser.cs b/src/Modules/Workspaces/Commands.Workspaces/RemovePowerBIWorkspaceUser.cs index 5f6ed8b6..d0c469c1 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/RemovePowerBIWorkspaceUser.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/RemovePowerBIWorkspaceUser.cs @@ -61,10 +61,14 @@ public override void ExecuteCmdlet() using (var client = this.CreateClient()) { - var result = this.Scope.Equals(PowerBIUserScope.Individual) ? - client.Workspaces.RemoveWorkspaceUser(workspaceId, this.UserPrincipalName) : + if (this.Scope.Equals(PowerBIUserScope.Individual)) + { + client.Workspaces.RemoveWorkspaceUser(workspaceId, this.UserPrincipalName); + } + else + { client.Workspaces.RemoveWorkspaceUserAsAdmin(workspaceId, this.UserPrincipalName); - this.Logger.WriteObject(result, true); + } } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/RestorePowerBIWorkspace.cs b/src/Modules/Workspaces/Commands.Workspaces/RestorePowerBIWorkspace.cs index 00d86cc5..5914fb47 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/RestorePowerBIWorkspace.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/RestorePowerBIWorkspace.cs @@ -60,7 +60,7 @@ protected override void BeginProcessing() if (this.Scope == PowerBIUserScope.Organization) { - this.Logger.WriteWarning($"Only preview workspaces are supported when -{nameof(this.Scope)} {nameof(PowerBIUserScope.Organization)} is specified"); + this.Logger.WriteWarning($"Only workspaces created in the new workspace experience are supported when -{nameof(this.Scope)} {nameof(PowerBIUserScope.Organization)} is specified"); } } @@ -71,8 +71,7 @@ public override void ExecuteCmdlet() using (var client = this.CreateClient()) { - var result = client.Workspaces.RestoreDeletedWorkspaceAsAdmin(workspaceId, restoreRequest); - this.Logger.WriteObject(result, true); + client.Workspaces.RestoreDeletedWorkspaceAsAdmin(workspaceId, restoreRequest); } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/SetPowerBIWorkspace.cs b/src/Modules/Workspaces/Commands.Workspaces/SetPowerBIWorkspace.cs index 3f28da78..5dd0a9c7 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/SetPowerBIWorkspace.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/SetPowerBIWorkspace.cs @@ -73,8 +73,7 @@ public override void ExecuteCmdlet() using (var client = this.CreateClient()) { - var result = client.Workspaces.UpdateWorkspaceAsAdmin(workspaceId, updatedProperties); - this.Logger.WriteObject(result, true); + client.Workspaces.UpdateWorkspaceAsAdmin(workspaceId, updatedProperties); } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/help/Add-PowerBIWorkspaceUser.md b/src/Modules/Workspaces/Commands.Workspaces/help/Add-PowerBIWorkspaceUser.md index 4bd47273..ef579c43 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/help/Add-PowerBIWorkspaceUser.md +++ b/src/Modules/Workspaces/Commands.Workspaces/help/Add-PowerBIWorkspaceUser.md @@ -15,13 +15,14 @@ Gives permissions to a specified user to access a Power BI workspace. ### Id (Default) ``` Add-PowerBIWorkspaceUser [-Scope ] -Id -UserPrincipalName - -AccessRight [] + -AccessRight [-UserType ] [] ``` ### Workspace ``` Add-PowerBIWorkspaceUser [-Scope ] -UserPrincipalName - -AccessRight -Workspace [] + -AccessRight [-UserType ] -Workspace + [] ``` ## DESCRIPTION @@ -99,6 +100,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -UserType +Type of user to be added. + +```yaml +Type: PrincipalType +Parameter Sets: (All) +Aliases: PrincipalType + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Workspace The workspace entity to add the user to. From 64c411570e176092e7517ee38fe9cdbc0822a1ab Mon Sep 17 00:00:00 2001 From: Chaz Beck Date: Tue, 7 May 2019 10:35:13 -0700 Subject: [PATCH 2/5] Fix for AppVeyor uploads. Fix for detecting if workspace is orphaned. --- scripts/Test.ps1 | 15 +++++++++++---- src/Common/Common.Api/Workspaces/Workspace.cs | 2 +- .../Commands.Workspaces/GetPowerBIWorkspace.cs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/Test.ps1 b/scripts/Test.ps1 index 5d0b2810..cb8559ff 100644 --- a/scripts/Test.ps1 +++ b/scripts/Test.ps1 @@ -105,7 +105,9 @@ $testProjects | ForEach-Object { $dotnetArgs = @('test', "`"$($_.FullName)`"") $dotnetArgs += $commonDotnetArgs - $logFileName = "$($_.BaseName)_$(Get-Date -Format 'yyyyMMdd_HHmmss').trx" + # Due to this issue, timestamp is being auto added by dotnet test which breaks AppVeyor from finding tests - https://github.com/Microsoft/vstest/issues/1951 + $logBaseName = $_.BaseName + $logFileName = "$($logBaseName).trx" # Depending how above issue is fixed, may need to add this back in _$(Get-Date -Format 'yyyyMMdd_HHmmss') if($Logger) { $dotnetArgs += @('--logger', "`"$Logger;LogFileName=$logFileName`"") } @@ -115,9 +117,14 @@ $testProjects | ForEach-Object { $exitCode = $LASTEXITCODE # Save exit code in case upload results fails if($ResultsDirectory -and $Logger -and $UploadResultsToAppVeyor -and $env:APPVEYOR_JOB_ID) { - $resultsLog = Join-Path -Path $ResultsDirectory -ChildPath $logFileName - if(Test-Path -Path $resultsLog) { + Write-Host "Publishing test results..." + #Write-Host "ResultsDirectory: $ResultsDirectory" + #Write-Host "LogFileName: $logFileName" + $resultsFileName = Join-Path -Path $ResultsDirectory -ChildPath "$($logBaseName)*.trx" + $resultsLog = Get-ChildItem -Path $resultsFileName | Select-Object -First 1 | % { $_.FullName } + if($resultsLog -and (Test-Path -Path $resultsLog)) { # https://www.appveyor.com/docs/running-tests/ + # https://www.appveyor.com/docs/running-tests/#pushing-real-time-test-results-to-build-console try { Write-Output "Uploading file to AppVeyor (job ID $($env:APPVEYOR_JOB_ID)): $resultsLog" $wc = New-Object 'System.Net.WebClient' @@ -128,7 +135,7 @@ $testProjects | ForEach-Object { } } else { - Write-Warning "No results file found at: $resultsLog" + Write-Warning "No results file found at: $resultsFileName" } } diff --git a/src/Common/Common.Api/Workspaces/Workspace.cs b/src/Common/Common.Api/Workspaces/Workspace.cs index 4a2ced29..24f08ad8 100644 --- a/src/Common/Common.Api/Workspaces/Workspace.cs +++ b/src/Common/Common.Api/Workspaces/Workspace.cs @@ -37,7 +37,7 @@ public bool IsOrphaned return false; } - return (this.Users == null) || (!this.Users.Any(u => u.AccessRight.Equals(WorkspaceUserAccessRight.Admin.ToString()))); + return (this.Users == null) || (!this.Users.Any(u => u.AccessRight.Equals(WorkspaceUserAccessRight.Admin))); } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs b/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs index e5ccc34c..5b9480c4 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/GetPowerBIWorkspace.cs @@ -176,7 +176,7 @@ private void ExecuteCmdletWithAll() return; } - var allWorkspaces = this.ExecuteCmdletWithAll((top, skip) => client.Workspaces.GetWorkspacesAsAdmin(expand: "users", filter: this.Filter, top: top, skip: skip)); + var allWorkspaces = this.ExecuteCmdletWithAll((top, skip) => client.Workspaces.GetWorkspacesAsAdmin(top: top, expand: "users", filter: this.Filter, skip: skip)); var filteredWorkspaces = new List(); From a31909c6c9c825c1bcdbeaff8eaf83c7fed8c7e4 Mon Sep 17 00:00:00 2001 From: Chaz Beck Date: Tue, 7 May 2019 10:52:33 -0700 Subject: [PATCH 3/5] Bumping version to 1.1 --- appveyor.yml | 2 +- src/PowerBIPowerShell.sln | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1e8d40fb..c9c555ac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ image: Visual Studio 2017 # Versioning -version: '1.0.{build}' +version: '1.1.{build}' assembly_info: patch: true diff --git a/src/PowerBIPowerShell.sln b/src/PowerBIPowerShell.sln index 46b80e49..4c7821e8 100644 --- a/src/PowerBIPowerShell.sln +++ b/src/PowerBIPowerShell.sln @@ -32,6 +32,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{128A3120-95D4-4D1D-8E1C-8AD15CB31831}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + ..\appveyor.yml = ..\appveyor.yml NuGet.config = NuGet.config ..\ReleaseNotes.md = ..\ReleaseNotes.md EndProjectSection From 93dcdf73cad7e0a356a5ae076f7bb37968101545 Mon Sep 17 00:00:00 2001 From: Chaz Beck Date: Thu, 9 May 2019 15:42:25 -0700 Subject: [PATCH 4/5] Updated New-PowerBIWorkpace to create new workspace type (instead of only O365 Group based workspaces) --- .../Common.Api/Workspaces/IWorkspacesClient.cs | 2 +- .../Common.Api/Workspaces/WorkspacesClient.cs | 4 ++-- .../NewPowerBIWorkspaceTests.cs | 2 +- .../Commands.Workspaces/NewPowerBIWorkspace.cs | 12 +++++++++++- .../help/New-PowerBIWorkspace.md | 17 ++++++++++++++++- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs b/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs index fe667b3f..d0a92ad4 100644 --- a/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs +++ b/src/Common/Common.Api/Workspaces/IWorkspacesClient.cs @@ -26,7 +26,7 @@ public interface IWorkspacesClient void RemoveWorkspaceUserAsAdmin(Guid workspaceId, string userPrincipalName); - object NewWorkspaceAsUser(string workspaceName); + object NewWorkspaceAsUser(string workspaceName, bool workspaceV2); } } diff --git a/src/Common/Common.Api/Workspaces/WorkspacesClient.cs b/src/Common/Common.Api/Workspaces/WorkspacesClient.cs index 035bcdc1..75dfdc7d 100644 --- a/src/Common/Common.Api/Workspaces/WorkspacesClient.cs +++ b/src/Common/Common.Api/Workspaces/WorkspacesClient.cs @@ -56,9 +56,9 @@ public void UpdateWorkspaceAsAdmin(Guid workspaceId, Workspace updatedProperties this.Client.Groups.UpdateGroupAsAdmin(workspaceId, updatedProperties); } - public object NewWorkspaceAsUser(string workspaceName) + public object NewWorkspaceAsUser(string workspaceName, bool workspaceV2) { - return (Workspace)this.Client.Groups.CreateGroup(new PowerBI.Api.V2.Models.GroupCreationRequest(name: workspaceName)); + return (Workspace)this.Client.Groups.CreateGroup(new PowerBI.Api.V2.Models.GroupCreationRequest(name: workspaceName), workspaceV2: workspaceV2); } } } diff --git a/src/Modules/Workspaces/Commands.Workspaces.Test/NewPowerBIWorkspaceTests.cs b/src/Modules/Workspaces/Commands.Workspaces.Test/NewPowerBIWorkspaceTests.cs index 08d9d527..c90a47bd 100644 --- a/src/Modules/Workspaces/Commands.Workspaces.Test/NewPowerBIWorkspaceTests.cs +++ b/src/Modules/Workspaces/Commands.Workspaces.Test/NewPowerBIWorkspaceTests.cs @@ -76,7 +76,7 @@ public void NewPowerBIWorkspaceTest() var expectedResponse = new object(); var client = new Mock(); client.Setup(x => x.Workspaces - .NewWorkspaceAsUser(workspaceName)) + .NewWorkspaceAsUser(workspaceName, true)) .Returns(expectedResponse); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new NewPowerBIWorkspace(initFactory) diff --git a/src/Modules/Workspaces/Commands.Workspaces/NewPowerBIWorkspace.cs b/src/Modules/Workspaces/Commands.Workspaces/NewPowerBIWorkspace.cs index f4d77db4..a1d70c11 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/NewPowerBIWorkspace.cs +++ b/src/Modules/Workspaces/Commands.Workspaces/NewPowerBIWorkspace.cs @@ -31,15 +31,25 @@ public NewPowerBIWorkspace(IPowerBIClientCmdletInitFactory init) : base(init) { [Parameter(Mandatory = true)] public string Name { get; set; } + [Parameter(Mandatory = false)] + [Alias("WorkspaceType")] + public NewWorkspaceType Type { get; set; } = NewWorkspaceType.Workspace; + #endregion public override void ExecuteCmdlet() { using (var client = this.CreateClient()) { - var result = client.Workspaces.NewWorkspaceAsUser(this.Name); + var result = client.Workspaces.NewWorkspaceAsUser(this.Name, this.Type == NewWorkspaceType.Workspace); this.Logger.WriteObject(result, true); } } } + + public enum NewWorkspaceType + { + Workspace, + Group + } } diff --git a/src/Modules/Workspaces/Commands.Workspaces/help/New-PowerBIWorkspace.md b/src/Modules/Workspaces/Commands.Workspaces/help/New-PowerBIWorkspace.md index 634f04ec..33825a1c 100644 --- a/src/Modules/Workspaces/Commands.Workspaces/help/New-PowerBIWorkspace.md +++ b/src/Modules/Workspaces/Commands.Workspaces/help/New-PowerBIWorkspace.md @@ -13,7 +13,7 @@ Creates a new Power BI workspace. ## SYNTAX ``` -New-PowerBIWorkspace -Name [] +New-PowerBIWorkspace -Name [-Type ] [] ``` ## DESCRIPTION @@ -45,6 +45,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Type +Type of workspace to be created. Options are Workspace or Group. Default is Workspace. + +```yaml +Type: NewWorkspaceType +Parameter Sets: (All) +Aliases: WorkspaceType + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). From 20be9315048df6a1741cad73f25c67ff8aed8a49 Mon Sep 17 00:00:00 2001 From: Chaz Beck Date: Thu, 9 May 2019 16:06:14 -0700 Subject: [PATCH 5/5] Adding back in a using namespace to System for datasource contract --- src/Common/Common.Api/Datasets/Datasource.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Common/Common.Api/Datasets/Datasource.cs b/src/Common/Common.Api/Datasets/Datasource.cs index 9e0af9cb..9724fa83 100644 --- a/src/Common/Common.Api/Datasets/Datasource.cs +++ b/src/Common/Common.Api/Datasets/Datasource.cs @@ -3,6 +3,8 @@ * Licensed under the MIT License. */ +using System; + namespace Microsoft.PowerBI.Common.Api.Datasets { public class Datasource