1

有人可以帮我吗?

我需要为这种方法使用摩尔创建一个单元测试:

   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项目

对不起,我的英语不好。

非常感谢。

4

0 回答 0