예제 #1
0
        public void CheckServers()
        {
            // Arrange
            IMemoryCache        memoryCache = new MemoryCache(new MemoryCacheOptions());
            Mock <IMemoryCache> cache       = new Mock <IMemoryCache>();

            var myContext = new Mock <HttpContext>();

            DateTime now    = DateTime.Now;
            Servers  server = new Servers();

            server.ServerId  = "das423";
            server.ServerURL = "/http/8080";

            var          json      = JsonConvert.SerializeObject(server);
            var          byteArray = Encoding.ASCII.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            stream.Flush();
            stream.Position = 0;

            myContext.SetupGet(x => x.Request.Body).Returns(stream);
            var controllerContext = new ControllerContext()
            {
                HttpContext = myContext.Object,
            };
            ServersController controller = new ServersController(memoryCache)
            {
                ControllerContext = controllerContext,
            };

            // Act
            var answer = controller.AddServer(server);

            // Assert
            Assert.AreEqual(answer.Value, server);

            // Arrange
            controller = new ServersController(memoryCache);

            // Act
            ActionResult <List <Servers> > list = controller.GetServers();

            // Assert
            Assert.IsTrue(list.Value.Count == 1);

            // Act
            answer = controller.DeleteServerById(server.ServerId);

            // Assert
            Assert.AreEqual(answer.Value, server);
        }