From bdb97bfd0ac3c314fb416352ee84bf2aa2fd41a7 Mon Sep 17 00:00:00 2001
From: NoriZC <110961157+NoriZC@users.noreply.github.com>
Date: Tue, 7 Mar 2023 17:16:12 +0800
Subject: [PATCH] Test removing automapper (#21135)
---
src/Monitor/Monitor/Az.Monitor.psd1 | 3 +-
src/Monitor/Monitor/Monitor.csproj | 1 -
.../PSMonitorPrivateLinkScope.cs | 14 +++++++
.../PSMonitorPrivateLinkScopedResource.cs | 14 +++++++
...rivateLinkScopeCreateOrUpdateCmdletBase.cs | 1 -
.../GetAzureInsightsPrivateLinkScope.cs | 7 ++--
...tAzureInsightsPrivateLinkScopedResource.cs | 5 +--
.../NewAzureInsightsPrivateLinkScope.cs | 3 +-
...wAzureInsightsPrivateLinkScopedResource.cs | 3 +-
.../UpdateAzureInsightsPrivateLinkScope.cs | 3 +-
src/Monitor/Monitor/Utils/PSMapper.cs | 40 -------------------
11 files changed, 37 insertions(+), 57 deletions(-)
delete mode 100644 src/Monitor/Monitor/Utils/PSMapper.cs
diff --git a/src/Monitor/Monitor/Az.Monitor.psd1 b/src/Monitor/Monitor/Az.Monitor.psd1
index 9fe7bd0769a4..fd49b17754cb 100644
--- a/src/Monitor/Monitor/Az.Monitor.psd1
+++ b/src/Monitor/Monitor/Az.Monitor.psd1
@@ -56,8 +56,7 @@ DotNetFrameworkVersion = '4.7.2'
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.11.2'; })
# Assemblies that must be loaded prior to importing this module
-RequiredAssemblies = 'Microsoft.Azure.Management.Monitor.dll',
- 'Microsoft.Azure.PowerShell.AutoMapper.dll',
+RequiredAssemblies = 'Microsoft.Azure.Management.Monitor.dll',
'ActivityLogAlert.Autorest\bin\Az.ActivityLogAlert.private.dll',
'DiagnosticSetting.Autorest\bin\Az.DiagnosticSetting.private.dll',
'ScheduledQueryRule.Autorest\bin\Az.ScheduledQueryRule.private.dll',
diff --git a/src/Monitor/Monitor/Monitor.csproj b/src/Monitor/Monitor/Monitor.csproj
index d35dafa87564..7063d72894b9 100644
--- a/src/Monitor/Monitor/Monitor.csproj
+++ b/src/Monitor/Monitor/Monitor.csproj
@@ -12,7 +12,6 @@
-
diff --git a/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScope.cs b/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScope.cs
index d2c1027a6ef5..13516968334f 100644
--- a/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScope.cs
+++ b/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScope.cs
@@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------
using System.Collections.Generic;
+using Microsoft.Azure.Management.Monitor.Models;
using Newtonsoft.Json;
namespace Microsoft.Azure.Commands.Insights.OutputClasses
@@ -34,6 +35,19 @@ public PSMonitorPrivateLinkScope() { }
this.ProvisioningState = provisioningState;
}
+ internal static PSMonitorPrivateLinkScope ToPSMonitorPrivateLinkScope(AzureMonitorPrivateLinkScope scope)
+ {
+ return new PSMonitorPrivateLinkScope
+ {
+ Id = scope.Id,
+ Name = scope.Name,
+ Type = scope.Type,
+ Location = scope.Location,
+ Tags = scope.Tags,
+ ProvisioningState = scope.ProvisioningState
+ };
+ }
+
///
/// Gets azure resource Id
///
diff --git a/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScopedResource.cs b/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScopedResource.cs
index 339d71a1d833..b2cd271dfbf1 100644
--- a/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScopedResource.cs
+++ b/src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScopedResource.cs
@@ -13,6 +13,8 @@
// ----------------------------------------------------------------------------------
using System.Collections.Generic;
+using System.Net.Mail;
+using Microsoft.Azure.Management.Monitor.Models;
using Newtonsoft.Json;
namespace Microsoft.Azure.Commands.Insights.OutputClasses
@@ -57,5 +59,17 @@ public class PSMonitorPrivateLinkScopedResource
///
[JsonProperty(PropertyName = "properties.provisioningState")]
public string ProvisioningState { get; private set; }
+
+ internal static PSMonitorPrivateLinkScopedResource ToPSMonitorPrivateLinkScopedResource(ScopedResource scope)
+ {
+ return new PSMonitorPrivateLinkScopedResource
+ {
+ Id = scope.Id,
+ Name = scope.Name,
+ Type = scope.Type,
+ LinkedResourceId = scope.LinkedResourceId,
+ ProvisioningState = scope.ProvisioningState
+ };
+ }
}
}
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/AzureInsightsPrivateLinkScopeCreateOrUpdateCmdletBase.cs b/src/Monitor/Monitor/PrivateLinkScopes/AzureInsightsPrivateLinkScopeCreateOrUpdateCmdletBase.cs
index 7ff0b6d848ae..36306f5da218 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/AzureInsightsPrivateLinkScopeCreateOrUpdateCmdletBase.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/AzureInsightsPrivateLinkScopeCreateOrUpdateCmdletBase.cs
@@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Collections.Generic;
using System.Linq;
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScope.cs b/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScope.cs
index bd36a06178b3..38b0c02d136d 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScope.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScope.cs
@@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;
@@ -72,14 +71,14 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.ListByResourceGroupWithHttpMessagesAsync(this.ResourceGroupName)
.Result;
- WriteObject(response.Body.Select(scope => PSMapper.Instance.Map(scope)).ToList(), true);
+ WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(scope)).ToList(), true);
}
else
{
var response = this.MonitorManagementClient
.PrivateLinkScopes.ListWithHttpMessagesAsync()
.Result;
- WriteObject(response.Body.Select(scope => PSMapper.Instance.Map(scope)).ToList(), true);
+ WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(scope)).ToList(), true);
}
}
else if (ParameterSetName.Equals(ByResourceNameParameterSet) || ParameterSetName.Equals(ResourceId))
@@ -95,7 +94,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.GetWithHttpMessagesAsync(this.ResourceGroupName, this.Name)
.Result;
- WriteObject(PSMapper.Instance.Map(response.Body));
+ WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScopedResource.cs b/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScopedResource.cs
index 5a033e38eea0..21b7022fdbbb 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScopedResource.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/GetAzureInsightsPrivateLinkScopedResource.cs
@@ -16,7 +16,6 @@
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;
@@ -98,7 +97,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopedResources
.ListByPrivateLinkScopeWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName)
.Result;
- WriteObject(response.Body.Select(scope => PSMapper.Instance.Map(scope)).ToList(), true);
+ WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(scope)).ToList(), true);
}
else if (this.IsParameterBound(c => c.Name))
{
@@ -106,7 +105,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopedResources
.GetWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName, this.Name)
.Result;
- WriteObject(PSMapper.Instance.Map(response.Body));
+ WriteObject(PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(response.Body));
}
}
}
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScope.cs b/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScope.cs
index 0433b5f9eb75..82e4d6fef892 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScope.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScope.cs
@@ -16,7 +16,6 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Management.Monitor.Models;
-using Microsoft.Azure.Commands.Insights.Utils;
using System.Linq;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
@@ -67,7 +66,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.Name, payLoad)
.Result;
- WriteObject(PSMapper.Instance.Map(response.Body));
+ WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScopedResource.cs b/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScopedResource.cs
index 76c6cd94a050..5be6fb8b376a 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScopedResource.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/NewAzureInsightsPrivateLinkScopedResource.cs
@@ -15,7 +15,6 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Monitor.Models;
namespace Microsoft.Azure.Commands.Insights.PrivateLinkScopes
@@ -56,7 +55,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopedResources
.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName, this.Name, this.LinkedResourceId)
.Result;
- WriteObject(PSMapper.Instance.Map(response.Body));
+ WriteObject(PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(response.Body));
}
}
diff --git a/src/Monitor/Monitor/PrivateLinkScopes/UpdateAzureInsightsPrivateLinkScope.cs b/src/Monitor/Monitor/PrivateLinkScopes/UpdateAzureInsightsPrivateLinkScope.cs
index fcabd6ffa61c..725fe3b5ac97 100644
--- a/src/Monitor/Monitor/PrivateLinkScopes/UpdateAzureInsightsPrivateLinkScope.cs
+++ b/src/Monitor/Monitor/PrivateLinkScopes/UpdateAzureInsightsPrivateLinkScope.cs
@@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Collections.Generic;
using System.Linq;
@@ -71,7 +70,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.UpdateTagsWithHttpMessagesAsync(this.ResourceGroupName, this.Name, this.Tags.ToDictionary(s => s.Split(':')[0], s => s.Split(':')[1]))
.Result;
- WriteObject(PSMapper.Instance.Map(response.Body));
+ WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
diff --git a/src/Monitor/Monitor/Utils/PSMapper.cs b/src/Monitor/Monitor/Utils/PSMapper.cs
deleted file mode 100644
index 400708940f46..000000000000
--- a/src/Monitor/Monitor/Utils/PSMapper.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// ----------------------------------------------------------------------------------
-//
-// Copyright Microsoft Corporation
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------------------------------------------------------------
-
-using AutoMapper;
-using Microsoft.Azure.Management.Monitor.Models;
-using Microsoft.Azure.Commands.Insights.OutputClasses;
-
-namespace Microsoft.Azure.Commands.Insights.Utils
-{
- class PSMapper
- {
- private static readonly IMapper _instance;
-
- static PSMapper()
- {
- var config = new MapperConfiguration(cfg =>
- {
- cfg.CreateMap().ReverseMap();
- cfg.CreateMap().ReverseMap();
- cfg.CreateMap().ReverseMap();
- cfg.CreateMap().ReverseMap();
- cfg.CreateMap().ReverseMap();
- });
- _instance = config.CreateMapper();
- }
-
- public static IMapper Instance { get { return _instance; } }
- }
-}