|
1 |
| -#region License |
2 |
| -// CommandLineOptionFormatterTests.cs |
3 |
| -// Copyright (c) 2013, Simon Williams |
4 |
| -// All rights reserved. |
5 |
| -// |
6 |
| -// Redistribution and use in source and binary forms, with or without modification, are permitted provide |
7 |
| -// d that the following conditions are met: |
8 |
| -// |
9 |
| -// Redistributions of source code must retain the above copyright notice, this list of conditions and the |
10 |
| -// following disclaimer. |
11 |
| -// |
12 |
| -// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
13 |
| -// the following disclaimer in the documentation and/or other materials provided with the distribution. |
14 |
| -// |
15 |
| -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
16 |
| -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
17 |
| -// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
18 |
| -// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
19 |
| -// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
20 |
| -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
21 |
| -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
22 |
| -// POSSIBILITY OF SUCH DAMAGE. |
23 |
| -#endregion |
24 |
| - |
25 |
| -using System; |
26 |
| -using System.Globalization; |
27 |
| -using System.Text; |
28 |
| -using Fclp.Internals; |
29 |
| -using Moq; |
30 |
| -using NUnit.Framework; |
31 |
| - |
32 |
| -namespace FluentCommandLineParser.Tests |
33 |
| -{ |
34 |
| - /// <summary> |
35 |
| - /// Contains unit test for the <see cref="CommandLineOptionFormatter"/> test. |
36 |
| - /// </summary> |
37 |
| - [TestFixture] |
38 |
| - public class CommandLineOptionFormatterTests |
39 |
| - { |
40 |
| - #region Constructors |
41 |
| - |
42 |
| - [Test] |
43 |
| - public void Ensure_Can_Be_Constructed() |
44 |
| - { |
45 |
| - new CommandLineOptionFormatter(); |
46 |
| - } |
47 |
| - |
48 |
| - #endregion Constructors |
49 |
| - |
50 |
| - #region Properties |
51 |
| - |
52 |
| - [Test] |
53 |
| - public void Ensure_ValueText_Can_Be_Set() |
54 |
| - { |
55 |
| - var formatter = new CommandLineOptionFormatter(); |
56 |
| - |
57 |
| - const string expected = "my value text"; |
58 |
| - |
59 |
| - formatter.ValueText = expected; |
60 |
| - |
61 |
| - Assert.AreEqual(expected, formatter.ValueText); |
62 |
| - } |
63 |
| - |
64 |
| - [Test] |
65 |
| - public void Ensure_DescriptionText_Can_Be_Set() |
66 |
| - { |
67 |
| - var formatter = new CommandLineOptionFormatter(); |
68 |
| - |
69 |
| - const string expected = "my description text"; |
70 |
| - |
71 |
| - formatter.DescriptionText = expected; |
72 |
| - |
73 |
| - Assert.AreEqual(expected, formatter.DescriptionText); |
74 |
| - } |
75 |
| - |
76 |
| - [Test] |
77 |
| - public void Ensure_NoOptionsText_Can_Be_Set() |
78 |
| - { |
79 |
| - var formatter = new CommandLineOptionFormatter(); |
80 |
| - |
81 |
| - const string expected = "no Options setup text"; |
82 |
| - |
83 |
| - formatter.NoOptionsText = expected; |
84 |
| - |
85 |
| - Assert.AreEqual(expected, formatter.NoOptionsText); |
86 |
| - } |
87 |
| - |
88 |
| - [Test] |
89 |
| - public void Ensure_Header_Can_Be_Set() |
90 |
| - { |
91 |
| - var formatter = new CommandLineOptionFormatter(); |
92 |
| - |
93 |
| - const string expected = "my custom header"; |
94 |
| - |
95 |
| - formatter.Header = expected; |
96 |
| - |
97 |
| - Assert.AreEqual(expected, formatter.Header); |
98 |
| - } |
99 |
| - |
100 |
| - #endregion Properties |
101 |
| - |
102 |
| - #region Format |
103 |
| - |
104 |
| - [Test] |
105 |
| - [ExpectedException(typeof(ArgumentNullException))] |
106 |
| - public void Ensure_Cannot_Specify_Null_options_Param() |
107 |
| - { |
108 |
| - var formatter = new CommandLineOptionFormatter(); |
109 |
| - |
110 |
| - formatter.Format(null); |
111 |
| - } |
112 |
| - |
113 |
| - [Test] |
114 |
| - public void Ensure_Format_Returns_Expected_String() |
115 |
| - { |
116 |
| - var formatter = new CommandLineOptionFormatter(); |
117 |
| - |
118 |
| - // expected: |
119 |
| - // Short1 Description1 |
120 |
| - // Short2:Long2 Description2 |
121 |
| - |
122 |
| - var mockOption1 = CreateMockOption("Short1", null, "Description1"); |
123 |
| - var mockOption2 = CreateMockOption("Short2", "Long2", "Description2"); |
124 |
| - |
125 |
| - var expectedSb = new StringBuilder(); |
126 |
| - expectedSb.AppendLine(); |
127 |
| - expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption1.ShortName, mockOption1.Description); |
128 |
| - expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption2.ShortName + ":" + mockOption2.LongName, mockOption2.Description); |
129 |
| - |
130 |
| - var expected = expectedSb.ToString(); |
131 |
| - var actual = formatter.Format(new[] { mockOption1, mockOption2 }); |
132 |
| - |
133 |
| - Assert.AreEqual(expected, actual, "Formatter returned unexpected string"); |
134 |
| - } |
135 |
| - |
136 |
| - [Test] |
137 |
| - public void Ensure_Header_Is_Displayed_If_One_Is_Set() |
138 |
| - { |
139 |
| - var formatter = new CommandLineOptionFormatter(); |
140 |
| - |
141 |
| - // expected: |
142 |
| - // my custom header |
143 |
| - // |
144 |
| - // Short1 Description1 |
145 |
| - // Short2:Long2 Description2 |
146 |
| - |
147 |
| - const string expectedHeader = "my custom header"; |
148 |
| - |
149 |
| - formatter.Header = expectedHeader; |
150 |
| - |
151 |
| - var mockOption1 = CreateMockOption("Short1", null, "Description1"); |
152 |
| - var mockOption2 = CreateMockOption("Short2", "Long2", "Description2"); |
153 |
| - |
154 |
| - var expectedSb = new StringBuilder(); |
155 |
| - expectedSb.AppendLine(); |
156 |
| - expectedSb.AppendLine(expectedHeader); |
157 |
| - expectedSb.AppendLine(); |
158 |
| - expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption1.ShortName, mockOption1.Description); |
159 |
| - expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption2.ShortName + ":" + mockOption2.LongName, mockOption2.Description); |
160 |
| - |
161 |
| - var expected = expectedSb.ToString(); |
162 |
| - var actual = formatter.Format(new[] { mockOption1, mockOption2 }); |
163 |
| - |
164 |
| - Assert.AreEqual(expected, actual, "Formatter returned unexpected string"); |
165 |
| - } |
166 |
| - |
167 |
| - [Test] |
168 |
| - public void Ensure_NoOptionsText_Returned_If_No_options_Have_Been_Setup() |
169 |
| - { |
170 |
| - var formatter = new CommandLineOptionFormatter(); |
171 |
| - |
172 |
| - var actual = formatter.Format(new ICommandLineOption[0]); |
173 |
| - |
174 |
| - Assert.AreEqual(formatter.NoOptionsText, actual); |
175 |
| - } |
176 |
| - |
177 |
| - #endregion Format |
178 |
| - |
179 |
| - #region Helper Methods |
180 |
| - |
181 |
| - /// <summary> |
182 |
| - /// Helper method to return a mocked <see cref="ICommandLineOption"/>. |
183 |
| - /// </summary> |
184 |
| - static ICommandLineOption CreateMockOption(string shortName, string longName, string description) |
185 |
| - { |
186 |
| - var mockOption = new Mock<ICommandLineOption>(); |
187 |
| - mockOption.SetupGet(x => x.ShortName).Returns(shortName); |
188 |
| - mockOption.SetupGet(x => x.LongName).Returns(longName); |
189 |
| - mockOption.SetupGet(x => x.Description).Returns(description); |
190 |
| - return mockOption.Object; |
191 |
| - } |
192 |
| - |
193 |
| - #endregion Helper Methods |
194 |
| - } |
195 |
| -} |
196 |
| - |
| 1 | +#region License |
| 2 | +// CommandLineOptionFormatterTests.cs |
| 3 | +// Copyright (c) 2013, Simon Williams |
| 4 | +// All rights reserved. |
| 5 | +// |
| 6 | +// Redistribution and use in source and binary forms, with or without modification, are permitted provide |
| 7 | +// d that the following conditions are met: |
| 8 | +// |
| 9 | +// Redistributions of source code must retain the above copyright notice, this list of conditions and the |
| 10 | +// following disclaimer. |
| 11 | +// |
| 12 | +// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
| 13 | +// the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 14 | +// |
| 15 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 16 | +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 17 | +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 18 | +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 19 | +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 20 | +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 21 | +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 22 | +// POSSIBILITY OF SUCH DAMAGE. |
| 23 | +#endregion |
| 24 | + |
| 25 | +using System; |
| 26 | +using System.Globalization; |
| 27 | +using System.Text; |
| 28 | +using Fclp.Internals; |
| 29 | +using Moq; |
| 30 | +using NUnit.Framework; |
| 31 | + |
| 32 | +namespace FluentCommandLineParser.Tests |
| 33 | +{ |
| 34 | + /// <summary> |
| 35 | + /// Contains unit test for the <see cref="CommandLineOptionFormatter"/> test. |
| 36 | + /// </summary> |
| 37 | + [TestFixture] |
| 38 | + public class CommandLineOptionFormatterTests |
| 39 | + { |
| 40 | + #region Constructors |
| 41 | + |
| 42 | + [Test] |
| 43 | + public void Ensure_Can_Be_Constructed() |
| 44 | + { |
| 45 | + new CommandLineOptionFormatter(); |
| 46 | + } |
| 47 | + |
| 48 | + #endregion Constructors |
| 49 | + |
| 50 | + #region Properties |
| 51 | + |
| 52 | + [Test] |
| 53 | + public void Ensure_ValueText_Can_Be_Set() |
| 54 | + { |
| 55 | + var formatter = new CommandLineOptionFormatter(); |
| 56 | + |
| 57 | + const string expected = "my value text"; |
| 58 | + |
| 59 | + formatter.ValueText = expected; |
| 60 | + |
| 61 | + Assert.AreEqual(expected, formatter.ValueText); |
| 62 | + } |
| 63 | + |
| 64 | + [Test] |
| 65 | + public void Ensure_DescriptionText_Can_Be_Set() |
| 66 | + { |
| 67 | + var formatter = new CommandLineOptionFormatter(); |
| 68 | + |
| 69 | + const string expected = "my description text"; |
| 70 | + |
| 71 | + formatter.DescriptionText = expected; |
| 72 | + |
| 73 | + Assert.AreEqual(expected, formatter.DescriptionText); |
| 74 | + } |
| 75 | + |
| 76 | + [Test] |
| 77 | + public void Ensure_NoOptionsText_Can_Be_Set() |
| 78 | + { |
| 79 | + var formatter = new CommandLineOptionFormatter(); |
| 80 | + |
| 81 | + const string expected = "no Options setup text"; |
| 82 | + |
| 83 | + formatter.NoOptionsText = expected; |
| 84 | + |
| 85 | + Assert.AreEqual(expected, formatter.NoOptionsText); |
| 86 | + } |
| 87 | + |
| 88 | + [Test] |
| 89 | + public void Ensure_Header_Can_Be_Set() |
| 90 | + { |
| 91 | + var formatter = new CommandLineOptionFormatter(); |
| 92 | + |
| 93 | + const string expected = "my custom header"; |
| 94 | + |
| 95 | + formatter.Header = expected; |
| 96 | + |
| 97 | + Assert.AreEqual(expected, formatter.Header); |
| 98 | + } |
| 99 | + |
| 100 | + #endregion Properties |
| 101 | + |
| 102 | + #region Format |
| 103 | + |
| 104 | + [Test] |
| 105 | + [ExpectedException(typeof(ArgumentNullException))] |
| 106 | + public void Ensure_Cannot_Specify_Null_options_Param() |
| 107 | + { |
| 108 | + var formatter = new CommandLineOptionFormatter(); |
| 109 | + |
| 110 | + formatter.Format(null); |
| 111 | + } |
| 112 | + |
| 113 | + [Test] |
| 114 | + public void Ensure_Format_Returns_Expected_String() |
| 115 | + { |
| 116 | + var formatter = new CommandLineOptionFormatter(); |
| 117 | + |
| 118 | + // expected: |
| 119 | + // Short1 Description1 |
| 120 | + // Short2:Long2 Description2 |
| 121 | + |
| 122 | + var mockOption1 = CreateMockOption("Short1", null, "Description1"); |
| 123 | + var mockOption2 = CreateMockOption("Short2", "Long2", "Description2"); |
| 124 | + |
| 125 | + var expectedSb = new StringBuilder(); |
| 126 | + expectedSb.AppendLine(); |
| 127 | + expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption1.ShortName, mockOption1.Description); |
| 128 | + expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption2.ShortName + ":" + mockOption2.LongName, mockOption2.Description); |
| 129 | + |
| 130 | + var expected = expectedSb.ToString(); |
| 131 | + var actual = formatter.Format(new[] { mockOption1, mockOption2 }); |
| 132 | + |
| 133 | + Assert.AreEqual(expected, actual, "Formatter returned unexpected string"); |
| 134 | + } |
| 135 | + |
| 136 | + [Test] |
| 137 | + public void Ensure_Header_Is_Displayed_If_One_Is_Set() |
| 138 | + { |
| 139 | + var formatter = new CommandLineOptionFormatter(); |
| 140 | + |
| 141 | + // expected: |
| 142 | + // my custom header |
| 143 | + // |
| 144 | + // Short1 Description1 |
| 145 | + // Short2:Long2 Description2 |
| 146 | + |
| 147 | + const string expectedHeader = "my custom header"; |
| 148 | + |
| 149 | + formatter.Header = expectedHeader; |
| 150 | + |
| 151 | + var mockOption1 = CreateMockOption("Short1", null, "Description1"); |
| 152 | + var mockOption2 = CreateMockOption("Short2", "Long2", "Description2"); |
| 153 | + |
| 154 | + var expectedSb = new StringBuilder(); |
| 155 | + expectedSb.AppendLine(); |
| 156 | + expectedSb.AppendLine(expectedHeader); |
| 157 | + expectedSb.AppendLine(); |
| 158 | + expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption1.ShortName, mockOption1.Description); |
| 159 | + expectedSb.AppendFormat(CultureInfo.CurrentUICulture, CommandLineOptionFormatter.TextFormat, mockOption2.ShortName + ":" + mockOption2.LongName, mockOption2.Description); |
| 160 | + |
| 161 | + var expected = expectedSb.ToString(); |
| 162 | + var actual = formatter.Format(new[] { mockOption1, mockOption2 }); |
| 163 | + |
| 164 | + Assert.AreEqual(expected, actual, "Formatter returned unexpected string"); |
| 165 | + } |
| 166 | + |
| 167 | + [Test] |
| 168 | + public void Ensure_NoOptionsText_Returned_If_No_options_Have_Been_Setup() |
| 169 | + { |
| 170 | + var formatter = new CommandLineOptionFormatter(); |
| 171 | + |
| 172 | + var actual = formatter.Format(new ICommandLineOption[0]); |
| 173 | + |
| 174 | + Assert.AreEqual(formatter.NoOptionsText, actual); |
| 175 | + } |
| 176 | + |
| 177 | + #endregion Format |
| 178 | + |
| 179 | + #region Helper Methods |
| 180 | + |
| 181 | + /// <summary> |
| 182 | + /// Helper method to return a mocked <see cref="ICommandLineOption"/>. |
| 183 | + /// </summary> |
| 184 | + static ICommandLineOption CreateMockOption(string shortName, string longName, string description) |
| 185 | + { |
| 186 | + var mockOption = new Mock<ICommandLineOption>(); |
| 187 | + mockOption.SetupGet(x => x.ShortName).Returns(shortName); |
| 188 | + mockOption.SetupGet(x => x.LongName).Returns(longName); |
| 189 | + mockOption.SetupGet(x => x.Description).Returns(description); |
| 190 | + return mockOption.Object; |
| 191 | + } |
| 192 | + |
| 193 | + #endregion Helper Methods |
| 194 | + } |
| 195 | +} |
| 196 | +
|
0 commit comments