Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Object reference not set to an instance of an object when addjsonfile in unit test

$
0
0

I do have appsettings.json file in the unit test project. However I get the error "Object reference not set to an instance of an object".

 [Fact]
        public void Given_AppSettings_Should_Return_Positive_Integer()
        {
            var logger = new Mock<ILogger>().Object;
            var deviceInformationGetter = new DeviceInformationGetter(logger);
            var builderMock = new Mock<ConfigurationBuilder>();
            var builder = builderMock.Object;
            builder.AddJsonFile("appsettings.json"); // here error 
            var configuration = builder.Build();
            var result = deviceInformationGetter.GetMaxRetryTimesFromAppSettings(configuration);

            Assert.True(result > 0);

        }

In  my project.json file I do have

"Microsoft.Framework.Configuration": "1.0.0-beta8"

Thanks.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>