Example #1
0
		public void ShouldReturnAStringVariable()
		{
			const string input = "Hey, {{firstName}}! What's up?";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 0);
			Assert.IsTrue(result.StringVariables.Count == 1);
			Assert.IsTrue(result.StringVariables.Any(a => a.Name == "firstName"));
		}
Example #2
0
		public void ShouldReturnTwoVariables()
		{
			const string input = "So, get this, {{firstPerson}}. There was this guy named {{secondPerson}}, right?";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 0);
			Assert.IsTrue(result.StringVariables.Count == 2);
			Assert.IsTrue(result.StringVariables.Any(a => a.Name == "firstPerson"));
			Assert.IsTrue(result.StringVariables.Any(a => a.Name == "secondPerson"));
		}
Example #3
0
		public void BooleanVariablesShouldSupportDescriptions()
		{
			const string input = "I {{#have|Random Description}}was awesome{{/have}}!";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.StringVariables.Count == 0);
			Assert.IsTrue(result.BooleanLogics.Count == 1);
			Assert.IsTrue(result.BooleanLogics[0].Description == "Random Description");
			Assert.IsTrue(result.BooleanLogics[0].Name == "have");
		}
Example #4
0
		public void ShouldReturnASingleBooleanLogic()
		{
			const string input = "In the beginning, there was {{#ifGreaterThanOne}}one and{{/ifGreaterThanOne}} only one subject";
			var template = new Template
			{
				TextTemplate = input
			};

			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 1);
			Assert.IsTrue(result.StringVariables.Count == 0);
			Assert.IsTrue(result.BooleanLogics.Any(a => a.Name == "ifGreaterThanOne"));
		}
Example #5
0
		public void ShouldReturnTwoBooleanLogics()
		{
			const string input =
				"In the {{#ifGreater}}beginning{{/ifGreater}}{{#ifLesser}}end{{/ifLesser}}, there was something.";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 2);
			Assert.IsTrue(result.StringVariables.Count == 0);
			Assert.IsTrue(result.BooleanLogics.Any(a => a.Name == "ifGreater"));
			Assert.IsTrue(result.BooleanLogics.Any(a => a.Name == "ifLesser"));
		}
Example #6
0
		public void StringVariableShouldSupportDescriptions()
		{
			const string input = "I have {{number|Number of pickles}} pickles!";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 0);
			Assert.IsTrue(result.StringVariables.Count == 1);
			Assert.IsTrue(result.StringVariables[0].Name == "number");
			Assert.IsTrue(result.StringVariables[0].Description == "Number of pickles");
		}
Example #7
0
		public void CombineVariablesTestWithDescriptions()
		{
			const string input =
				"Don't {{verb}} each {{#repeater}}and every {{/repeater}}{{time|Days or weeks}} by the {{noun}} you reap{{#includeRest|Includes the rest of the phrase}}, but by the {{otherNoun}}s that you plant{{/includeRest}}.";
			var template = new Template
			{
				Subject = "My {{verb}}",
				TextTemplate = input
			};

			var service = new Parser();

			var emailScope = service.InitializeEmail(template);

			emailScope.StringVariables.First(a => a.Name == "verb").Value = "judge";
			emailScope.BooleanLogics.First(a => a.Name == "repeater").Value = false;
			emailScope.StringVariables.First(a => a.Name == "time").Value = "day";
			emailScope.StringVariables.First(a => a.Name == "noun").Value = "harvest";
			emailScope.BooleanLogics.First(a => a.Name == "includeRest").Value = true;
			emailScope.StringVariables.First(a => a.Name == "otherNoun").Value = "seed";

			var output = service.FinalizeTemplate(emailScope);
			Assert.AreEqual("Don't judge each day by the harvest you reap, but by the seeds that you plant.", output.PlainEmailBody);
			Assert.AreEqual("My judge", output.Subject);
			Assert.IsTrue(emailScope.StringVariables.First(a => a.Name == "time").Description == "Days or weeks");
			Assert.IsTrue(emailScope.StringVariables.First(a => a.Name == "verb").Description == "");
			Assert.IsTrue(emailScope.BooleanLogics.First(a => a.Name == "includeRest").Description == "Includes the rest of the phrase");
			Assert.IsTrue(emailScope.BooleanLogics.First(a => a.Name == "repeater").Description == "");
		}
