I have a series of NUnit tests and some are failing, yet I can't seem to find a reason, and the exception is telling 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 is often an indication that other memory is corrupt.
If in my action I pass a null value to the partial view, like so: return PartialView(@"MyPartialView", null);
Then the test passes.
Other similar cases fail as well, yet others pass. I have not been able to identify a reason for each.
Can anyone help me identify what is wrong?
Thanks,
EDIT: Ok, I fixed ALL other failing tests and now I have only the ones with the System.AccessViolationException left.
ADDED Setup procedure form my tests:
[SetUp]
public void SetUp()
{
controllerBuilder = new TestControllerBuilder();
repository = MockRepository.GenerateStub<ISomeRepository>();
someController = new SomeController
(repository);
controllerBuilder.InitializeController(someController);
}
Found an answer... really stupid problem, like most problems in programming. As I always say, if you can't solve it the first couple of hours, then you know its something really really stupid.
Here is where I found the answer, took me a while, but the name of the question didn't help things either:
Attempted to read or write protected memory
In short, I had to replace the MVCContrib Dlls.
Thanks to everyone for the help...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With