如何为SPJobDefinitionCollection创建GetEnumerator方法

时间:2012-05-29 17:26:18

标签: c# unit-testing sharepoint moles pex

有人可以帮帮我吗?

我需要使用摩尔为此方法创建单元测试:

   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();
    }

但是,当我执行测试时,会出现以下错误消息:

failing test: MoleNotImplementedException, SPPersistedObjectCollection`1.GetEnumerator() was not moled.

此行中出现此错误:

        foreach (SPJobDefinition job in webApp.JobDefinitions)

这是我的单元测试代码:

    [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);

    }

我已经在互联网上阅读了我需要使用Binding将GetEnumerator()实现到集合中。然后改变我的单元测试来实现这个,但错误是一样的。 AssistantJob类实现JobDefinition抽象类。

        webapp.JobDefinitionsGet = () => new MSPJobDefinitionCollection().Bind(new MApprovalAssistantJob[] {
            new MAssistantJob() {  },
            new MAssistantJob() {  }
        });

有人可以帮我在 MSPJobDefinitionCollection 中添加 MAssistantJob 项吗?

对不起,我的英语不好。

非常感谢。

0 个答案:

没有答案