Beispiel #1
0
        public static string CheckPartners(PartnerController partnerController, List <Partner> expectedPartners)
        {
            // Get partners
            ViewResult viewResult = (ViewResult)partnerController.Index();

            if (viewResult.ViewData.Model.GetType() != typeof(List <Partner>))
            {
                return("PartnerController returned wrong action result. Expected: " + typeof(List <Partner>).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]);
            }

            IList <Partner> actualPartners = (List <Partner>)viewResult.ViewData.Model;

            if (actualPartners.Count != expectedPartners.Count)
            {
                return("PartnerController returned the wrong number of stores.  Expected: " + expectedPartners.Count + " Got: " + actualPartners.Count.ToString());
            }

            // Check that each partner was found
            foreach (Partner expectedPartner in expectedPartners)
            {
                Partner foundPartner = null;
                foreach (Partner actualPartner in actualPartners)
                {
                    if (expectedPartner.Id == actualPartner.Id)
                    {
                        foundPartner = actualPartner;
                        break;
                    }
                }

                if (foundPartner == null)
                {
                    return("PartnerController didn't return partner " + expectedPartner.Id.ToString());
                }

                if (foundPartner.ExternalId != expectedPartner.ExternalId)
                {
                    return("ExternalId mismatch. Expected: " + expectedPartner.ExternalId + " Got: " + foundPartner.ExternalId);
                }
                if (foundPartner.Name != expectedPartner.Name)
                {
                    return("Name mismatch. Expected: " + expectedPartner.Name + " Got: " + foundPartner.Name);
                }
            }

            // All good
            return("");
        }