Permalink
Browse files

Bunch of changes

- Make HttpRestMessageInspector generic logger not thighed to PowerShell
- Inject Moq in the Store tests
- Change GetAzureStoreAvailableAddOnTest to use Moq
- Refactor the Store related code into StoreClient.cs
- Add Get-AzureStoreAddOn cmdlet
  • Loading branch information...
1 parent be4ab39 commit 29e39bcd4f042907c9359c591af0472e76e079ec @ogail committed Feb 12, 2013
Showing with 728 additions and 233 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 WindowsAzurePowershell/src/Management.CloudService/Cmdlet/TestAzureName.cs
  3. +7 −2 WindowsAzurePowershell/src/Management.Store.Test/Management.Store.Test.csproj
  4. +0 −101 WindowsAzurePowershell/src/Management.Store.Test/Stubs/SimpleMarketplaceManagement.cs
  5. +208 −0 WindowsAzurePowershell/src/Management.Store.Test/UnitTests/Cmdlet/GetAzureStoreAddOnTest.cs
  6. +32 −14 WindowsAzurePowershell/src/Management.Store.Test/UnitTests/Cmdlet/GetAzureStoreAvailableAddOnTest.cs
  7. +4 −0 WindowsAzurePowershell/src/Management.Store.Test/packages.config
  8. +1 −1 WindowsAzurePowershell/src/Management.Store/Cmdlet/Common/Parameter.cs
  9. +21 −47 WindowsAzurePowershell/src/Management.Store/Cmdlet/GetAzureStoreAddOn.cs
  10. +14 −24 WindowsAzurePowershell/src/Management.Store/Cmdlet/GetAzureStoreAvailableAddOn.cs
  11. +4 −0 WindowsAzurePowershell/src/Management.Store/Management.Store.csproj
  12. +96 −5 WindowsAzurePowershell/src/Management.Store/Microsoft.WindowsAzure.Management.Store.format.ps1xml
  13. +39 −0 WindowsAzurePowershell/src/Management.Store/Model/AddOn.cs
  14. +62 −0 WindowsAzurePowershell/src/Management.Store/Model/AddOnSearchOptions.cs
  15. +126 −0 WindowsAzurePowershell/src/Management.Store/Model/StoreClient.cs
  16. +38 −0 WindowsAzurePowershell/src/Management.Store/Model/WindowsAzureOffer.cs
  17. +2 −2 WindowsAzurePowershell/src/Management/Cmdlets/Common/CloudBaseCmdlet.cs
  18. +24 −30 WindowsAzurePowershell/src/Management/Model/HttpRestMessageInspector.cs
  19. +15 −0 WindowsAzurePowershell/src/Management/Utilities/General.cs
  20. +2 −1 WindowsAzurePowershell/src/ServiceManagement/ServiceManagement.csproj
  21. +28 −0 WindowsAzurePowershell/src/ServiceManagement/Store/ResourceModel/Error.cs
  22. +2 −4 WindowsAzurePowershell/src/ServiceManagement/Store/ResourceModel/OperationStatus.cs
