Skip to content

Instantly share code, notes, and snippets.

@Cheesebaron
Created March 24, 2017 12:49
Show Gist options
  • Save Cheesebaron/99dd5f4ff662e6750aadd037e330cd6c to your computer and use it in GitHub Desktop.
Save Cheesebaron/99dd5f4ff662e6750aadd037e330cd6c to your computer and use it in GitHub Desktop.
MvvmCross xUnit Fixture
public class MvxFixture : IDisposable
{
public MvxFixture()
{
MvxTest.Initialize();
}
~MvxFixture()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// dispose shit here...
}
}
}
[CollectionDefinition("MvxTests")]
public class MvxTestCollection : ICollectionFixture<MvxFixture>
{
}
public static class MvxTest
{
private static bool _initialized;
public static void Initialize()
{
if (_initialized) return;
MvxSingleton.ClearAllSingletons();
var ioc = MvxSimpleIoCContainer.Initialize();
ioc.RegisterSingleton(ioc);
ioc.RegisterSingleton<IMvxTrace>(new TestTrace());
MvxSingletonCache.Initialize();
InitializeMvxSettings(ioc);
AdditionalSetup(ioc);
MvxTrace.Initialize();
_initialized = true;
}
private static void InitializeMvxSettings(IMvxIoCProvider ioc)
{
ioc.RegisterSingleton<IMvxSettings>(new MvxSettings());
}
private static void AdditionalSetup(IMvxIoCProvider ioc)
{
ioc.RegisterSingleton<IMvxTextProvider>(new ResxTextProvider());
// register more shit here...
}
public static void SetInvariantCulture()
{
var invariantCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = invariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = invariantCulture;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment