Skip to content

Commit 733d37d

Browse files
committed
add unit test project
1 parent b167871 commit 733d37d

10 files changed

+400
-5
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>
7+
</ProductVersion>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>BasicSccProvider.Tests</RootNamespace>
13+
<AssemblyName>BasicSccProvider.Tests</AssemblyName>
14+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="ICSharpCode.SharpZipLib">
37+
<HintPath>..\lib\ICSharpCode.SharpZipLib.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
40+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
41+
<Reference Include="Microsoft.VisualStudio.Shell.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
42+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
43+
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
44+
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
45+
<EmbedInteropTypes>True</EmbedInteropTypes>
46+
</Reference>
47+
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
48+
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
49+
<Reference Include="System" />
50+
<Reference Include="System.Core">
51+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
52+
</Reference>
53+
<Reference Include="System.Data" />
54+
<Reference Include="System.Design" />
55+
<Reference Include="System.Drawing" />
56+
<Reference Include="System.Windows.Forms" />
57+
<Reference Include="System.Xml" />
58+
<Reference Include="Tamir.SharpSSH">
59+
<HintPath>..\lib\Tamir.SharpSSH.dll</HintPath>
60+
</Reference>
61+
<Reference Include="Winterdom.IO.FileMap">
62+
<HintPath>..\lib\Winterdom.IO.FileMap.dll</HintPath>
63+
</Reference>
64+
</ItemGroup>
65+
<ItemGroup>
66+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
67+
<Visible>False</Visible>
68+
</CodeAnalysisDependentAssemblyPaths>
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="GitFileStatusTrackerTest.cs" />
72+
<Compile Include="Properties\AssemblyInfo.cs" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<ProjectReference Include="..\BasicSccProvider.csproj">
76+
<Project>{ADECE07A-5D80-4950-9DA5-A681CE2F5106}</Project>
77+
<Name>BasicSccProvider</Name>
78+
</ProjectReference>
79+
<ProjectReference Include="..\GitSharp.Core\GitSharp.Core.csproj">
80+
<Project>{C46EDD61-C202-465A-93F1-ADE20A83BB59}</Project>
81+
<Name>GitSharp.Core</Name>
82+
</ProjectReference>
83+
<ProjectReference Include="..\GitSharp\GitSharp.csproj">
84+
<Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
85+
<Name>GitSharp</Name>
86+
</ProjectReference>
87+
</ItemGroup>
88+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
89+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
90+
Other similar extension points exist, see Microsoft.Common.targets.
91+
<Target Name="BeforeBuild">
92+
</Target>
93+
<Target Name="AfterBuild">
94+
</Target>
95+
-->
96+
</Project>
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
using System;
2+
using System.IO;
3+
using GitScc;
4+
using GitSharp;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
namespace BasicSccProvider.Tests
8+
{
9+
10+
11+
/// <summary>
12+
///This is a test class for GitFileStatusTrackerTest and is intended
13+
///to contain all GitFileStatusTrackerTest Unit Tests
14+
///</summary>
15+
[TestClass()]
16+
public class GitFileStatusTrackerTest
17+
{
18+
19+
20+
private TestContext testContextInstance;
21+
22+
/// <summary>
23+
///Gets or sets the test context which provides
24+
///information about and functionality for the current test run.
25+
///</summary>
26+
public TestContext TestContext
27+
{
28+
get
29+
{
30+
return testContextInstance;
31+
}
32+
set
33+
{
34+
testContextInstance = value;
35+
}
36+
}
37+
38+
#region Additional test attributes
39+
//
40+
//You can use the following additional attributes as you write your tests:
41+
//
42+
//Use ClassInitialize to run code before running the first test in the class
43+
//[ClassInitialize()]
44+
//public static void MyClassInitialize(TestContext testContext)
45+
//{
46+
//}
47+
//
48+
//Use ClassCleanup to run code after all tests in a class have run
49+
//[ClassCleanup()]
50+
//public static void MyClassCleanup()
51+
//{
52+
//}
53+
//
54+
//Use TestInitialize to run code before running each test
55+
//[TestInitialize()]
56+
//public void MyTestInitialize()
57+
//{
58+
//}
59+
//
60+
//Use TestCleanup to run code after each test has run
61+
//[TestCleanup()]
62+
//public void MyTestCleanup()
63+
//{
64+
//}
65+
//
66+
#endregion
67+
68+
69+
/// <summary>
70+
///A test for HasGitRepository
71+
///</summary>
72+
[TestMethod()]
73+
public void HasGitRepositoryTest()
74+
{
75+
var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
76+
77+
GitFileStatusTracker tracker = new GitFileStatusTracker();
78+
tracker.Open(tempFolder);
79+
Assert.IsFalse(tracker.HasGitRepository);
80+
81+
Repository.Init(tempFolder);
82+
83+
tracker.Open(tempFolder);
84+
Assert.IsTrue(tracker.HasGitRepository);
85+
86+
}
87+
88+
[TestMethod]
89+
public void GetFileStatusTest()
90+
{
91+
var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
92+
var tempFile = Path.Combine(tempFolder, "test");
93+
94+
Repository.Init(tempFolder);
95+
GitFileStatusTracker tracker = new GitFileStatusTracker();
96+
tracker.Open(tempFolder);
97+
98+
string[] lines = { "First line", "Second line", "Third line" };
99+
File.WriteAllLines(tempFile, lines);
100+
101+
tracker.Update();
102+
Assert.AreEqual(GitFileStatus.UnTrackered, tracker.GetFileStatus(tempFile));
103+
104+
using (var repo = new Repository(tempFolder))
105+
{
106+
repo.Index.Add(tempFile);
107+
108+
tracker.Update();
109+
Assert.AreEqual(GitFileStatus.Staged, tracker.GetFileStatus(tempFile));
110+
111+
repo.Index.CommitChanges("test", new Author("test", "[email protected]"));
112+
113+
tracker.Update();
114+
Assert.AreEqual(GitFileStatus.Trackered, tracker.GetFileStatus(tempFile));
115+
116+
repo.Close();
117+
}
118+
119+
File.WriteAllText(tempFile, "changed text");
120+
121+
tracker.Update();
122+
Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));
123+
}
124+
125+
[TestMethod]
126+
public void GetFileContentTest()
127+
{
128+
var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
129+
var tempFile = Path.Combine(tempFolder, "test");
130+
131+
Repository.Init(tempFolder);
132+
133+
string[] lines = { "First line", "Second line", "Third line" };
134+
File.WriteAllLines(tempFile, lines);
135+
136+
137+
using (var repo = new Repository(tempFolder))
138+
{
139+
repo.Index.Add(tempFile);
140+
repo.Index.CommitChanges("test", new Author("test", "[email protected]"));
141+
repo.Close();
142+
}
143+
144+
GitFileStatusTracker tracker = new GitFileStatusTracker();
145+
tracker.Open(tempFolder);
146+
147+
var fileContent = tracker.GetFileContent(tempFile);
148+
149+
using (var binWriter = new BinaryWriter(File.Open(tempFile + ".bk", FileMode.Create)))
150+
{
151+
binWriter.Write(fileContent);
152+
}
153+
154+
var newlines = File.ReadAllLines(tempFile + ".bk");
155+
Assert.AreEqual(lines[0], newlines[0]);
156+
Assert.AreEqual(lines[1], newlines[1]);
157+
Assert.AreEqual(lines[2], newlines[2]);
158+
}
159+
}
160+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BasicSccProvider.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("BasicSccProvider.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c6686e46-d8d4-4f1c-8098-4b9d8bbaf537")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

BasicSccProvider.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core", "GitSharp.C
1616
EndProject
1717
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp", "GitSharp\GitSharp.csproj", "{7311850F-619A-4241-B09F-157792C75FBA}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicSccProvider.Tests", "BasicSccProvider.Tests\BasicSccProvider.Tests.csproj", "{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}"
20+
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9B2F3727-28C1-4D1B-951E-BA1AB452DA67}"
22+
ProjectSection(SolutionItems) = preProject
23+
BasicSccProvider.vsmdi = BasicSccProvider.vsmdi
24+
Local.testsettings = Local.testsettings
25+
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
26+
EndProjectSection
27+
EndProject
1928
Global
29+
GlobalSection(TestCaseManagementSettings) = postSolution
30+
CategoryFile = BasicSccProvider.vsmdi
31+
EndGlobalSection
2032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2133
Debug|Any CPU = Debug|Any CPU
2234
Release|Any CPU = Release|Any CPU
@@ -34,6 +46,10 @@ Global
3446
{7311850F-619A-4241-B09F-157792C75FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
3547
{7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
3648
{7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Release|Any CPU.Build.0 = Release|Any CPU
3753
EndGlobalSection
3854
GlobalSection(SolutionProperties) = preSolution
3955
HideSolutionNode = FALSE

BasicSccProvider.vsmdi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
4+
<RunConfiguration id="26b9a90c-6bd7-4fde-b33a-84e4da47125b" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
5+
</TestList>
6+
</TestLists>

GitFileStatusTracker.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,32 @@ public GitFileStatus GetFileStatus(string fileName)
7676
}
7777
}
7878

79-
internal void Update()
79+
public void Update()
8080
{
8181
if (this.repositoryStatus!=null)
8282
this.repositoryStatus.Update();
8383
}
84+
85+
public byte[] GetFileContent(string fileName)
86+
{
87+
if (!HasGitRepository || string.IsNullOrEmpty(fileName))
88+
return null;
89+
90+
fileName = workingFolderUri.MakeRelativeUri(new Uri(fileName)).ToString();
91+
92+
Leaf leaf = null;
93+
94+
if (this.repositoryStatus != null &&
95+
this.repositoryStatus.Repository != null &&
96+
this.repositoryStatus.Repository.Head != null &&
97+
this.repositoryStatus.Repository.Head.CurrentCommit != null &&
98+
this.repositoryStatus.Repository.Head.CurrentCommit.Tree != null)
99+
{
100+
leaf = this.repositoryStatus.Repository.Head.CurrentCommit.Tree[fileName] as Leaf;
101+
}
102+
103+
return leaf == null ? null : leaf.RawData;
104+
}
84105
}
85106

86107
public static class HashSetExt

Local.testsettings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestSettings name="Local" id="26b9a90c-6bd7-4fde-b33a-84e4da47125b" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<Description>These are default test settings for a local test run.</Description>
4+
<Deployment enabled="false" />
5+
<Execution>
6+
<TestTypeSpecific />
7+
<AgentRule name="Execution Agents">
8+
</AgentRule>
9+
</Execution>
10+
</TestSettings>

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ Features
1515

1616
How to use
1717
----------
18-
* Download and install Git and [Git Source Control Provider]:http://gitscc.codeplex.com/releases
19-
* Open Visual Studio and go to Tools -> Options.
20-
* Select Source Control in the tree view
18+
* Run Visual Studio.
19+
* Go to Tools | Extension Manager, search online gallary for Git Source Control Provider and install.
20+
* Go to Tools | Options.
21+
* Select Source Control in the tree view.
2122
* Select Git Source Control Provider from the drop down list, and click OK.
2223
* Open your solution controlled by Git to see the file's status.
2324

@@ -27,4 +28,4 @@ If the file status is out of sync, right click solution explorer items and selec
2728

2829
What's coming
2930
-----------------
30-
[Project Roadmap]:http://gitscc.codeplex.com/wikipage?title=Project%20Roadmap&referringTitle=Home
31+
[Project Roadmap](http://gitscc.codeplex.com/wikipage?title=Project%20Roadmap)

0 commit comments

Comments
 (0)