1

我正在尝试测试QueryAllScheduledJob方法。它包含对返回 IAsyncEnumerable 集合的 GetScheduledJobs 的调用。我已经为 GetScheduledJobs 创建了一个设置。我收到GetScheduledJobs类型为“空实例”的异常。在我的设置中,我尝试使用 Task.Result 进行返回,它给出了编译时错误。

实现类

public async IAsyncEnumerable<ScheduledJobModel> QueryAllScheduledJob()
    {
        var enumerator = ScheduledJobRepository.GetScheduledJobs().GetAsyncEnumerator();
        while (await enumerator.MoveNextAsync())
            yield return ConvertTypeToModel<ScheduledJobModel, ScheduledJobs>(enumerator.Current);
    }

测试班

 [Theory]
        [InlineData(5)]
        public async void ShouldHaveScheduledJobRecords(int numberOfScheduledJobs)
        {
            //Arrange 
            var data = ScheduleJobFixtureHelper.GetXNumberofScheduledJobs(numberOfScheduledJobs);
            ScheduledJobRepository.Setup(a => a.GetScheduledJobs()).Returns(data);
            ////Act
            var results = QueueManager.QueryAllScheduledJob();
            //Assert
            Assert.Equal(numberOfScheduledJobs, await results.CountAsync());
        }



  public async IAsyncEnumerable<ScheduledJobs> GetXNumberofScheduledJobs(int totalNumberofScheduledJob)
        {
           IEnumerator<ScheduledJobs> enumerator =  AutoFixture.CreateMany<ScheduledJobs>(totalNumberofScheduledJob).GetEnumerator();
            while (enumerator.MoveNext())
            {
                yield return enumerator.Current;
            }
        }
4

0 回答 0