Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change unit tests to run unit tests if environment variable or emulat… #427

Merged
merged 3 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
using Microsoft.Bot.Builder.Core.Extensions;
using Microsoft.Bot.Builder.Core.Extensions.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage;

namespace Microsoft.Bot.Builder.Azure.Tests
{
[TestClass]
[TestCategory("Storage")]
[TestCategory("Storage - Azure Blob")]
public class BlobtorageTests : StorageBaseTests
public class BlobStorageTests : StorageBaseTests
{
private IStorage storage;

Expand All @@ -24,8 +24,8 @@ public class BlobtorageTests : StorageBaseTests
private static TestContext _testContext;

private static string emulatorPath = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\azurestorageemulator.exe");
private const string noEmulatorMessage = "This test requires Azure Storage Emulator! go to https://go.microsoft.com/fwlink/?LinkId=717179 to download and install.";
private const string DataConnectionString = "UseDevelopmentStorage=true";
private const string noEmulatorMessage = "This test requires Azure Storage Emulator! go to https://go.microsoft.com/fwlink/?LinkId=717179 to download and install.";
private string connectionString = null;
private static Lazy<bool> hasStorageEmulator = new Lazy<bool>(() =>
{
if (File.Exists(emulatorPath))
Expand All @@ -51,81 +51,81 @@ public static void SetupTests(TestContext testContext)

private string _containerName;

private const string emulatorConnectionString = "UseDevelopmentStorage=true";

[TestInitialize]
public void TestInit()
{
if (hasStorageEmulator.Value)
connectionString = Environment.GetEnvironmentVariable("STORAGECONNECTIONSTRING") ?? emulatorConnectionString;

if (connectionString != emulatorConnectionString || hasStorageEmulator.Value)
{
_containerName = TestContext.TestName.ToLowerInvariant().Replace("_", "") + TestContext.GetHashCode().ToString("x");
storage = new AzureBlobStorage(DataConnectionString, _containerName);
_containerName = TestContext.TestName.ToLowerInvariant().Replace("_", "") + TestContext.GetHashCode().ToString("x");
storage = new AzureBlobStorage(connectionString, _containerName);
}
}

[TestCleanup]
public async Task BlobStorage_TestCleanUp()
{
if (storage != null)
{
var storageAccount = CloudStorageAccount.Parse(DataConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(_containerName);
await container.DeleteIfExistsAsync();
if (storage != null)
{
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(_containerName);
await container.DeleteIfExistsAsync();
}
}

public bool CheckStorageEmulator()
public bool HasStorage()
{
if (!hasStorageEmulator.Value)
Debug.WriteLine(noEmulatorMessage);
if (Debugger.IsAttached)
Assert.IsTrue(hasStorageEmulator.Value, noEmulatorMessage);
return hasStorageEmulator.Value;
return storage != null;
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task BlobStorage_CreateObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._createObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task BlobStorage_ReadUnknownTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._readUnknownTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task BlobStorage_UpdateObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._updateObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task BlobStorage_DeleteObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._deleteObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task BlobStorage_HandleCrazyKeys()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._handleCrazyKeys(storage);
}

[TestMethod]
public async Task BlobStorage_TypedSerialization()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._typedSerialization(this.storage);
}
}
Expand Down
39 changes: 20 additions & 19 deletions tests/Microsoft.Bot.Builder.Azure.Tests/BlobTranscriptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,78 +40,79 @@ public class BlobTranscriptTests : TranscriptBaseTests
return false;
});

public static bool CheckStorageEmulator()
public bool HasStorage()
{
if (!hasStorageEmulator.Value)
System.Diagnostics.Debug.WriteLine(noEmulatorMessage);
if (System.Diagnostics.Debugger.IsAttached)
Assert.IsTrue(hasStorageEmulator.Value, noEmulatorMessage);
return hasStorageEmulator.Value;
return this.store != null;
}

public static CloudStorageAccount cloudStorageAccount;

[ClassInitialize]
public static void Initialize(TestContext context)
{
if (CheckStorageEmulator())
cloudStorageAccount = (hasStorageEmulator.Value) ? CloudStorageAccount.DevelopmentStorageAccount : null;
var connectionString = Environment.GetEnvironmentVariable("STORAGECONNECTIONSTRING");
if (!String.IsNullOrEmpty(connectionString))
cloudStorageAccount = CloudStorageAccount.Parse(connectionString);

if (cloudStorageAccount != null)
{
var containerName = "BlobTranscriptTests".ToLower();
var blobClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
container.DeleteIfExistsAsync().Wait();
cloudStorageAccount.CreateCloudBlobClient().GetContainerReference(nameof(BlobTranscriptTests).ToLower()).DeleteIfExistsAsync().Wait();
}
}

public BlobTranscriptTests() : base()
{
this.store = new AzureBlobTranscriptStore(CloudStorageAccount.DevelopmentStorageAccount, "BlobTranscriptTests");
if (cloudStorageAccount != null)
this.store = new AzureBlobTranscriptStore(cloudStorageAccount, nameof(BlobTranscriptTests));
}

[TestMethod]
public async Task BlobTranscript_BadArgs()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._BadArgs();
}

[TestMethod]
public async Task BlobTranscript_LogActivity()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._LogActivity();
}

