Пример #1
0
        public void Test_False_GetIPList()
        {
            var ip_list = SetDefaultIPList();

            var mock = new Mock <IIPsRepository>();

            mock.Setup(p => p.GetIPList()).Returns(ip_list);

            var ip_controller_service = new IPService(mock.Object);

            var returned_ip_list_object = ip_controller_service.GetIPList();

            var expected_ip_list_data = new List <IP>
            {
                new IP("1", "13.13.13.13/32"),
                new IP("2", "12.12.12.12/30")
            };

            var expected_ip_list_object = new {
                error = false,
                data  = expected_ip_list_data
            };

            Assert.False(CompareObjects(returned_ip_list_object, expected_ip_list_object));
        }
Пример #2
0
        public async Task Test_False_UpdateIP()
        {
            var ip_list = SetDefaultIPList();

            var mock = new Mock <IIPsRepository>();

            mock.Setup(p => p.GetIPList()).Returns(ip_list);
            mock.Setup(p => p.UpdateIPAsync(It.IsAny <IP>())).Callback((IP ip_arg) => {
                int index           = ip_list.Data.FindIndex(ip => ip.Id == ip_arg.Id);
                ip_list.Data[index] = ip_arg;
            });

            var ip_controller_service = new IPService(mock.Object);

            await ip_controller_service.UpdateIPAsync("ca3d03674e2045ef85b824a14a386698", "14.14.14.14/28");

            var returned_obj = ip_controller_service.GetIPList();

            var expected_ip_list_data = new List <IP>
            {
                new IP("ca3d03674e2045ef85b824a14a386698", "12.12.12.12/32"),
                new IP("38a8e64feb7244da816063d63868f38e", "12.12.12.12/30")
            };

            var expected_obj = new {
                error = false,
                data  = expected_ip_list_data
            };

            Assert.False(CompareObjects(returned_obj, expected_obj));
        }
Пример #3
0
        public void Test_True_GetIPList()
        {
            var ip_list = SetDefaultIPList();

            var mock = new Mock <IIPsRepository>();

            mock.Setup(p => p.GetIPList()).Returns(ip_list);

            var ip_controller_service = new IPService(mock.Object);

            var returned_ip_list_object = ip_controller_service.GetIPList();

            var expected_ip_list_data = new List <IP>
            {
                new IP("ca3d03674e2045ef85b824a14a386698", "12.12.12.12/32"),
                new IP("38a8e64feb7244da816063d63868f38e", "12.12.12.12/30")
            };

            var expected_ip_list_object = new {
                error = false,
                data  = expected_ip_list_data
            };

            Assert.True(CompareObjects(returned_ip_list_object, expected_ip_list_object));
        }
Пример #4
0
 public JsonResult GetIPList()
 {
     return(Json(_ipService.GetIPList()));
 }