Open GoogleCodeExporter opened 9 years ago
[deleted comment]
[deleted comment]
[deleted comment]
I don't understand the error report.
mock.SetupSet(x=>x[It.IsAny<Key>() = It.IsAny<Value>())
doesn't even compile. I'm not sure what you mean by "generic It.IsAny<Type>"
either.
Original comment by dan...@cazzulino.com
on 1 Aug 2011 at 7:04
[deleted comment]
The problem is that in C# you cannot use open generics anywhere :P.
Can't fix the compiler in Moq ;)
Original comment by dan...@cazzulino.com
on 1 Aug 2011 at 7:13
[deleted comment]
If you don't provide code that compiles at least, I can hardly repro or see
what the problem is. It must NOT be your production code, by definition. Just a
clean, self-contained, failing repro.
Proper bug reporting is a pre-requisite for getting a fix for it, in almost any
project I used or worked with.
Original comment by dan...@cazzulino.com
on 1 Aug 2011 at 7:28
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var mockMyClass = new Mock<MyClass>();
Key retKey = default(Key);
Value retVal = default(Value);
mockMyClass.SetupSet(x => x[It.IsAny<Key>()] = It.IsAny<Value>()).Callback<Key, Value>(
(k, v) =>
{
retKey = k;
retVal = v;
});
var testKey = new Key();
var testVal = new Value();
mockMyClass.Object[testKey] = testVal;
Assert.AreEqual(testVal, retVal);
}
}
public class MyClass
{
private Dictionary<Key, Value> _dict = new Dictionary<Key, Value>();
public virtual Value this[Key k]
{
get { return _dict[k]; }
set { _dict[k] = value; }
}
}
public class Key
{
}
public class Value
{
}
}
Original comment by Greg.Ne...@gmail.com
on 1 Aug 2011 at 7:40
Got it.
The following works:
[TestMethod]
public void TestMethod1()
{
var mockMyClass = new Mock<MyClass>(MockBehavior.Strict);
Key retKey = default(Key);
Value retVal = default(Value);
var testKey = new Key();
var testVal = new Value();
mockMyClass.SetupSet(x => x[testKey] = testVal).Callback<Key, Value>(
(k, v) =>
{
retKey = k;
retVal = v;
});
mockMyClass.Object[testKey] = testVal;
Assert.AreEqual(testVal, retVal);
}
Original comment by dan...@cazzulino.com
on 1 Aug 2011 at 8:32
Original issue reported on code.google.com by
Greg.Ne...@gmail.com
on 1 Aug 2011 at 4:41