PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/Text/CopyrightInfoFixture.cs

https://github.com/sflanker/commandline
C# | 143 lines | 96 code | 21 blank | 26 comment | 3 complexity | e9a44dfa050e06e650268d7fabd3e747 MD5 | raw file
Possible License(s): Apache-2.0
  1. #region License
  2. //
  3. // Command Line Library: CopyrightInfoFixture.cs
  4. //
  5. // Author:
  6. // Giacomo Stelluti Scala (gsscoder@gmail.com)
  7. //
  8. // Copyright (C) 2005 - 2013 Giacomo Stelluti Scala
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. // THE SOFTWARE.
  27. //
  28. #endregion
  29. #region Using Directives
  30. using System;
  31. using System.Globalization;
  32. using System.Text;
  33. using Xunit;
  34. using FluentAssertions;
  35. #endregion
  36. namespace CommandLine.Text.Tests
  37. {
  38. public class CopyrightInfoFixture
  39. {
  40. #region Mock Objects
  41. private sealed class CopyleftInfo : CopyrightInfo
  42. {
  43. public CopyleftInfo(bool isSymbolUpper, string author, params int[] years)
  44. : base(isSymbolUpper, author, years)
  45. {
  46. }
  47. protected override string CopyrightWord
  48. {
  49. get { return "Copyleft"; }
  50. }
  51. protected override string FormatYears(int[] years)
  52. {
  53. var yearsPart = new StringBuilder(years.Length * 4);
  54. foreach (int year in years)
  55. {
  56. string y = year.ToString(CultureInfo.InvariantCulture);
  57. if (y.Length == 2)
  58. yearsPart.Append(string.Concat("'", y));
  59. else
  60. yearsPart.Append(y);
  61. yearsPart.Append(", ");
  62. }
  63. yearsPart.Remove(yearsPart.Length - 2, 2);
  64. return yearsPart.ToString();
  65. }
  66. }
  67. #endregion
  68. [Fact]
  69. public void Lower_symbol_one_year()
  70. {
  71. var copyright = new CopyrightInfo(false, "Authors, Inc.", 2007);
  72. copyright.ToString().Should().Be("Copyright (c) 2007 Authors, Inc.");
  73. }
  74. [Fact]
  75. public void Upper_symbol_two_consecutive_years()
  76. {
  77. var copyright = new CopyrightInfo(true, "X & Y Group", 2006, 2007);
  78. copyright.ToString().Should().Be("Copyright (C) 2006, 2007 X & Y Group");
  79. }
  80. [Fact]
  81. public void Default_symbol_two_non_consecutive_years()
  82. {
  83. var copyright = new CopyrightInfo("W & Z, Inc.", 2005, 2007);
  84. copyright.ToString().Should().Be("Copyright (C) 2005 - 2007 W & Z, Inc.");
  85. }
  86. [Fact]
  87. public void Default_symbol_several_years()
  88. {
  89. var copyright = new CopyrightInfo("CommandLine, Ltd", 1999, 2003, 2004, 2007);
  90. copyright.ToString().Should().Be("Copyright (C) 1999 - 2003, 2004 - 2007 CommandLine, Ltd");
  91. }
  92. [Fact]
  93. public void Will_throw_exception_if_author_is_null()
  94. {
  95. Assert.Throws<ArgumentException>(
  96. () => new CopyrightInfo(null, 2000));
  97. }
  98. [Fact]
  99. public void Will_throw_exception_if_no_years_are_supplied()
  100. {
  101. Assert.Throws<ArgumentOutOfRangeException>(
  102. () => new CopyrightInfo("Authors, Inc."));
  103. }
  104. [Fact]
  105. public void Derived_class()
  106. {
  107. var info = new CopyleftInfo(true, "Free Company, Inc.", 96, 97, 98, 2005);
  108. info.ToString().Should().Be("Copyleft (C) '96, '97, '98, 2005 Free Company, Inc.");
  109. }
  110. #region #BUG0006
  111. [Fact]
  112. public void Should_not_grow_when_converted_to_string()
  113. {
  114. var info = new CopyrightInfo ("ManOnTheMoon, Inc.", 2019);
  115. for (int i=0; i<10; i++)
  116. {
  117. info.ToString().Length.Should().Be(37);
  118. }
  119. }
  120. #endregion
  121. }
  122. }