|
4 | 4 | usingSystem.Collections.Generic; |
5 | 5 | usingSystem.Globalization; |
6 | 6 | usingSystem.Linq; |
| 7 | +usingSystem.Reflection; |
7 | 8 | usingCommandLine.Core; |
| 9 | +usingCommandLine.Infrastructure; |
8 | 10 | usingCommandLine.Tests.Fakes; |
| 11 | +usingCommandLine.Tests.Unit.Infrastructure; |
9 | 12 | usingCommandLine.Text; |
10 | 13 | usingFluentAssertions; |
11 | 14 | usingXunit; |
@@ -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 | +publicvoidAutoBuild_when_no_assembly_attributes() |
| 573 | +{ |
| 574 | +try |
| 575 | +{ |
| 576 | +stringexpectedCopyright="Copyright (C) 1 author"; |
| 577 | + |
| 578 | +ReflectionHelper.SetAttributeOverride(newAttribute[0]); |
| 579 | + |
| 580 | +ParserResult<Simple_Options>fakeResult=newNotParsed<Simple_Options>( |
| 581 | +TypeInfo.Create(typeof(Simple_Options)),newError[0]); |
| 582 | +boolonErrorCalled=false; |
| 583 | +HelpTextactualResult=HelpText.AutoBuild(fakeResult, ht => |
| 584 | +{ |
| 585 | +onErrorCalled=true; |
| 586 | +returnht; |
| 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 | +publicvoidAutoBuild_with_assembly_title_and_version_attributes_only() |
| 600 | +{ |
| 601 | +try |
| 602 | +{ |
| 603 | +stringexpectedTitle="Title"; |
| 604 | +stringexpectedVersion="1.2.3.4"; |
| 605 | + |
| 606 | +ReflectionHelper.SetAttributeOverride(newAttribute[] |
| 607 | +{ |
| 608 | +newAssemblyTitleAttribute(expectedTitle), |
| 609 | +newAssemblyInformationalVersionAttribute(expectedVersion) |
| 610 | +}); |
| 611 | + |
| 612 | +ParserResult<Simple_Options>fakeResult=newNotParsed<Simple_Options>( |
| 613 | +TypeInfo.Create(typeof(Simple_Options)),newError[0]); |
| 614 | +boolonErrorCalled=false; |
| 615 | +HelpTextactualResult=HelpText.AutoBuild(fakeResult, ht => |
| 616 | +{ |
| 617 | +onErrorCalled=true; |
| 618 | +returnht; |
| 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 | +publicvoidAutoBuild_with_assembly_company_attribute_only() |
| 633 | +{ |
| 634 | +try |
| 635 | +{ |
| 636 | +stringexpectedCompany="Company"; |
| 637 | + |
| 638 | +ReflectionHelper.SetAttributeOverride(newAttribute[] |
| 639 | +{ |
| 640 | +newAssemblyCompanyAttribute(expectedCompany) |
| 641 | +}); |
| 642 | + |
| 643 | +ParserResult<Simple_Options>fakeResult=newNotParsed<Simple_Options>( |
| 644 | +TypeInfo.Create(typeof(Simple_Options)),newError[0]); |
| 645 | +boolonErrorCalled=false; |
| 646 | +HelpTextactualResult=HelpText.AutoBuild(fakeResult, ht => |
| 647 | +{ |
| 648 | +onErrorCalled=true; |
| 649 | +returnht; |
| 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