|
2 | 2 |
|
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
5 | | -using System.Globalization; |
6 | 5 | using System.Linq; |
7 | 6 | using System.Reflection; |
8 | | -using CommandLine.Core; |
9 | 7 | using CommandLine.Infrastructure; |
10 | 8 | using CommandLine.Tests.Fakes; |
11 | | -using CommandLine.Tests.Unit.Infrastructure; |
12 | 9 | using CommandLine.Text; |
13 | 10 | using FluentAssertions; |
14 | 11 | using Xunit; |
15 | 12 | using System.Text; |
16 | 13 |
|
17 | 14 | namespace CommandLine.Tests.Unit.Text |
18 | 15 | { |
19 | | - public class HelpTextTests |
| 16 | + public class HelpTextTests : IDisposable |
20 | 17 | { |
| 18 | + public void Dispose() |
| 19 | + { |
| 20 | + ReflectionHelper.SetAttributeOverride(null); |
| 21 | + } |
| 22 | + |
21 | 23 | [Fact] |
22 | 24 | public void Create_empty_instance() |
23 | 25 | { |
@@ -573,91 +575,70 @@ public void Default_set_to_sequence_should_be_properly_printed() |
573 | 575 | [Fact] |
574 | 576 | public void AutoBuild_when_no_assembly_attributes() |
575 | 577 | { |
576 | | - try |
577 | | - { |
578 | | - string expectedCopyright = "Copyright (C) 1 author"; |
| 578 | + string expectedCopyright = "Copyright (C) 1 author"; |
579 | 579 |
|
580 | | - ReflectionHelper.SetAttributeOverride(new Attribute[0]); |
| 580 | + ReflectionHelper.SetAttributeOverride(new Attribute[0]); |
581 | 581 |
|
582 | | - ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
583 | | - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
584 | | - bool onErrorCalled = false; |
585 | | - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
586 | | - { |
587 | | - onErrorCalled = true; |
588 | | - return ht; |
589 | | - }, ex => ex); |
590 | | - |
591 | | - onErrorCalled.Should().BeTrue(); |
592 | | - actualResult.Copyright.Should().Be(expectedCopyright); |
593 | | - } |
594 | | - finally |
| 582 | + ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
| 583 | + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
| 584 | + bool onErrorCalled = false; |
| 585 | + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
595 | 586 | { |
596 | | - ReflectionHelper.SetAttributeOverride(null); |
597 | | - } |
| 587 | + onErrorCalled = true; |
| 588 | + return ht; |
| 589 | + }, ex => ex); |
| 590 | + |
| 591 | + onErrorCalled.Should().BeTrue(); |
| 592 | + actualResult.Copyright.Should().Be(expectedCopyright); |
598 | 593 | } |
599 | 594 |
|
600 | 595 | [Fact] |
601 | 596 | public void AutoBuild_with_assembly_title_and_version_attributes_only() |
602 | 597 | { |
603 | | - try |
604 | | - { |
605 | | - string expectedTitle = "Title"; |
606 | | - string expectedVersion = "1.2.3.4"; |
| 598 | + string expectedTitle = "Title"; |
| 599 | + string expectedVersion = "1.2.3.4"; |
607 | 600 |
|
608 | | - ReflectionHelper.SetAttributeOverride(new Attribute[] |
609 | | - { |
610 | | - new AssemblyTitleAttribute(expectedTitle), |
611 | | - new AssemblyInformationalVersionAttribute(expectedVersion) |
612 | | - }); |
613 | | - |
614 | | - ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
615 | | - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
616 | | - bool onErrorCalled = false; |
617 | | - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
618 | | - { |
619 | | - onErrorCalled = true; |
620 | | - return ht; |
621 | | - }, ex => ex); |
622 | | - |
623 | | - onErrorCalled.Should().BeTrue(); |
624 | | - actualResult.Heading.Should().Be(string.Format("{0} {1}", expectedTitle, expectedVersion)); |
625 | | - } |
626 | | - finally |
| 601 | + ReflectionHelper.SetAttributeOverride(new Attribute[] |
| 602 | + { |
| 603 | + new AssemblyTitleAttribute(expectedTitle), |
| 604 | + new AssemblyInformationalVersionAttribute(expectedVersion) |
| 605 | + }); |
| 606 | + |
| 607 | + ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
| 608 | + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
| 609 | + bool onErrorCalled = false; |
| 610 | + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
627 | 611 | { |
628 | | - ReflectionHelper.SetAttributeOverride(null); |
629 | | - } |
| 612 | + onErrorCalled = true; |
| 613 | + return ht; |
| 614 | + }, ex => ex); |
| 615 | + |
| 616 | + onErrorCalled.Should().BeTrue(); |
| 617 | + actualResult.Heading.Should().Be(string.Format("{0} {1}", expectedTitle, expectedVersion)); |
630 | 618 | } |
631 | 619 |
|
632 | 620 |
|
633 | 621 | [Fact] |
634 | 622 | public void AutoBuild_with_assembly_company_attribute_only() |
635 | 623 | { |
636 | | - try |
637 | | - { |
638 | | - string expectedCompany = "Company"; |
| 624 | + string expectedCompany = "Company"; |
639 | 625 |
|
640 | | - ReflectionHelper.SetAttributeOverride(new Attribute[] |
641 | | - { |
642 | | - new AssemblyCompanyAttribute(expectedCompany) |
643 | | - }); |
| 626 | + ReflectionHelper.SetAttributeOverride(new Attribute[] |
| 627 | + { |
| 628 | + new AssemblyCompanyAttribute(expectedCompany) |
| 629 | + }); |
644 | 630 |
|
645 | | - ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
646 | | - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
647 | | - bool onErrorCalled = false; |
648 | | - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
649 | | - { |
650 | | - onErrorCalled = true; |
651 | | - return ht; |
652 | | - }, ex => ex); |
653 | | - |
654 | | - onErrorCalled.Should().BeFalse(); // Other attributes have fallback logic |
655 | | - actualResult.Copyright.Should().Be(string.Format("Copyright (C) {0} {1}", DateTime.Now.Year, expectedCompany)); |
656 | | - } |
657 | | - finally |
| 631 | + ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>( |
| 632 | + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); |
| 633 | + bool onErrorCalled = false; |
| 634 | + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => |
658 | 635 | { |
659 | | - ReflectionHelper.SetAttributeOverride(null); |
660 | | - } |
| 636 | + onErrorCalled = true; |
| 637 | + return ht; |
| 638 | + }, ex => ex); |
| 639 | + |
| 640 | + onErrorCalled.Should().BeFalse(); // Other attributes have fallback logic |
| 641 | + actualResult.Copyright.Should().Be(string.Format("Copyright (C) {0} {1}", DateTime.Now.Year, expectedCompany)); |
661 | 642 | } |
662 | 643 |
|
663 | 644 | [Fact] |
|
0 commit comments