Skip to content

Commit

Permalink
Revert "Fix mockContext for fixtures. (Azure#34)" (Azure#37)
Browse files Browse the repository at this point in the history
This reverts commit 768ba77.
  • Loading branch information
romahamu authored Mar 16, 2020
1 parent af8cee3 commit b5bc02d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 80 deletions.
22 changes: 18 additions & 4 deletions src/StorageCache/HPCCache.Test/Fixtures/HpcCacheTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace Microsoft.Azure.Commands.HPCCache.Test.Fixtures
using Microsoft.Azure.Commands.HPCCache.Test.Utilities;
using Microsoft.Azure.Management.Authorization;
using Microsoft.Azure.Management.Authorization.Models;
using Microsoft.Azure.Management.Internal.Resources;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.Management.StorageCache.Models;
using Microsoft.Rest.Azure;
Expand All @@ -49,17 +49,31 @@ public class HpcCacheTestContext : IDisposable
/// </summary>
private bool disposedValue = false;

/// <summary>
/// Initializes a new instance of the <see cref="HpcCacheTestContext"/> class.
/// </summary>
/// <param name="suiteObject">Class object.</param>
/// <param name="methodName">Method name of the calling method.</param>
public HpcCacheTestContext(
object suiteObject,
[System.Runtime.CompilerServices.CallerMemberName]
string methodName = ".ctor")
{
this.mockContext = MockContext.Start(suiteObject.GetType().Name, methodName);
this.RegisterSubscriptionForResource("Microsoft.StorageCache");
}

/// <summary>
/// Initializes a new instance of the <see cref="HpcCacheTestContext"/> class.
/// </summary>
/// <param name="type">Class type.</param>
/// <param name="methodName">Method name of the calling method.</param>
public HpcCacheTestContext(
string className,
Type type,
[System.Runtime.CompilerServices.CallerMemberName]
string methodName = ".ctor")
{
this.mockContext = MockContext.Start(className, methodName);
this.mockContext = MockContext.Start(type.Name, methodName);
this.RegisterSubscriptionForResource("Microsoft.StorageCache");
}

Expand Down
11 changes: 3 additions & 8 deletions src/StorageCache/HPCCache.Test/Fixtures/HpcCacheTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
namespace Microsoft.Azure.Commands.HPCCache.Test.Fixtures
{
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.Azure.Commands.HPCCache.Test.Helper;
using Microsoft.Azure.Commands.HPCCache.Test.Utilities;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.Management.StorageCache.Models;
using Microsoft.Azure.Test.HttpRecorder;
Expand Down Expand Up @@ -60,13 +59,9 @@ public class HpcCacheTestFixture : IDisposable
/// </summary>
public HpcCacheTestFixture()
{
var sf = new StackTrace().GetFrame(1);
var callingClassType = sf.GetMethod().ReflectedType?.ToString();
var mockName = sf.GetMethod().Name;

using (this.Context = new HpcCacheTestContext(callingClassType, mockName))
using (this.Context = new HpcCacheTestContext(this))
{
//this.Context = new HpcCacheTestContext(this);
this.Context = new HpcCacheTestContext(this);
try
{
StorageCacheManagementClient storagecacheMgmtClient = this.Context.GetClient<StorageCacheManagementClient>();
Expand Down
18 changes: 7 additions & 11 deletions src/StorageCache/HPCCache.Test/Fixtures/StorageAccountFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Web;
using Microsoft.Azure.Commands.HPCCache.Test.Helper;
using Microsoft.Azure.Commands.HPCCache.Test.Utilities;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Azure.Management.StorageCache;
Expand Down Expand Up @@ -46,12 +46,9 @@ public class StorageAccountFixture : IDisposable
public StorageAccountFixture(HpcCacheTestFixture fixture)
{
this.fixture = fixture;
var sf = new StackTrace().GetFrame(1);
var callingClassType = sf.GetMethod().ReflectedType?.ToString();
var mockName = sf.GetMethod().Name;
using (this.Context = new HpcCacheTestContext(callingClassType, mockName))
using (this.Context = new HpcCacheTestContext(this))
{
// this.Context = new HpcCacheTestContext(this);
this.Context = new HpcCacheTestContext(this);
this.StorageTarget = this.AddClfsStorageTarget(this.Context);
Match clfsTargetMatch = ClfsTargetRegex.Match(this.StorageTarget.Clfs.Target);
var storageAccountName = clfsTargetMatch.Groups["StorageAccountName"].Value;
Expand Down Expand Up @@ -80,12 +77,11 @@ public StorageAccountFixture(HpcCacheTestFixture fixture)
/// </summary>
public StorageTarget StorageTarget { get; set; }

/// <summary>
/// Dispose the object.
/// </summary>
/// <inheritdoc/>
public void Dispose()
{
this.Context.Dispose();
// We do not create anything in this fixture but
// just use the HpcCacheTestFixture which has its own disposal method.
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/StorageCache/HPCCache.Test/HPCCache.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.StorageCache" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.18.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="13.1.0" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.11.0-preview" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HPCCache\HPCCache.csproj" />
</ItemGroup>

</Project>
6 changes: 5 additions & 1 deletion src/StorageCache/HPCCache.Test/Helper/CacheHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ namespace Microsoft.Azure.Commands.HPCCache.Test.Helper
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.HPCCache.Test.Utilities;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.Management.StorageCache.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit.Abstractions;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Microsoft.Azure.Commands.HPCCache.Test.Helper
{
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Sku = Microsoft.Azure.Management.Storage.Models.Sku;
Expand Down
50 changes: 0 additions & 50 deletions src/StorageCache/HPCCache.Test/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.Azure.Commands.HPCCache.Test.ScenarioTests
using System.Linq;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.HPCCache.Test.Fixtures;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Internal.Resources;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.ServiceManagement.Common.Models;
Expand Down

0 comments on commit b5bc02d

Please sign in to comment.