ExtractVariables() public method

public ExtractVariables ( ) : void
return void
        public void EmailContainsUnevenNumberOfCurlyBracketsRaisesException()
        {
            var communicationTemplate = new CommunicationTemplate();
            communicationTemplate.EmailContent = "<stuff>{var1}}</stuff><p>{var2}</p>";

            Assert.That(() => communicationTemplate.ExtractVariables(),
                Throws.Exception.With.Message.EqualTo("Odd number of opening and closing brackets in template"));
        }
        public void EmailContainsOverlappingOpeningAndClosingBrackets_RaisesException()
        {
            var communicationTemplate = new CommunicationTemplate();
            communicationTemplate.EmailContent = "<stuff>{var1</stuff><p>{var2}}</p>";

            Assert.That(() => communicationTemplate.ExtractVariables(),
                Throws.Exception.With.Message.EqualTo("Brackets must be open and closed before creating new ones"));
        }
        public void SmsContainsCurlyBracketUsesVariableName()
        {
            var communicationTemplate = new CommunicationTemplate();
            communicationTemplate.SmsContent = "stuff{var1}stuff{var2}";

            communicationTemplate.ExtractVariables();

            Assert.That(communicationTemplate.TemplateVariables[0].VariableName, Is.EqualTo("var1"));
            Assert.That(communicationTemplate.TemplateVariables[1].VariableName, Is.EqualTo("var2"));
            Assert.That(communicationTemplate.TemplateVariables.Count, Is.EqualTo(2));
        }
        public void EmailContainsCurlyBracketUsesVariableName()
        {
            var communicationTemplate = new CommunicationTemplate();
            communicationTemplate.EmailContent = "<stuff>{var1}</stuff><p>{var2}</p>";

            communicationTemplate.ExtractVariables();

            Assert.That(communicationTemplate.TemplateVariables[0].VariableName, Is.EqualTo("var1"));
            Assert.That(communicationTemplate.TemplateVariables[1].VariableName, Is.EqualTo("var2"));
            Assert.That(communicationTemplate.TemplateVariables.Count, Is.EqualTo(2));
        }
        public ActionResult Create(TemplateModel model)
        {
            try {
                using(var session = Raven.GetStore().OpenSession("Configuration")){
                    var existingTemplate = session.Load<CommunicationTemplate>(model.TemplateName);
                    if (existingTemplate != null){
                        throw new Exception("shouldn't exist");
                    }

                    var communicationTemplate = new CommunicationTemplate
                    {
                        EmailContent = model.EmailContent,
                        SmsContent = model.SmsContent,
                        TemplateName = model.TemplateName
                    };
                    communicationTemplate.ExtractVariables();
                    session.Store(communicationTemplate, communicationTemplate.TemplateName);
                    session.SaveChanges();
                }
                return RedirectToAction ("Index");
            } catch {
                return View ();
            }
        }
 public ActionResult Edit(string templateName, CommunicationTemplate model)
 {
     try {
         using(var session = Raven.GetStore().OpenSession("Configuration"))
         {
             var existingTemplate = session.Load<CommunicationTemplate>(templateName);
             if (existingTemplate == null)
             {
                 throw new Exception("should have a document here...");
             }
             existingTemplate = model;
             existingTemplate.ExtractVariables();
             session.SaveChanges();
         }
         return RedirectToAction ("Index");
     } catch {
         return View ();
     }
 }