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