1

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);
        }

    }
AdamG31
  • 23
  • 4
  • You want to "mock", not "fake". See here https://stackoverflow.com/questions/4379450/mock-httpcontext-current-in-test-init-method or https://docs.microsoft.com/en-us/archive/msdn-magazine/2014/november/async-programming-unit-testing-asynchronous-code for how to unit test `async` code – eglease Sep 16 '21 at 14:28
  • @eglease if I take out the faking I have errors with the code to locate the directory ( string workingDirectory = HostingEnvironment.MapPath) – AdamG31 Sep 16 '21 at 14:31
  • I just meant that the correct term for fake classes used for testing is "mocking". You can still call the actual object "fake" but what you are trying to do is "mock" `HttpContext`. – eglease Sep 16 '21 at 14:41

0 Answers0