forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#16283 from Azure/bez/fix
Fix conflicts
- Loading branch information
Showing
19 changed files
with
320 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Sql/Sql.Test/UnitTests/ResourceWildcardFilterHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Microsoft.Azure.Commands.Sql.Common; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests | ||
{ | ||
public class ResourceWildcardFilterHelperTests | ||
{ | ||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void SqlSubResourceWildcardFilterTest() | ||
{ | ||
ResourceWildcardFilterHelper wildcardFilterHelper = new ResourceWildcardFilterHelper(); | ||
|
||
// should match test01 | ||
Assert.Single(wildcardFilterHelper.SqlSubResourceWildcardFilter("test01", ReturnedResources, "PropertyName1")); | ||
// should match none | ||
Assert.Empty(wildcardFilterHelper.SqlSubResourceWildcardFilter("test", ReturnedResources, "PropertyName1")); | ||
// should match all | ||
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter("t*t*", ReturnedResources, "PropertyName1").Count); | ||
// should match none | ||
Assert.Empty(wildcardFilterHelper.SqlSubResourceWildcardFilter("t*t", ReturnedResources, "PropertyName1")); | ||
// should match test01 and test11 | ||
Assert.Equal(2, wildcardFilterHelper.SqlSubResourceWildcardFilter("t*1", ReturnedResources, "PropertyName1").Count); | ||
// should match all because empty value | ||
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter(string.Empty, ReturnedResources, "PropertyName1").Count); | ||
// should match all because null property name | ||
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter("anything", ReturnedResources, null).Count); | ||
} | ||
|
||
private readonly List<TestResource> ReturnedResources = new List<TestResource>() | ||
{ | ||
new TestResource("test01", "case01"), | ||
new TestResource("test02", "case02"), | ||
new TestResource("test03", "case03"), | ||
new TestResource("test04", "case04"), | ||
new TestResource("test05", "case05"), | ||
new TestResource("test06", "case06"), | ||
new TestResource("test07", "case07"), | ||
new TestResource("test08", "case08"), | ||
new TestResource("test09", "case09"), | ||
new TestResource("test10", "case10"), | ||
new TestResource("test11", "case11"), | ||
}; | ||
} | ||
|
||
internal class TestResource | ||
{ | ||
public TestResource(string PropertyName1, string PropertyName2) | ||
{ | ||
this.PropertyName1 = PropertyName1; | ||
this.PropertyName2 = PropertyName2; | ||
} | ||
|
||
public string PropertyName1 { get; set; } | ||
|
||
public string PropertyName2 { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Sql.Common | ||
{ | ||
public class ResourceWildcardFilterHelper | ||
{ | ||
public List<T> SqlSubResourceWildcardFilter<T>(string value, IEnumerable<T> resources, string propertyName) | ||
{ | ||
if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(propertyName)) | ||
{ | ||
IEnumerable<T> output = resources; | ||
WildcardPattern pattern = new WildcardPattern(value, WildcardOptions.IgnoreCase); | ||
output = output.Where(t => IsMatch(t, propertyName, pattern)); | ||
|
||
return output.ToList(); | ||
} | ||
else | ||
{ | ||
return resources.ToList(); | ||
} | ||
} | ||
|
||
private bool IsMatch<T>(T resource, string property, WildcardPattern pattern) | ||
{ | ||
var value = (string)GetPropertyValue(resource, property); | ||
return !string.IsNullOrEmpty(value) && pattern.IsMatch(value); | ||
} | ||
|
||
private object GetPropertyValue<T>(T resource, string property) | ||
{ | ||
System.Reflection.PropertyInfo pi = typeof(T).GetProperty(property); | ||
if (pi != null) | ||
{ | ||
return pi.GetValue(resource, null); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Synapse/Synapse/Models/DataPlaneModels/Artifact/Notebooks/PSNotebookFolder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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 Azure.Analytics.Synapse.Artifacts.Models; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Azure.Commands.Synapse.Models | ||
{ | ||
public class PSNotebookFolder | ||
{ | ||
public PSNotebookFolder(NotebookFolder folder) | ||
{ | ||
this.Name = folder?.Name; | ||
} | ||
|
||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...Synapse/Models/DataPlaneModels/Artifact/SparkJobDefinitions/PSSparkJobDefinitionFolder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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 Azure.Analytics.Synapse.Artifacts.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Synapse.Models | ||
{ | ||
public class PSSparkJobDefinitionFolder | ||
{ | ||
public PSSparkJobDefinitionFolder(SparkJobDefinitionFolder folder) | ||
{ | ||
this.Name = folder?.Name; | ||
} | ||
|
||
public string Name { get; set; } | ||
} | ||
} |
Oops, something went wrong.