I have a series of NUnit tests, some of them fail, but I cannot find the reason, and the exception tells me nothing. This is my case:
//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); }
Unit Test Exception:
System.AccessViolationException: Attempted to read or write protected memory. This often indicates that another memory is corrupted.
If in my action I pass a null value to a partial view, for example: return PartialView(@"MyPartialView", null); Then the test passes.
Other similar cases fail, but others pass. I could not determine the reason for each.
Can someone help me determine what is wrong?
Thanks,
EDIT: Ok, I fixed ALL other failed tests, and now I only have those with a System.AccessViolationException .
ADDED Installation procedure generates my tests:
[SetUp] public void SetUp() { controllerBuilder = new TestControllerBuilder(); repository = MockRepository.GenerateStub<ISomeRepository>(); someController = new SomeController (repository); controllerBuilder.InitializeController(someController); }
Ajc source share