public static string CheckPartnerApplications(PartnerController partnerController, Partner partner, List <ACSApplicationModel> expectedACSApplicationModels) { // Get partners applications ViewResult viewResult = (ViewResult)partnerController.Details(partner.Id, false); if (viewResult.ViewData.Model.GetType() != typeof(PartnerModel)) { return("PartnerController returned wrong action result. Expected: " + typeof(PartnerModel).ToString() + " Got: " + viewResult.ViewData.Model.GetType().ToString()); } // Did the controller return any errors? if (partnerController.ViewData.ModelState.Count != 0) { return("PartnerController returned " + partnerController.ViewData.ModelState.Count.ToString()); // + " model errors: " + storeController.ViewData.ModelState[0].Errors[0]); } PartnerModel actualPartnerModel = (PartnerModel)viewResult.ViewData.Model; // Check that the partner has the correct applications foreach (ACSApplicationModel expectedACSApplicationModel in expectedACSApplicationModels) { ACSApplication foundACSApplication = null; foreach (ACSApplication actualACSApplication in actualPartnerModel.ACSApplications) { if (expectedACSApplicationModel.ACSApplication.Id == actualACSApplication.Id) { foundACSApplication = actualACSApplication; break; } } if (foundACSApplication == null) { return("PartnerController didn't return partner application " + expectedACSApplicationModel.ACSApplication.Id.ToString()); } if (foundACSApplication.ExternalApplicationId != expectedACSApplicationModel.ACSApplication.ExternalApplicationId) { return("ExternalApplicationId mismatch. Expected: " + expectedACSApplicationModel.ACSApplication.ExternalApplicationId + " Got: " + foundACSApplication.ExternalApplicationId); } if (foundACSApplication.Name != expectedACSApplicationModel.ACSApplication.Name) { return("Name mismatch. Expected: " + expectedACSApplicationModel.ACSApplication.Name + " Got: " + foundACSApplication.Name); } if (foundACSApplication.PartnerId != expectedACSApplicationModel.ACSApplication.PartnerId) { return("PartnerId mismatch. Expected: " + expectedACSApplicationModel.ACSApplication.PartnerId + " Got: " + foundACSApplication.PartnerId); } } // All good return(""); }