Skip to content

Instantly share code, notes, and snippets.

@richorama
Last active August 29, 2015 14:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richorama/8dc3d9c5da8be778ebe1 to your computer and use it in GitHub Desktop.
Save richorama/8dc3d9c5da8be778ebe1 to your computer and use it in GitHub Desktop.
A unit testing class for Orleans Silos
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Orleans.Host.SiloHost;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Tests
{
[TestClass]
public class GrainTests
{
[TestMethod]
public async Task TestGrains()
{
// insert your grain test code here
var grain = MyGrainFactory.GetGrain(1234);
await grain.Foo();
}
// code to initialize and clean up an Orleans Silo
static OrleansSiloHost siloHost;
static AppDomain hostDomain;
static void InitSilo(string[] args)
{
siloHost = new OrleansSiloHost("test");
siloHost.ConfigFileName = "DevTestServerConfiguration.xml";
siloHost.DeploymentId = "1";
siloHost.InitializeOrleansSilo();
var ok = siloHost.StartOrleansSilo();
if (!ok) throw new SystemException(string.Format("Failed to start Orleans silo '{0}' as a {1} node.", siloHost.SiloName, siloHost.SiloType));
}
[ClassInitialize]
public static void GrainTestsClassInitialize(TestContext testContext)
{
hostDomain = AppDomain.CreateDomain("OrleansHost", null, new AppDomainSetup
{
AppDomainInitializer = InitSilo,
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
});
Orleans.OrleansClient.Initialize("DevTestClientConfiguration.xml");
}
[ClassCleanup]
public static void GrainTestsClassCleanUp()
{
hostDomain.DoCallBack(() =>
{
siloHost.Dispose();
siloHost = null;
AppDomain.Unload(hostDomain);
});
var startInfo = new ProcessStartInfo
{
FileName = "taskkill",
Arguments = "/F /IM vstest.executionengine.x86.exe",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
};
Process.Start(startInfo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment