MvvmCross:如何使用从MvxIoCSupportingTest派生的多个测试类

时间:2015-11-22 10:15:01

标签: c# unit-testing mvvmcross

我有两个xUnit测试类,派生自MvxIoCSupportingTest。 运行我的单元测试我收到错误消息:

Cirrious.CrossCore.Exceptions.MvxException : You should only initialize MvxBindingSingletonCache once

有没有办法明确地将IoC实例化为符号?

1 个答案:

答案 0 :(得分:1)

使用此类而不是MvxIoCSupportingTest

using MvvmCross.Core;
using MvvmCross.Core.Platform;
using MvvmCross.Platform.IoC;
using MvvmCross.Platform.Platform;

namespace MvvmCross.Test.Core
{
    public class BaseMvvmCrossTest
    {
        static BaseMvvmCrossTest()
        {
            if (MvxSimpleIoCContainer.Instance == null)
            {
                MvxSingletonCache.Initialize();
                MvxSimpleIoCContainer.Initialize();

                MvxSimpleIoCContainer.Instance.RegisterSingleton(MvxSimpleIoCContainer.Instance);
                MvxSimpleIoCContainer.Instance.RegisterSingleton<IMvxTrace>(new TestTrace());
                MvxSimpleIoCContainer.Instance.RegisterSingleton<IMvxSettings>(new MvxSettings());

                MvxTrace.Initialize();
            }
        }
    }
}