public string BuildHtml()
        {
            if (checker.IsCurrentUserAdministrator())
            {
                IList <ApplicationInstance> applications =
                    new List <ApplicationInstance>(applicationInstanceRepository.GetAll());

                string bodyTemplate =
                    fileLocator.ReadTextFile("Tarantino.Core", ApplicationListingBodyView.BodyTemplate);

                replacer.Text = bodyTemplate;

                ApplicationInstance lastInstance = new ApplicationInstance();
                string rowHTMl = "";
                foreach (ApplicationInstance instance in applications)
                {
                    if (instance.MaintenanceHostHeader != lastInstance.MaintenanceHostHeader)
                    {
                        int instanceCount = GetInstanceCount(applications, instance.MaintenanceHostHeader);
                        rowHTMl += applicationListingRowView.BuildFirstRowHtml(instance, instanceCount);
                    }
                    else
                    {
                        rowHTMl += applicationListingRowView.BuildMRowHtml(instance);
                    }
                    lastInstance = instance;
                }
                replacer.Replace("ROWS", rowHTMl);
            }
            else
            {
                replacer.Text = "Unauthorized request.";
            }
            return(replacer.Text);
        }
        public void Correctly_returns_html_for_page_for_an_administrator()
        {
            List <ApplicationInstance> applicationList = new List <ApplicationInstance>();

            //application group 1
            applicationList.Add(new ApplicationInstance());
            applicationList[0].MaintenanceHostHeader = "1";
            applicationList.Add(new ApplicationInstance());
            applicationList[1].MaintenanceHostHeader = "1";

            //application group 2
            applicationList.Add(new ApplicationInstance());
            applicationList[2].MaintenanceHostHeader = "2";
            applicationList.Add(new ApplicationInstance());
            applicationList[3].MaintenanceHostHeader = "2";

            MockRepository mocks = new MockRepository();
            IApplicationInstanceRepository repository  = mocks.CreateMock <IApplicationInstanceRepository>();
            IResourceFileLocator           fileLocator = mocks.CreateMock <IResourceFileLocator>();
            ITokenReplacer replacer = mocks.CreateMock <ITokenReplacer>();
            IAdministratorSecurityChecker securityChecker           = mocks.CreateMock <IAdministratorSecurityChecker>();
            IApplicationListingRowView    applicationListingRowView = mocks.CreateMock <IApplicationListingRowView>();

            using (mocks.Record())
            {
                Expect.Call(securityChecker.IsCurrentUserAdministrator()).Return(true);

                Expect.Call(repository.GetAll()).Return(applicationList);
                Expect.Call(fileLocator.ReadTextFile("Tarantino.Core", ApplicationListingBodyView.BodyTemplate)).Return("body template");
                replacer.Text = "body template";
                Expect.Call(applicationListingRowView.BuildFirstRowHtml(applicationList[0], 2)).Return("1");
                Expect.Call(applicationListingRowView.BuildMRowHtml(applicationList[1])).Return("2");
                Expect.Call(applicationListingRowView.BuildFirstRowHtml(applicationList[2], 2)).Return("3");
                Expect.Call(applicationListingRowView.BuildMRowHtml(applicationList[3])).Return("4");
                replacer.Replace("ROWS", "1234");
                Expect.Call(replacer.Text).Return("formatted HTML");
            }

            using (mocks.Playback())
            {
                IApplicationListingBodyView view = new ApplicationListingBodyView(securityChecker, repository, fileLocator, replacer, applicationListingRowView);
                string html = view.BuildHtml();
                Assert.That(html, Is.EqualTo("formatted HTML"));
            }

            mocks.VerifyAll();
        }