Example #8
0
		public void CombineDuplicateVariablesTest()
		{
			const string input =
				"Don't {{verb}} each {{#repeater}}and every {{/repeater}}{{time}} by the {{noun}} you reap{{#includeRest}}, but by the {{otherNoun}}s that you plant{{/includeRest}}. Yes, {{otherNoun}}s.";
			var template = new Template
			{
				TextTemplate = input
			};

			var service = new Parser();
			var emailScope = service.InitializeEmail(template);

			emailScope.StringVariables.First(a => a.Name == "verb").Value = "judge";
			emailScope.BooleanLogics.First(a => a.Name == "repeater").Value = false;
			emailScope.StringVariables.First(a => a.Name == "time").Value = "day";
			emailScope.StringVariables.First(a => a.Name == "noun").Value = "harvest";
			emailScope.BooleanLogics.First(a => a.Name == "includeRest").Value = true;
			emailScope.StringVariables.First(a => a.Name == "otherNoun").Value = "seed";

			var output = service.FinalizeTemplate(emailScope);
			Assert.AreEqual("Don't judge each day by the harvest you reap, but by the seeds that you plant. Yes, seeds.", output.PlainEmailBody);
		}
Example #9
0
		public void CombineVariablesTest()
		{
			const string plainInput =
				"Don't {{verb}} each {{#repeater}}and every {{/repeater}}{{time}} by the {{noun}} you reap{{#includeRest}}, but by the {{otherNoun}}s that you plant{{/includeRest}}.";
			const string htmlInput =
				"<html><head></head><body><h1>Don't</h1> {{verb}} each {{#repeater}}and every {{/repeater}}{{time}}.</body></html>";
			var template = new Template
			{
				Subject = "This is my {{noun}}",
				HtmlTemplate = htmlInput,
				TextTemplate = plainInput
			};
			var service = new Parser();

			var emailScope = service.InitializeEmail(template);

			emailScope.StringVariables.First(a => a.Name == "verb").Value = "judge";
			emailScope.BooleanLogics.First(a => a.Name == "repeater").Value = false;
			emailScope.StringVariables.First(a => a.Name == "time").Value = "day";
			emailScope.StringVariables.First(a => a.Name == "noun").Value = "harvest";
			emailScope.BooleanLogics.First(a => a.Name == "includeRest").Value = true;
			emailScope.StringVariables.First(a => a.Name == "otherNoun").Value = "seed";

			var output = service.FinalizeTemplate(emailScope);
			Assert.AreEqual("Don't judge each day by the harvest you reap, but by the seeds that you plant.", output.PlainEmailBody);
			Assert.AreEqual("<html><head></head><body><h1>Don't</h1> judge each day.</body></html>", output.HtmlEmailBody);
			Assert.AreEqual("This is my harvest", output.Subject);
		}
Example #10
0
		public void HtmlParseWithNoTagsShouldYieldExpectedOutcome()
		{
			const string input = "<html><h1>Four scope and seven years ago...";
			var template = new Template
			{
				HtmlTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);
			var output = service.FinalizeTemplate(result);
			Assert.AreEqual("<html><h1>Four scope and seven years ago...", output.HtmlEmailBody);
		}
Example #11
0
		public void ShouldReturnTwoBooleanAndTwoVariablesWithSomeDescriptions()
		{
			const string input =
				"Back in the 4th of {{month|Month in the year}}, there {{#ifSingular}}was{{/ifSingular}}{{#ifPlural|Changes the tense}}were{{/ifPlural}} {{count}} different ways of doing things.";
			var template = new Template
			{
				TextTemplate = input
			};
			var service = new Parser();
			var result = service.InitializeEmail(template);

			Assert.IsTrue(result.BooleanLogics.Count == 2);
			Assert.IsTrue(result.StringVariables.Count == 2);
			Assert.IsTrue(result.StringVariables.Any(a => a.Name == "month"));
			Assert.IsTrue(result.StringVariables.First(a => a.Name == "month").Description == "Month in the year");
			Assert.IsTrue(result.StringVariables.Any(a => a.Name == "count"));
			Assert.IsTrue(result.StringVariables.First(a => a.Name == "count").Description == "");
			Assert.IsTrue(result.BooleanLogics.Any(a => a.Name == "ifSingular"));
			Assert.IsTrue(result.BooleanLogics.First(a => a.Name == "ifSingular").Description == "");
			Assert.IsTrue(result.BooleanLogics.Any(a => a.Name == "ifPlural"));
			Assert.IsTrue(result.BooleanLogics.First(a => a.Name == "ifPlural").Description == "Changes the tense");
		}