Can somebody help me please?
I need create a unit test using moles for this method:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
foreach (SPJobDefinition job in webApp.JobDefinitions)
if (job.Name == "AAAA") job.Delete();
AssistantJob aJob = new AssistantJob(webApp);
SPDailySchedule schedule = new SPDailySchedule();
schedule.BeginHour = 2;
schedule.BeginMinute = 30;
schedule.BeginSecond = 0;
schedule.EndHour = 3;
schedule.EndMinute = 30;
schedule.EndSecond = 0;
aJob.Schedule = schedule;
aJob.Update();
}
But, when I execute the test the following error message appears:
failing test: MoleNotImplementedException, SPPersistedObjectCollection`1.GetEnumerator() was not moled.
This error occur in this line:
foreach (SPJobDefinition job in webApp.JobDefinitions)
This is my unit test code:
[PexMethod]
public void FeatureActivated(
[PexAssumeUnderTest]ApprovalAssistantCleanupEventReceiver target
)
{
MSPFarm.BehaveAsNotImplemented();
BSPFeatureReceiverProperties props = new BSPFeatureReceiverProperties();
BSPFeature feature = new BSPFeature();
MSPWebApplication webapp = new MSPWebApplication();
props.Feature = feature;
feature.Parent = webapp.Instance;
webapp.JobDefinitionsGet = () => new MSPJobDefinitionCollection();
target.FeatureActivated(props);
}
I've read on the internet I need use Binding to implement GetEnumerator() into a collection. Then changed my unit test to implement this, but the error is the same. The AssistantJob class implement the JobDefinition abstract class.
webapp.JobDefinitionsGet = () => new MSPJobDefinitionCollection().Bind(new MApprovalAssistantJob[] {
new MAssistantJob() { },
new MAssistantJob() { }
});
Can someone help me to add MAssistantJob items inside the MSPJobDefinitionCollection???
I'm sorry my English isn't good.
Thanks very much.