Hi
I am trying to fake a method that as an argument receives a ref parameter that is a struct:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock.ArrangeActAssert;
namespace TestProject1
{
public struct Result
{
public int Value;
}
[TestClass]
public class ProgramTest
{
public static void Method(ref Result r)
{
r.Value = 1;
}
[TestMethod]
[Isolated]
public void MethodTest()
{
// Arrange
var r = new Result {Value = 123};
Isolate.WhenCalled(() => Method(ref r)).
DoInstead(context =>
{
var r2 = (Result) context.Parameters[0];
r2.Value = 321;
});
// Act
Method(ref r);
// Assert
Assert.AreEqual(321, r.Value);
}
}
}
My DoInstead block is called, by the Value isn't changed on r - hence the Assert fails unexpectedly. If I change Result to a class it is working perfectly - but fails if its a struct.
Is this a bug? and are there any workarrounds?