Beispiel #1
0
        public void Test_Delete_Found()
        {
            var    mockCache = new Mock <IMemoryCache>();
            Har    toReturn  = GenerateSimpleHarObject();
            object h         = (object)toReturn;

            mockCache.Setup(repo => repo.TryGetValue(1, out h)).Returns(true);

            HarController controller = new HarController(mockCache.Object);
            IActionResult result     = controller.Delete(1);

            Assert.NotNull(result);
            ObjectResult objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(200, objectResult.StatusCode);

            Object val = objectResult.Value;

            bool success = GetProperty <bool>(val, "Success");

            Assert.Equal(true, success);


            int status = GetProperty <int>(val, "Status");

            Assert.Equal(200, status);

            Har model = GetProperty <Har>(val, "Model");

            Assert.Equal(toReturn, model);
        }
Beispiel #2
0
        public void Test_Delete_NotFound()
        {
            var    mockCache = new Mock <IMemoryCache>();
            object h         = null;

            mockCache.Setup(repo => repo.TryGetValue(It.IsAny <object>(), out h)).Returns(false);

            HarController controller = new HarController(mockCache.Object);
            IActionResult result     = controller.Delete(1);

            Assert.NotNull(result);
            ObjectResult objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(404, objectResult.StatusCode);
        }