Function app unit testing with GetInput and data repository return not working

When running a unit test, it does not seem to continue through the repo/data return to continue processing and just fast forwards to the return. The gist of the code is:

namespace program
{
    [FunctionName("Processor")]
    public static async Task<Boolean> Processor([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
    {
        var eventDetails =  context.GetInput<entitydataobject>();
        IRepoData repo = null;
        List<Guid> list;
        try
        {
            repo = Repository();
            list = repo.GetEntityList(Guid.Parse(entitydataobject.Guid), entitydataobject.Name);
        }
        catch(Exception ex)
        {
            log.LogError("Processor Error: " + ex.Message);
        }
    }
    
    public static IRepoData Repository() 
    {
        try
        {
            return new RepoData("Data Source=instance.local;Initial Catalog=database;integrated security=True;MultipleActiveResultSets=True;");
        }
        catch (Exception ex)
        {
            throw new Exception("Repository Error: " + ex.Message);
        }
    }
}

The gist of the Unit Test:

namespace Test 
{ 
    [TestClass] 
    [ExcludeFromCodeCoverage] 
    public class ProcessorTests 
    {
        var mockContext = new Mock<IDurableOrchestrationContest>();      
        var inputData = JsonConvert.DeserializeObject<entitydataobject>(File.ReadAllText("file.json"));      
        var list = new List<Guid>();      
        var repository = new Mock<IRepository>();      
        var log = new Mock<ILogger>();       
        list.Add(new Guid());      
        list.Add(new Guid());       
        repository.Setup(repo => repo.GetEntityIdList(Guid.Parse("4D47AF6C-0000-0000-0000-000000000000", "string").Returns(list);      
        mockContext.Setup(x => x.GetInput<entitydataobject>()).Returns(entitydataobject); 
        var result = program.Processor(context.Object, log.Object);
        Assert.IsTrue(result.Result);                
    }
}

My guess is that the repository setup is not passing through.

I tried to execute in VS 2022, and it progresses up to the point of repository/GetEntityList, but just skips over it/does not populate the list.

1

I tried your code and got the same error , the issues with the GetEntityList method inside your unit test.

Update the Processor Method:
Processor to await asynchronous methods .Use async repository method to avoid blocking threads

  public static async Task<Boolean> ProcessEntity([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
        {
            var eventDetails = context.GetInput<entitydataobject>();
            IRepoData repo = null;
            List<Guid> list;

            try
            {
                repo = Repository();

                list = await Task.Run(() => repo.GetEntityList(Guid.Parse(eventDetails.Guid), eventDetails.Name));
                if (list != null && list.Count > 0)
                {
                    return true;
                }

                return false;
            }
            catch (Exception ex)
            {
                log.LogError("Processor Error: " + ex.Message);
                return false;
            }
        }

        public static IRepoData Repository()
        {
            try
            {
                return new RepoData("Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=True;");
            }
            catch (Exception ex)
            {
                throw new Exception("Repository Error: " + ex.Message);
            }
        }
    }

Update the Unit test :
The IRepoData interface and its implementation (RepoData) have been refactored to be asynchronous, using Task<List<Guid>>.The unit test uses await to handle the asynchronous nature of Processor. The repository mock now returns a Task using .ReturnsAsync(list).

public class ProcessorTests
        {
            private readonly IDurableOrchestrationContext _context;
            private readonly ILogger _logger;
            private readonly IRepoData _repo;

            private readonly entitydataobject _validEntityDataObject;
            private readonly List<Guid> _entityList;

            public ProcessorTests()
            {
                _context = Substitute.For<IDurableOrchestrationContext>();
                _logger = Substitute.For<ILogger>();
                _repo = Substitute.For<IRepoData>();
                _validEntityDataObject = new entitydataobject
                {
                    Guid = Guid.NewGuid().ToString(),
                    Name = "SampleName"
                };

                _entityList = new List<Guid> { Guid.NewGuid(), Guid.NewGuid() };

                _context.GetInput<entitydataobject>().Returns(_validEntityDataObject);
            }

            [Fact]
            public async Task ProcessEntity_ShouldReturnTrue_WhenDataIsProcessedSuccessfully()
            {
                _repo.GetEntityList(Arg.Any<Guid>(), Arg.Any<string>()).Returns(_entityList);

                var result = await Processor.ProcessEntity(_context, _logger);


Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật