|
| 1 | +//These tests work fine one at a time, but MSUnit runs async, so they all try to hit the |
| 2 | +//file system at the same time. Leaving them here because I'm sure I'll need them in the future. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.IO; |
| 7 | +using Microsoft.Vbe.Interop; |
| 8 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 9 | +using Moq; |
| 10 | +using Rubberduck.SourceControl; |
| 11 | +using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane; |
| 12 | + |
| 13 | +namespace RubberduckTests.SourceControl |
| 14 | +{ |
| 15 | + [TestClass] |
| 16 | + public class SourceControlTests |
| 17 | + { |
| 18 | + [Ignore] |
| 19 | + [TestMethod] |
| 20 | + public void InitVBAProjectIntitializesRepo() |
| 21 | + { |
| 22 | + //Assert.Inconclusive("This test accesses file system."); |
| 23 | + |
| 24 | + //arrange |
| 25 | + var component = new Mock<VBComponent>(); |
| 26 | + component.Setup(c => c.Name).Returns("Module1"); |
| 27 | + component.Setup(c => c.Type).Returns(vbext_ComponentType.vbext_ct_StdModule); |
| 28 | + component.Setup(c => c.Export("foo")).Verifiable(); |
| 29 | + |
| 30 | + var componentList = new List<VBComponent> { component.Object }; |
| 31 | + |
| 32 | + var components = new Mock<VBComponents>(); |
| 33 | + components.Setup(c => c.GetEnumerator()).Returns(componentList.GetEnumerator()); |
| 34 | + |
| 35 | + var project = new Mock<VBProject>(); |
| 36 | + |
| 37 | + project.Setup(p => p.VBComponents).Returns(components.Object); |
| 38 | + project.Setup(p => p.Name).Returns("SourceControlTest"); |
| 39 | + |
| 40 | + //act |
| 41 | + var git = new GitProvider(project.Object); |
| 42 | + git.InitVBAProject(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); |
| 43 | + |
| 44 | + //assert |
| 45 | + Assert.AreEqual(project.Object.Name, git.CurrentRepository.Name); |
| 46 | + |
| 47 | + var repoDir = Path.Combine(git.CurrentRepository.LocalLocation, ".git"); |
| 48 | + Assert.IsTrue(Directory.Exists(repoDir), "Repo directory does not exist."); |
| 49 | + } |
| 50 | + |
| 51 | + [Ignore] |
| 52 | + [TestMethod] |
| 53 | + public void CloneCreatesLocalRepo() |
| 54 | + { |
| 55 | + //Assert.Inconclusive("This test accesses file system."); |
| 56 | + |
| 57 | + //arrange |
| 58 | + var project = new Mock<VBProject>(); |
| 59 | + var expected = new Repository("SourceControlTest", |
| 60 | + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SourceControlTest"), |
| 61 | + @"https://github.com/ckuhn203/SourceControlTest.git" |
| 62 | + ); |
| 63 | + var git = new GitProvider(project.Object); |
| 64 | + |
| 65 | + //act |
| 66 | + var actual = git.Clone(expected.RemoteLocation, expected.LocalLocation); |
| 67 | + |
| 68 | + //assert |
| 69 | + Assert.AreEqual(expected.Name, actual.Name); |
| 70 | + Assert.AreEqual(expected.LocalLocation, actual.LocalLocation); |
| 71 | + Assert.AreEqual(expected.RemoteLocation, actual.RemoteLocation); |
| 72 | + Assert.IsTrue(Directory.Exists(Path.Combine(expected.LocalLocation, ".git"))); |
| 73 | + } |
| 74 | + |
| 75 | + [Ignore] |
| 76 | + [TestMethod] |
| 77 | + public void CreateBranchTest() |
| 78 | + { |
| 79 | + //Assert.Inconclusive("This test accesses file system."); |
| 80 | + |
| 81 | + var project = new Mock<VBProject>(); |
| 82 | + var repo = new Repository("SourceControlTest", |
| 83 | + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SourceControlTest"), |
| 84 | + @"https://github.com/ckuhn203/SourceControlTest.git" |
| 85 | + ); |
| 86 | + var git = new GitProvider(project.Object); |
| 87 | + git = new GitProvider(project.Object, git.Clone(repo.RemoteLocation, repo.LocalLocation), new CodePaneWrapperFactory()); |
| 88 | + |
| 89 | + git.CreateBranch("NewBranch"); |
| 90 | + |
| 91 | + Assert.AreEqual("NewBranch", git.CurrentBranch); |
| 92 | + } |
| 93 | + |
| 94 | + //[TestCleanup] |
| 95 | + //public void ForceDeleteDirectory() |
| 96 | + //{ |
| 97 | + |
| 98 | + |
| 99 | + // string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SourceControlTest"); |
| 100 | + // var directory = new DirectoryInfo(path) { Attributes = FileAttributes.Normal }; |
| 101 | + |
| 102 | + // foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories)) |
| 103 | + // { |
| 104 | + // info.Attributes = FileAttributes.Normal; |
| 105 | + // } |
| 106 | + |
| 107 | + // directory.Delete(true); |
| 108 | + //} |
| 109 | + } |
| 110 | +} |
0 commit comments