public
interface
ISamplePoco
{
string
Name {
get
;
set
; }
}
[TestMethod]
public
void
GenerateMockWithPocoPropertyBehaviour()
{
// arrange
var target = Mock.Create<ISamplePoco>(Behavior.CallOriginal);
// act
target.Name =
"Dude"
;
target.Name +=
"s"
;
// assert
Assert.AreEqual(
"Dudes"
, target.Name);
}
string
name =
string
.Empty;
Mock.Arrange(() => target.Name).Returns(name);
Mock.ArrangeSet((
string
val) => { name = val; }).IgnoreArguments();
var monkey = new Mock<IMonkey>();
monkey.SetupAllProperties();
monkey.Object.Name = "Spike";
Assert.AreEqual("Spike", monkey.Object.Name);
var monkey = Isolate.Fake.Instance<IMonkey>();
monkey.Name = "Spike";
Assert.AreEqual("Spike", monkey.Name);
var monkey = Mock.Create<IMonkey>();
Mock.ArrangeSet(() => { monkey.Name = "Spike"; });
monkey.Name = "Spike"; Assert.AreEqual("Spike", monkey.Name); // FAILS!
private HttpWebRequest _webRequestMock;
private void SetupMocks() {_webRequestMock = Mock.Create<HttpWebRequest>();_webResponseMock = Mock.Create<WebResponse>(); Mock.SetupStatic<HttpUtils>(Behavior.Strict); Mock.Arrange(() => HttpUtils.CreateWebRequest(Arg.IsAny<string>())).Returns(_webRequestMock); Mock.Arrange(() => _webRequestMock.GetResponse()).Returns(_webResponseMock); }
Mock.NonPublic.Arrange<bool>(
target,
"IsUSPriceChangeOnCanadianAdoptedRSTitle",
mockedDBTrans,
Arg.IsAny<TitleRequestDataset.TitleRequestRow>())
.DoInstead( () => {calledIsUSPriceChangeOnCanadianAdoptedRSTitle = true;} )
.Returns(true);
I get an ArgumentException at run time with the following message:
Direct null valued argument for non-public member is not supported. Use ArgExpr.IsNull<T>() or other members from ArgExpr wrapper class to provide your specification.
Please advise on how to get around this.
Thanks,
Asim
var uut = Mock.Create<
SPRoleDefinitionBindingCollection
>();
var role = Mock.Create<
SPRoleDefinition
>();
Mock.Arrange(() => role.BasePermissions)
.Returns(SPBasePermissions.ViewUsageData | SPBasePermissions.EditListItems | SPBasePermissions.DeleteListItems);
uut.Add(role);
var result = uut.ContainsPermission(SPBasePermissions.DeleteListItems);
Assert.IsTrue(result);
Mock.Arrange(() => helper.LoadFromDB(out test1DS, out test2DS))
.DoInstead(someDelegate)
.Returns(true);
The problem is that the data sets the mock implementation populates are the ones declared within the unit test, not the ones declared in the method-under-test. So the process flag in the code snippet above still returns false (due to d1 being null), and the business logic I wanted to test (within the "if (process)" block above) never gets run.
Is there a way to map (for lack of a better word) the test1DS and test2DS (that I declared in the unit test code and populated in my DoInstead delegate) to the data sets d1 and d2 declared within the method-under-test, so as to allow the process flag to evaluate to true once the mocked implementation has run?
Thanks,
Asim