-2

This is the constructor of my test class

public IngestServiceTest()
{
    IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
    _logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<object>();
    
    var fileProcessLogDbSetMock = new Mock<DbSet<FileProcessLog>>();
    mockDowJonesContext.Setup(s => s.FileProcessLogs).Returns(fileProcessLogDbSetMock.Object);
    ingestService = new IngestService(mockDowJonesContext.Object, configuration, _logger);
}

But it hits System.NullReferenceException: 'Object reference not set to an instance of an object.' at mockDowJonesContext.Setup(s => s.FileProcessLogs).Returns(fileProcessLogDbSetMock.Object);

I see many tutorial but it is with Repository but mine is without Repository.

Steve
  • 2,963
  • 15
  • 61
  • 133
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Progman May 30 '21 at 10:56

1 Answers1

1

mockDowJonesContext needs to be initialized

Kazys
  • 377
  • 2
  • 12