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)); }
public async Task Test_IP_Is_Not_Unique_Exception_UpdateIP() { 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_obj = await ip_controller_service.UpdateIPAsync("ca3d03674e2045ef85b824a14a386698", "12.12.12.12/32"); var expected_obj = new { error = true, message = "This IP address already exists." }; Assert.True(CompareObjects(returned_obj, expected_obj)); }
public async Task <JsonResult> UpdateIP(string id, string subnet) { return(Json(await _ipService.UpdateIPAsync(id, subnet))); }