public void AuditController_AuditList_JsonDataString_Valid_Json_ShouldReturn_EmptyModel() { //----------------------------Arrange----------------------------- using (var controller = new AuditController()) { //-------------------Arrange----------------------------- var validJosonA = @"{ 'AuditType': 'testTypeA','AuditDate':'2019/10/03'}"; var validJosonB = @"{ 'AuditType': 'testTypeB','AuditDate':'2019/10/03'}"; var AuditA = JsonConvert.DeserializeObject <Audit>(validJosonA); var AuditB = JsonConvert.DeserializeObject <Audit>(validJosonB); var audits = new List <Audit> { AuditA, AuditB }; //-------------------Act--------------------------------- var expectedAudits = JsonConvert.SerializeObject(audits); var result = controller.AuditList(expectedAudits); //-------------------Assert----------------------------------- Assert.IsInstanceOfType(result, typeof(ActionResult)); Assert.IsInstanceOfType(result, typeof(PartialViewResult)); var partialViewResult = (PartialViewResult)result; Assert.AreEqual("AuditList", partialViewResult.ViewName); Assert.AreEqual(expectedAudits, JsonConvert.SerializeObject(partialViewResult.ViewData.Model)); }; }
public void AuditController_AuditList_JsonDataString_Invalid_Json_ShouldReturn_EmptyModel() { //----------------------------Arrange----------------------------- using (var controller = new AuditController()) { //-------------------Act--------------------------------- var result = controller.AuditList("invalidJson"); //-------------------Assert----------------------------------- Assert.IsInstanceOfType(result, typeof(ActionResult)); Assert.IsInstanceOfType(result, typeof(PartialViewResult)); var partialViewResult = (PartialViewResult)result; Assert.AreEqual("AuditList", partialViewResult.ViewName); }; }