I've got a bunch of tests that need to mock SPAttachmentCollection. In Isolator, I did it like this:
In JustMock, I've done it like this:
Is there a better way? I would like to use ReturnsCollection() on properties.ListItem.Attachments, but it's unavailable for some reason.
-Andy
public
void
CreateAttachmentFromAfterUrl_AttachmentNameNotInAfterUrl_ReturnsNull()
{
var properties = Isolate.Fake.Instance<SPItemEventProperties>();
Isolate.WhenCalled(() => properties.ListItem.Attachments)
.WillReturnCollectionValuesOf(
new
[] {
"A"
,
"B"
});
Isolate.WhenCalled(() => properties.AfterUrl)
.WillReturn(
"C"
);
var attachment = AttachmentFactory.CreateAttachmentFromAfterUrl(properties);
attachment.ShouldBeNull();
}
In JustMock, I've done it like this:
public
void
CreateAttachmentFromAfterUrl_AttachmentNameNotInAfterUrl_ReturnsNull()
{
var properties = Mock.Create<SPItemEventProperties>();
var collection = Mock.Create<SPAttachmentCollection>();
var list =
new
List<
string
> {
"A"
,
"B"
};
Mock.Arrange(() => collection.GetEnumerator()).Returns(list.GetEnumerator());
Mock.Arrange(() => properties.ListItem.Attachments).Returns(collection);
Mock.Arrange(() => properties.AfterUrl).Returns(
"C"
);
var attachment = AttachmentFactory.CreateAttachmentFromAfterUrl(properties);
attachment.ShouldBeNull();
}
Is there a better way? I would like to use ReturnsCollection() on properties.ListItem.Attachments, but it's unavailable for some reason.
-Andy