public void Model_TrySubmitForm_RaisesValidating_Saving_Saved()
        {
            var validatingRisen = false;
            var fieldValidatingRisen = false;
            var savingRisen = false;
            var savedRisen = false;

            SitefinityEventHandler<IFormValidatingEvent> validatingHandler = (IFormValidatingEvent @event) =>
            {
                validatingRisen = true;
            };

            SitefinityEventHandler<IFormFieldValidatingEvent> fieldValidatingHandler = (IFormFieldValidatingEvent @event) =>
            {
                fieldValidatingRisen = true;
            };

            SitefinityEventHandler<FormSavingEvent> savingHandler = (FormSavingEvent @event) =>
            {
                savingRisen = true;
            };

            SitefinityEventHandler<FormSavedEvent> savedHandler = (FormSavedEvent @event) =>
            {
                savedRisen = true;
            };

            EventHub.Subscribe<IFormValidatingEvent>(validatingHandler);
            EventHub.Subscribe<IFormFieldValidatingEvent>(fieldValidatingHandler);
            EventHub.Subscribe<FormSavingEvent>(savingHandler);
            EventHub.Subscribe<FormSavedEvent>(savedHandler);

            try
            {
                var model = new FormModel();
                model.FormId = FormEventsTests.formId;

                var values = new NameValueCollection();
                values.Add(FormEventsTests.FieldName, "text");

                model.TrySubmitForm(new System.Web.Mvc.FormCollection(values), null, string.Empty);

                Assert.IsTrue(validatingRisen, "Form Validating event was not risen.");
                Assert.IsTrue(fieldValidatingRisen, "Form Field validating event was not risen.");
                Assert.IsTrue(savingRisen, "Form saving event was not risen.");
                Assert.IsTrue(savedRisen, "Form saved event was not risen.");
            }
            finally
            {
                EventHub.Unsubscribe<IFormValidatingEvent>(validatingHandler);
                EventHub.Unsubscribe<IFormFieldValidatingEvent>(fieldValidatingHandler);
                EventHub.Unsubscribe<FormSavingEvent>(savingHandler);
                EventHub.Unsubscribe<FormSavedEvent>(savedHandler);
            }
        }
        public void Model_TrySubmitForm_ValidatingEventHandlerFails_InvalidResult()
        {
            var validatingRisen = false;

            SitefinityEventHandler<IFormValidatingEvent> validatingHandler = (IFormValidatingEvent @event) =>
            {
                validatingRisen = true;
                throw new ValidationException("Not valid");
            };

            EventHub.Subscribe<IFormValidatingEvent>(validatingHandler);

            try
            {
                var model = new FormModel();
                model.FormId = FormEventsTests.formId;

                var values = new NameValueCollection();
                values.Add(FormEventsTests.FieldName, "text");

                var result = model.TrySubmitForm(new System.Web.Mvc.FormCollection(values), null, string.Empty);

                Assert.IsTrue(validatingRisen, "Form Validating event was not risen.");
                Assert.AreEqual(SubmitStatus.InvalidEntry, result, "Form was not invalidated via the validating event handler.");
            }
            finally
            {
                EventHub.Unsubscribe<IFormValidatingEvent>(validatingHandler);
            }
        }