|
14 | 14 | using Rubberduck.UI.Command.ComCommands;
|
15 | 15 | using RubberduckTests.Mocks;
|
16 | 16 | using Rubberduck.VBEditor.SafeComWrappers.Abstract;
|
17 |
| -using Rubberduck.Parsing.Symbols; |
18 | 17 |
|
19 | 18 | namespace RubberduckTests.CodeExplorer
|
20 | 19 | {
|
@@ -592,12 +591,133 @@ public void UpdateFromFile_Cancel()
|
592 | 591 | {
|
593 | 592 | const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas";
|
594 | 593 |
|
595 |
| - using (var explorer = new MockedCodeExplorer(ProjectType.HostProject) |
| 594 | + using (var explorer = new MockedCodeExplorer( |
| 595 | + ProjectType.HostProject, |
| 596 | + ("TestModule", ComponentType.StandardModule, string.Empty)) |
596 | 597 | .ConfigureOpenDialog(new[] { path }, DialogResult.Cancel)
|
597 | 598 | .SelectFirstProject())
|
598 | 599 | {
|
599 |
| - explorer.ExecuteUpdateFromFileCommand(filename => filename); |
600 |
| - explorer.VbComponents.Verify(c => c.Import(path), Times.Never); |
| 600 | + explorer.ExecuteUpdateFromFileCommand(filename => "TestModule"); |
| 601 | + explorer.VbComponents.Verify(c => c.Import(It.IsAny<string>()), Times.Never); |
| 602 | + explorer.VbComponents.Verify(c => c.Remove(It.IsAny<IVBComponent>()), Times.Never); |
| 603 | + } |
| 604 | + } |
| 605 | + |
| 606 | + [Category("Code Explorer")] |
| 607 | + [Test] |
| 608 | + public void ReplaceProjectContentsFromFiles_Imports() |
| 609 | + { |
| 610 | + const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas"; |
| 611 | + |
| 612 | + using (var explorer = new MockedCodeExplorer( |
| 613 | + ProjectType.HostProject, |
| 614 | + ("TestModule", ComponentType.StandardModule, string.Empty)) |
| 615 | + .ConfigureOpenDialog(new[] { path }, DialogResult.OK) |
| 616 | + .SelectFirstProject()) |
| 617 | + { |
| 618 | + explorer.ExecuteReplaceProjectContentsFromFilesCommand(); |
| 619 | + explorer.VbComponents.Verify(c => c.Import(path), Times.Once); |
| 620 | + } |
| 621 | + } |
| 622 | + |
| 623 | + [Category("Code Explorer")] |
| 624 | + [Test] |
| 625 | + public void ReplaceProjectContentsFromFiles_ImportsMultiple() |
| 626 | + { |
| 627 | + const string path1 = @"C:\Users\Rubberduck\Desktop\StdModule1.bas"; |
| 628 | + const string path2 = @"C:\Users\Rubberduck\Desktop\Class1.cls"; |
| 629 | + |
| 630 | + using (var explorer = new MockedCodeExplorer( |
| 631 | + ProjectType.HostProject, |
| 632 | + ("TestModule", ComponentType.StandardModule, string.Empty)) |
| 633 | + .ConfigureOpenDialog(new[] { path1, path2 }, DialogResult.OK) |
| 634 | + .SelectFirstProject()) |
| 635 | + { |
| 636 | + explorer.ExecuteReplaceProjectContentsFromFilesCommand(); |
| 637 | + explorer.VbComponents.Verify(c => c.Import(path1), Times.Once); |
| 638 | + explorer.VbComponents.Verify(c => c.Import(path2), Times.Once); |
| 639 | + } |
| 640 | + } |
| 641 | + |
| 642 | + [Category("Code Explorer")] |
| 643 | + [Test] |
| 644 | + public void ReplaceProjectContentsFromFiles_RemovesReimportableComponents() |
| 645 | + { |
| 646 | + const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas"; |
| 647 | + |
| 648 | + using (var explorer = new MockedCodeExplorer( |
| 649 | + ProjectType.HostProject, |
| 650 | + ("TestModule", ComponentType.StandardModule, string.Empty), |
| 651 | + ("TestClass", ComponentType.ClassModule, string.Empty), |
| 652 | + ("TestUserForm", ComponentType.UserForm, string.Empty)) |
| 653 | + .ConfigureOpenDialog(new[] { path }, DialogResult.OK) |
| 654 | + .SelectFirstProject()) |
| 655 | + { |
| 656 | + explorer.ExecuteReplaceProjectContentsFromFilesCommand(); |
| 657 | + |
| 658 | + var modulesNames = explorer |
| 659 | + .VbComponents |
| 660 | + .Object |
| 661 | + .Select(component => component.Name) |
| 662 | + .ToList(); |
| 663 | + |
| 664 | + explorer.VbComponents.Verify(c => c.Remove(It.IsAny<IVBComponent>()), Times.Exactly(3)); |
| 665 | + |
| 666 | + Assert.IsFalse(modulesNames.Contains("TestModule")); |
| 667 | + Assert.IsFalse(modulesNames.Contains("TestClass")); |
| 668 | + Assert.IsFalse(modulesNames.Contains("TestUserForm")); |
| 669 | + |
| 670 | + //This depends on the setup of Import on the VBComponents mock, which determines the component name from the filename. |
| 671 | + Assert.IsTrue(modulesNames.Contains("StdModule1")); |
| 672 | + } |
| 673 | + } |
| 674 | + |
| 675 | + [Category("Code Explorer")] |
| 676 | + [Test] |
| 677 | + public void ReplaceProjectContentsFromFiles_DoesNotRemoveNonReimportableComponents() |
| 678 | + { |
| 679 | + const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas"; |
| 680 | + |
| 681 | + using (var explorer = new MockedCodeExplorer( |
| 682 | + ProjectType.HostProject, |
| 683 | + ("TestModule", ComponentType.StandardModule, string.Empty), |
| 684 | + ("TestDocument", ComponentType.Document, string.Empty)) |
| 685 | + .ConfigureOpenDialog(new[] { path }, DialogResult.OK) |
| 686 | + .SelectFirstProject()) |
| 687 | + { |
| 688 | + explorer.ExecuteReplaceProjectContentsFromFilesCommand(); |
| 689 | + |
| 690 | + var modulesNames = explorer |
| 691 | + .VbComponents |
| 692 | + .Object |
| 693 | + .Select(component => component.Name) |
| 694 | + .ToList(); |
| 695 | + |
| 696 | + explorer.VbComponents.Verify(c => c.Remove(It.IsAny<IVBComponent>()), Times.Once); |
| 697 | + |
| 698 | + Assert.IsTrue(modulesNames.Contains("TestDocument")); |
| 699 | + Assert.IsFalse(modulesNames.Contains("TestModule")); |
| 700 | + |
| 701 | + //This depends on the setup of Import on the VBComponents mock, which determines the component name from the filename. |
| 702 | + Assert.IsTrue(modulesNames.Contains("StdModule1")); |
| 703 | + } |
| 704 | + } |
| 705 | + |
| 706 | + [Category("Code Explorer")] |
| 707 | + [Test] |
| 708 | + public void ReplaceProjectContentsFromFiles_Cancel() |
| 709 | + { |
| 710 | + const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas"; |
| 711 | + |
| 712 | + using (var explorer = new MockedCodeExplorer( |
| 713 | + ProjectType.HostProject, |
| 714 | + ("TestModule", ComponentType.StandardModule, string.Empty)) |
| 715 | + .ConfigureOpenDialog(new[] { path }, DialogResult.Cancel) |
| 716 | + .SelectFirstProject()) |
| 717 | + { |
| 718 | + explorer.ExecuteReplaceProjectContentsFromFilesCommand(); |
| 719 | + explorer.VbComponents.Verify(c => c.Import(It.IsAny<string>()), Times.Never); |
| 720 | + explorer.VbComponents.Verify(c => c.Remove(It.IsAny<IVBComponent>()), Times.Never); |
601 | 721 | }
|
602 | 722 | }
|
603 | 723 |
|
|
0 commit comments