View
@@ -10,4 +10,5 @@ TestResults
*.orig
*.ncrunchsolution
/Publish
-/Package
+/Package
+/WindowsAzurePowershell/src/packages
@@ -116,7 +116,7 @@ public override void ExecuteCmdlet()
ServiceBinding,
new Uri(ServiceEndpoint),
CurrentSubscription.Certificate,
- new HttpRestMessageInspector(this));
+ new HttpRestMessageInspector(text => this.WriteDebug(text)));
}
IsServiceBusNamespaceAvailable(CurrentSubscription.SubscriptionId, Name);
@@ -63,6 +63,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Moq">
+ <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -81,7 +84,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Stubs\SimpleMarketplaceManagement.cs" />
+ <Compile Include="UnitTests\Cmdlet\GetAzureStoreAddOnTest.cs" />
<Compile Include="UnitTests\Cmdlet\GetAzureStoreAvailableAddOnTest.cs" />
</ItemGroup>
<ItemGroup>
@@ -106,7 +109,9 @@
<Name>ServiceManagement</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@@ -1,101 +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.
-// ----------------------------------------------------------------------------------
-
-namespace Microsoft.WindowsAzure.Management.Store.Test.Stubs
-{
- using System;
- using System.Collections.Generic;
- using Microsoft.Samples.WindowsAzure.ServiceManagement.Marketplace.Contract;
- using Microsoft.Samples.WindowsAzure.ServiceManagement.Marketplace.ResourceModel;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Microsoft.WindowsAzure.Management.Test.Tests.Utilities;
-
- class SimpleMarketplaceManagement : IMarketplaceManagement
- {
- /// <summary>
- /// Gets or sets a value indicating whether the thunk wrappers will
- /// throw an exception if the thunk is not implemented. This is useful
- /// when debugging a test.
- /// </summary>
- public bool ThrowsIfNotImplemented { get; set; }
-
- /// <summary>
- /// Initializes a new instance of the SimpleMarketplaceManagement class.
- /// </summary>
- public SimpleMarketplaceManagement()
- {
- ThrowsIfNotImplemented = true;
- }
-
- public Func<SimpleServiceManagementAsyncResult, List<Offer>> ListWindowsAzureOffersThunk { get; set; }
- public IAsyncResult BeginListWindowsAzureOffers(AsyncCallback callback, object state)
- {
- SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
- result.Values["callback"] = callback;
- result.Values["state"] = state;
-
- return result;
- }
-
- public List<Offer> EndListWindowsAzureOffers(IAsyncResult asyncResult)
- {
- List<Offer> offers = new List<Offer>();
-
- if (ListWindowsAzureOffersThunk != null)
- {
- SimpleServiceManagementAsyncResult result = asyncResult as SimpleServiceManagementAsyncResult;
- Assert.IsNotNull(result, "asyncResult was not SimpleServiceManagementAsyncResult!");
-
- offers = ListWindowsAzureOffersThunk(result);
- }
- else if (ThrowsIfNotImplemented)
- {
- throw new NotImplementedException("ListOffersThunk is not implemented!");
- }
-
- return offers;
- }
-
- public Func<SimpleServiceManagementAsyncResult, List<Plan>> ListOfferPlansThunk { get; set; }
- public IAsyncResult BeginListOfferPlans(string Id, string query, AsyncCallback callback, object state)
- {
- SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
- result.Values["Id"] = Id;
- result.Values["query"] = query;
- result.Values["callback"] = callback;
- result.Values["state"] = state;
-
- return result;
- }
-
- public List<Plan> EndListOfferPlans(IAsyncResult asyncResult)
- {
- List<Plan> OfferPlans = new List<Plan>();
-
- if (ListOfferPlansThunk != null)
- {
- SimpleServiceManagementAsyncResult result = asyncResult as SimpleServiceManagementAsyncResult;
- Assert.IsNotNull(result, "asyncResult was not SimpleServiceManagementAsyncResult!");
-
- OfferPlans = ListOfferPlansThunk(result);
- }
- else if (ThrowsIfNotImplemented)
- {
- throw new NotImplementedException("ListOfferPlansThunk is not implemented!");
- }
-
- return OfferPlans;
- }
- }
-}
@@ -0,0 +1,208 @@
+// ----------------------------------------------------------------------------------
+//
+// 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.
+// ----------------------------------------------------------------------------------
+
+namespace Microsoft.WindowsAzure.Management.Store.Test.UnitTests.Cmdlet
+{
+ using Microsoft.Samples.WindowsAzure.ServiceManagement.Store.Contract;
+ using Microsoft.WindowsAzure.Management.Store.Cmdlet;
+ using Microsoft.WindowsAzure.Management.Test.Stubs;
+ using Microsoft.WindowsAzure.Management.Test.Tests.Utilities;
+ using Moq;
+ using VisualStudio.TestTools.UnitTesting;
+ using System;
+ using Microsoft.Samples.WindowsAzure.ServiceManagement.Store.ResourceModel;
+ using System.Management.Automation;
+ using System.Collections.Generic;
+ using Microsoft.WindowsAzure.Management.Store.Model;
+
+ [TestClass]
+ public class GetAzureStoreAddOnTests : TestBase
+ {
+ [TestInitialize]
+ public void SetupTest()
+ {
+ Management.Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
+ new FileSystemHelper(this).CreateAzureSdkDirectoryAndImportPublishSettings();
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithEmptyCloudService()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ List<PSObject> actual = new List<PSObject>();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<List<PSObject>>())).Callback((object obj) => actual = (List<PSObject>)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ mockStoreClient.Setup(f => f.GetAddOn(It.IsAny<AddOnSearchOptions>())).Returns(new List<AddOn>());
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand() { StoreClient = mockStoreClient.Object, CommandRuntime = mockCommandRuntime.Object };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions(null, null, null)), Times.Exactly(1));
+ Assert.AreEqual<int>(0, actual.Count);
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithoutSearchOptions()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ List<PSObject> actual = new List<PSObject>();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<List<PSObject>>(), true)).Callback((object obj, bool isCollection) => actual = (List<PSObject>)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ List<AddOn> expected = new List<AddOn>();
+ expected.Add(new AddOn(new Resource() { Name = "BingSearchAddOn" }, "West US"));
+ expected.Add(new AddOn(new Resource() { Name = "BingTranslateAddOn" }, "West US"));
+ mockStoreClient.Setup(f => f.GetAddOn(It.IsAny<AddOnSearchOptions>())).Returns(expected);
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand() { StoreClient = mockStoreClient.Object, CommandRuntime = mockCommandRuntime.Object };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions(null, null, null)), Times.Exactly(1));
+ Assert.AreEqual<int>(expected.Count, actual.Count);
+
+ for (int i = 0; i < expected.Count; i++)
+ {
+ Assert.AreEqual<string>(expected[i].Info.Name, actual[i].GetVariableValue<string>("Name"));
+ Assert.AreEqual<string>(expected[i].GeoRegion, actual[i].GetVariableValue<string>("Location"));
+ }
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithNameFilter()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ PSObject actual = new PSObject();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<PSObject>())).Callback((object obj) => actual = (PSObject)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ List<AddOn> expected = new List<AddOn>();
+ expected.Add(new AddOn(new Resource() { Name = "BingTranslateAddOn" }, "West US"));
+ mockStoreClient.Setup(f => f.GetAddOn(new AddOnSearchOptions("BingTranslateAddOn", null, null))).Returns(expected);
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand() {
+ StoreClient = mockStoreClient.Object,
+ CommandRuntime = mockCommandRuntime.Object,
+ Name = "BingTranslateAddOn"
+ };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions("BingTranslateAddOn", null, null)), Times.Exactly(1));
+ Assert.AreEqual<string>(expected[0].Info.Name, actual.GetVariableValue<string>("Name"));
+ Assert.AreEqual<string>(expected[0].GeoRegion, actual.GetVariableValue<string>("Location"));
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithLocationFilter()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ List<PSObject> actual = new List<PSObject>();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<List<PSObject>>(), true)).Callback((object obj, bool isCollection) => actual = (List<PSObject>)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ List<AddOn> expected = new List<AddOn>();
+ expected.Add(new AddOn(new Resource() { Name = "BingSearchAddOn" }, "West US"));
+ expected.Add(new AddOn(new Resource() { Name = "MongoDB" }, "West US"));
+ expected.Add(new AddOn(new Resource() { Name = "BingTranslateAddOn" }, "West US"));
+ mockStoreClient.Setup(f => f.GetAddOn(new AddOnSearchOptions(null, null, "West US"))).Returns(expected);
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand() {
+ StoreClient = mockStoreClient.Object,
+ CommandRuntime = mockCommandRuntime.Object,
+ Location = "West US"
+ };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions(null, null, "West US")), Times.Exactly(1));
+ Assert.AreEqual<int>(expected.Count, actual.Count);
+
+ for (int i = 0; i < expected.Count; i++)
+ {
+ Assert.AreEqual<string>(expected[i].Info.Name, actual[i].GetVariableValue<string>("Name"));
+ Assert.AreEqual<string>("West US", actual[i].GetVariableValue<string>("Location"));
+ }
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithProviderFilter()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ List<PSObject> actual = new List<PSObject>();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<List<PSObject>>(), true)).Callback((object obj, bool isCollection) => actual = (List<PSObject>)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ List<AddOn> expected = new List<AddOn>();
+ expected.Add(new AddOn(new Resource() { Name = "BingSearchAddOn", ResourceProviderNamespace = "Microsoft" }, "West US"));
+ expected.Add(new AddOn(new Resource() { Name = "BingTranslateAddOn", ResourceProviderNamespace = "Microsoft" }, "West US"));
+ mockStoreClient.Setup(f => f.GetAddOn(new AddOnSearchOptions(null, "Microsoft", null))).Returns(expected);
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand()
+ {
+ StoreClient = mockStoreClient.Object,
+ CommandRuntime = mockCommandRuntime.Object,
+ Provider = "Microsoft"
+ };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions(null, "Microsoft", null)), Times.Exactly(1));
+ Assert.AreEqual<int>(expected.Count, actual.Count);
+
+ for (int i = 0; i < expected.Count; i++)
+ {
+ Assert.AreEqual<string>(expected[i].Info.Name, actual[i].GetVariableValue<string>("Name"));
+ Assert.AreEqual<string>("Microsoft", actual[i].GetVariableValue<string>("Provider"));
+ }
+ }
+
+ [TestMethod]
+ public void GetAzureStoreAddOnWithCompleteSearchOptions()
+ {
+ // Setup
+ Mock<ICommandRuntime> mockCommandRuntime = new Mock<ICommandRuntime>();
+ PSObject actual = new PSObject();
+ mockCommandRuntime.Setup(f => f.WriteObject(It.IsAny<PSObject>())).Callback((object obj) => actual = (PSObject)obj);
+ Mock<StoreClient> mockStoreClient = new Mock<StoreClient>();
+ List<AddOn> expected = new List<AddOn>();
+ expected.Add(new AddOn(new Resource() { Name = "BingSearchAddOn", ResourceProviderNamespace = "Microsoft" }, "West US"));
+ mockStoreClient.Setup(f => f.GetAddOn(new AddOnSearchOptions("BingSearchAddOn", "Microsoft", "West US"))).Returns(expected);
+ GetAzureStoreAddOnCommand cmdlet = new GetAzureStoreAddOnCommand()
+ {
+ StoreClient = mockStoreClient.Object,
+ CommandRuntime = mockCommandRuntime.Object,
+ Provider = "Microsoft",
+ Name = "BingSearchAddOn",
+ Location = "West US"
+ };
+
+ // Test
+ cmdlet.ExecuteCmdlet();
+
+ // Assert
+ mockStoreClient.Verify(f => f.GetAddOn(new AddOnSearchOptions("BingSearchAddOn", "Microsoft", "West US")), Times.Exactly(1));
+ Assert.AreEqual<string>("BingSearchAddOn", actual.GetVariableValue<string>("Name"));
+ Assert.AreEqual<string>("Microsoft", actual.GetVariableValue<string>("Provider"));
+ Assert.AreEqual<string>("West US", actual.GetVariableValue<string>("Location"));
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 29e39bc

Please sign in to comment.