public void WhenComponentKeyDoesNotMatch() { // Arrange string longName = nameof(longName); string shortName = nameof(shortName); string key = nameof(key); DirectiveComponents components = new DirectiveComponents(key, null, null); var mock = new Mock <DirectiveHandler>(); mock.Setup(h => h.LongName).Returns(longName); mock.Setup(h => h.ShortName).Returns(shortName); DirectiveHandler sut = mock.Object; // Act Directive directive; bool result = sut.TryParse(components, out directive); // Assert Assert.AreNotEqual(longName, key); Assert.AreNotEqual(shortName, key); Assert.IsFalse(result); Assert.IsNull(directive); }
public void TryParseTest_LongForm_Other() { // Arrange string input = $"{{pagetype: not a valid page type}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = PageTypeHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsFalse(result); }
public void TryParseTest_NaN() { // Arrange string input = $"{{columns: NaN}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = ColumnsHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsFalse(result); Assert.IsNull(directive); }
public void TryParseTest_LongForm() { // Arrange string color = "red"; string input = $"{{chordcolour: {color}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = ChordColourHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(ChordColourDirective)); Assert.AreEqual(color, (directive as ChordColourDirective).Colour); }
public void TryParseTest_ShortForm() { // Arrange string subtitle = "some subtitle"; string input = $"{{st: {subtitle}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = SubtitleHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(SubtitleDirective)); Assert.AreEqual(subtitle, (directive as SubtitleDirective).Text); }
public void TryParseTest_ShortForm() { // Arrange string fontFamily = "times"; string input = $"{{tf: {fontFamily}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = TextFontHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(TextFontDirective)); Assert.AreEqual(fontFamily, (directive as TextFontDirective).FontFamily); }
public void TryParseTest_LongForm_A4() { // Arrange PageType pageType = PageType.A4; string input = $"{{pagetype: a4}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = PageTypeHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(PageTypeDirective)); Assert.AreEqual(pageType, (directive as PageTypeDirective).PageType); }
public void TryParseTest_ShortForm() { // Arrange string comment = "some comment"; string input = $"{{ci: {comment}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = CommentItalicHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(CommentItalicDirective)); Assert.AreEqual(comment, (directive as CommentItalicDirective).Text); }
public void TryParseTest_ShortForm() { // Arrange int number = 3; string input = $"{{col: {number}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = ColumnsHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(ColumnsDirective)); Assert.AreEqual(number, (directive as ColumnsDirective).Number); }
public void TryParseTest_ShortForm() { // Arrange int fontSize = 9; string input = $"{{ts: {fontSize}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = TextSizeHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(TextSizeDirective)); Assert.AreEqual(fontSize, (directive as TextSizeDirective).FontSize); }
public void TryParseTest_LongForm_Center() { // Arrange Alignment alignment = Alignment.Center; string input = $"{{titles: center}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = TitlesHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(TitlesDirective)); Assert.AreEqual(alignment, (directive as TitlesDirective).Flush); }
public void TryParseTest_LongForm() { // Arrange string chord = "X"; string definition = "some definition"; string input = $"{{define {chord}: {definition}}}"; DirectiveComponents components = DirectiveComponents.Parse(input); DirectiveHandler sut = DefineHandler.Instance; Directive directive; // Act bool result = sut.TryParse(components, out directive); // Assert Assert.IsTrue(result); Assert.IsInstanceOfType(directive, typeof(DefineDirective)); Assert.AreEqual(chord, (directive as DefineDirective).Chord); Assert.AreEqual(definition, (directive as DefineDirective).Definition); }
public void WhenSubKeyIsRequiredButIsMissing() { // Arrange string key = nameof(key); DirectiveComponents components = new DirectiveComponents(key, null, null); var mock = new Mock <DirectiveHandler>(); mock.Setup(h => h.LongName).Returns(key); mock.Setup(h => h.SubKey).Returns(ComponentPresence.Required); mock.Setup(h => h.Value).Returns(ComponentPresence.Optional); DirectiveHandler sut = mock.Object; // Act Directive directive; bool result = sut.TryParse(components, out directive); // Assert Assert.IsFalse(result); Assert.IsNull(directive); }