Пример #1
0
        public void InsertCoin_Fail()
        {
            var mockHttpContext = new Mock <HttpContextBase>();
            var response        = new Mock <HttpResponseBase>();

            mockHttpContext.SetupGet(x => x.Response).Returns(response.Object);

            controller = new JarController(_mockCoinJar.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockHttpContext.Object
                }
            };


            _mockCoinJar.Setup(s => s.AddCoin(It.IsAny <ICoin>()));
            _mockCoinJar.Setup(s => s.OuncesLeft()).Returns(42);
            controller.HttpContext.Response.StatusCode = 400;

            var result = controller.InsertCoin(null);

            Assert.IsNotNull(result);

            JsonResult jsonResult = result as JsonResult;

            Assert.IsTrue(jsonResult.Data.ToString().Contains("Error"));
            Assert.IsTrue(jsonResult.Data.ToString().Contains("Invalid coinValue"));
        }
Пример #2
0
        public void InsertCoin_Success()
        {
            controller = new JarController(_mockCoinJar.Object);

            _mockCoinJar.Setup(s => s.AddCoin(It.IsAny <ICoin>()));
            _mockCoinJar.Setup(s => s.OuncesLeft()).Returns(42);

            var result = controller.InsertCoin("1c");

            Assert.IsNotNull(result);

            JsonResult jsonResult = result as JsonResult;

            Assert.IsTrue(jsonResult.Data.ToString().Contains("Success"));
        }