由于System.AccessViolationException,NUnit测试失败

AJC*_*AJC 6 c# nunit unit-testing asp.net-mvc-3

我有一系列NUnit测试,有些失败,但我似乎无法找到原因,而且异常告诉我什么.这是我的情况:

    //Controller Action
    [HttpPost]
    [AjaxExceptionHandler]
    [OutputCache(Duration = 0)]
    public PartialViewResult SomeAction(long id)
    {
        try
        {
            var model = _repository.GetModel(id);
            return PartialView(@"MyPartialView", model);
        }
        catch (Exception ex)
        {
            exceptionManager.HandleException(ex, FT_EXCEPTION_POLICY);
            throw;
        }
    }

    //Action Unit Test
    [Test]
    [Category(TestConstants.UnitTest)]
    public void SomeAction_Returns_Expected_View()
    {
        var model = Builder<ViewModel>.CreateNew().Build();

        repository.Stub(it => it.GetModel(Arg<long>.Is.Anything)).Return(model);

        var viewResult = (PartialViewResult)someController.SomeAction(1);
        Assert.AreEqual(@"MyPartialView", viewResult.ViewName);
    }       
Run Code Online (Sandbox Code Playgroud)

单元测试例外:

System.AccessViolationException:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.

如果在我的操作中,我将null值传递给局部视图,如下所示:return PartialView(@"MyPartialView", null);然后测试通过.

其他类似的案例也失败了,但其他案件也通过了.我无法确定每个原因.

谁能帮我辨别出什么问题?

谢谢,

编辑:好的,我修复了所有其他失败的测试,现在我只剩下System.AccessViolationException.

从我的测试中添加安装程序:

    [SetUp]
    public void SetUp()
    {
        controllerBuilder = new TestControllerBuilder();

        repository = MockRepository.GenerateStub<ISomeRepository>();

        someController = new SomeController
            (repository);

        controllerBuilder.InitializeController(someController);
    }
Run Code Online (Sandbox Code Playgroud)

AJC*_*AJC 3

找到了答案......非常愚蠢的问题,就像编程中的大多数问题一样。正如我常说的,如果你在最初的几个小时内无法解决它,那么你就知道这确实是非常愚蠢的事情。

这是我找到答案的地方,花了我一段时间,但问题的名称也没有帮助:

尝试读取或写入受保护的内存

简而言之,我必须更换 MVCContrib Dll。

感谢大家的帮助...