[TestMethod]
public async Task BlobTranscript_LogMultipleActivities()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._LogMultipleActivities();
}

[TestMethod]
public async Task BlobTranscript_GetConversationActivities()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._GetTranscriptActivities();
}

[TestMethod]
public async Task BlobTranscript_GetConversationActivitiesStartDate()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._GetTranscriptActivitiesStartDate();
}

[TestMethod]
public async Task BlobTranscript_ListConversations()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._ListTranscripts();
}

[TestMethod]
public async Task BlobTranscript_DeleteConversation()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._DeleteTranscript();
}

Expand Down
30 changes: 16 additions & 14 deletions tests/Microsoft.Bot.Builder.Azure.Tests/TableStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Bot.Builder.Core.Extensions;
using Microsoft.Bot.Builder.Core.Extensions.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Storage;

namespace Microsoft.Bot.Builder.Azure.Tests
{
Expand Down Expand Up @@ -51,9 +52,14 @@ public static void SetupTests(TestContext testContext)
[TestInitialize]
public void TestInit()
{
if (hasStorageEmulator.Value)
var cloudStorageAccount = (hasStorageEmulator.Value) ? CloudStorageAccount.DevelopmentStorageAccount : null;
var connectionString = Environment.GetEnvironmentVariable("STORAGECONNECTIONSTRING") ;
if (!String.IsNullOrEmpty(connectionString))
cloudStorageAccount = CloudStorageAccount.Parse(connectionString);

if (cloudStorageAccount != null)
{
storage = new AzureTableStorage("UseDevelopmentStorage=true", TestContext.TestName.Replace("_","") + TestContext.GetHashCode().ToString("x"));
storage = new AzureTableStorage(cloudStorageAccount, TestContext.TestName.Replace("_","") + TestContext.GetHashCode().ToString("x"));
}
}

Expand All @@ -67,59 +73,55 @@ public async Task TableStorage_TestCleanUp()
}
}

public bool CheckStorageEmulator()
public bool HasStorage()
{
if (!hasStorageEmulator.Value)
Debug.WriteLine(noEmulatorMessage);
if (Debugger.IsAttached)
Assert.IsTrue(hasStorageEmulator.Value, noEmulatorMessage);
return hasStorageEmulator.Value;
return storage != null;
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task TableStorage_CreateObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._createObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task TableStorage_ReadUnknownTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._readUnknownTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task TableStorage_UpdateObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._updateObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task TableStorage_DeleteObjectTest()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._deleteObjectTest(storage);
}

// NOTE: THESE TESTS REQUIRE THAT THE AZURE STORAGE EMULATOR IS INSTALLED AND STARTED !!!!!!!!!!!!!!!!!
[TestMethod]
public async Task TableStorage_HandleCrazyKeys()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._handleCrazyKeys(storage);
}

[TestMethod]
public async Task TableStorage_TypedSerialization()
{
if (CheckStorageEmulator())
if (HasStorage())
await base._typedSerialization(this.storage);
}
}
Expand Down