public void ReturnBadRequest_When_RequestBodyIsNotParsable() { //Arrange var badRequestJsonBodyStream = new MemoryStream(Encoding.UTF8.GetBytes("attribute :**? value")); var contextWithoutCacheControl = MakeFakeContext(false); contextWithoutCacheControl.Setup(x => x.Request.Body).Returns(badRequestJsonBodyStream); contextWithoutCacheControl.Setup(x => x.Request.ContentLength).Returns(badRequestJsonBodyStream.Length); _controller.ControllerContext.HttpContext = contextWithoutCacheControl.Object; //Act var result = _controller.UploadMobileLogs().Result; //Assert Assert.IsInstanceOf <BadRequestObjectResult>(result); contextWithoutCacheControl.Verify(c => c.Request.Body, Times.Once); Assert.That(((BadRequestObjectResult)result).Value.ToString(), Does.StartWith("No logs found in body or unable to parse logs data")); }