简体   繁体   中英

How do I use C# Unit test FakeHttpContext correctly?

I have the following code with gives the correct assert result but the test case errors with the message "Object synchronization method was called from an unsynchronized block of code." What can I do to correct the issue?

        public async Task Test()
    {
        using (new FakeHttpContext.FakeHttpContext())
        {
            BasketController _controller = new BasketController();
            List<StockMovementModel> model = new List<StockMovementModel>
        {
            StockMovementFixtures.TestFixture()
        };
            var result = await _controller.CreateTransfer(model, new Kendo.Mvc.UI.DataSourceRequest()).ConfigureAwait(false);
            Assert.IsNotNull(result);
        }

    }

Workarround that seems to be working:

using (var ctx = new FakeHttpContext()) { lock (ctx) { ...... } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM