Permalink
Browse files

add unit test project

  • Loading branch information...
yysun committed May 29, 2010
1 parent b167871 commit 733d37dbe40af1c2a0df8c516e42df71bae2ae81
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>BasicSccProvider.Tests</RootNamespace>
+ <AssemblyName>BasicSccProvider.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="ICSharpCode.SharpZipLib">
+ <HintPath>..\lib\ICSharpCode.SharpZipLib.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.VisualStudio.Shell.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <EmbedInteropTypes>True</EmbedInteropTypes>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Design" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Tamir.SharpSSH">
+ <HintPath>..\lib\Tamir.SharpSSH.dll</HintPath>
+ </Reference>
+ <Reference Include="Winterdom.IO.FileMap">
+ <HintPath>..\lib\Winterdom.IO.FileMap.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="GitFileStatusTrackerTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\BasicSccProvider.csproj">
+ <Project>{ADECE07A-5D80-4950-9DA5-A681CE2F5106}</Project>
+ <Name>BasicSccProvider</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\GitSharp.Core\GitSharp.Core.csproj">
+ <Project>{C46EDD61-C202-465A-93F1-ADE20A83BB59}</Project>
+ <Name>GitSharp.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\GitSharp\GitSharp.csproj">
+ <Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
+ <Name>GitSharp</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,160 @@
+using System;
+using System.IO;
+using GitScc;
+using GitSharp;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BasicSccProvider.Tests
+{
+
+
+ /// <summary>
+ ///This is a test class for GitFileStatusTrackerTest and is intended
+ ///to contain all GitFileStatusTrackerTest Unit Tests
+ ///</summary>
+ [TestClass()]
+ public class GitFileStatusTrackerTest
+ {
+
+
+ private TestContext testContextInstance;
+
+ /// <summary>
+ ///Gets or sets the test context which provides
+ ///information about and functionality for the current test run.
+ ///</summary>
+ public TestContext TestContext
+ {
+ get
+ {
+ return testContextInstance;
+ }
+ set
+ {
+ testContextInstance = value;
+ }
+ }
+
+ #region Additional test attributes
+ //
+ //You can use the following additional attributes as you write your tests:
+ //
+ //Use ClassInitialize to run code before running the first test in the class
+ //[ClassInitialize()]
+ //public static void MyClassInitialize(TestContext testContext)
+ //{
+ //}
+ //
+ //Use ClassCleanup to run code after all tests in a class have run
+ //[ClassCleanup()]
+ //public static void MyClassCleanup()
+ //{
+ //}
+ //
+ //Use TestInitialize to run code before running each test
+ //[TestInitialize()]
+ //public void MyTestInitialize()
+ //{
+ //}
+ //
+ //Use TestCleanup to run code after each test has run
+ //[TestCleanup()]
+ //public void MyTestCleanup()
+ //{
+ //}
+ //
+ #endregion
+
+
+ /// <summary>
+ ///A test for HasGitRepository
+ ///</summary>
+ [TestMethod()]
+ public void HasGitRepositoryTest()
+ {
+ var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
+
+ GitFileStatusTracker tracker = new GitFileStatusTracker();
+ tracker.Open(tempFolder);
+ Assert.IsFalse(tracker.HasGitRepository);
+
+ Repository.Init(tempFolder);
+
+ tracker.Open(tempFolder);
+ Assert.IsTrue(tracker.HasGitRepository);
+
+ }
+
+ [TestMethod]
+ public void GetFileStatusTest()
+ {
+ var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
+ var tempFile = Path.Combine(tempFolder, "test");
+
+ Repository.Init(tempFolder);
+ GitFileStatusTracker tracker = new GitFileStatusTracker();
+ tracker.Open(tempFolder);
+
+ string[] lines = { "First line", "Second line", "Third line" };
+ File.WriteAllLines(tempFile, lines);
+
+ tracker.Update();
+ Assert.AreEqual(GitFileStatus.UnTrackered, tracker.GetFileStatus(tempFile));
+
+ using (var repo = new Repository(tempFolder))
+ {
+ repo.Index.Add(tempFile);
+
+ tracker.Update();
+ Assert.AreEqual(GitFileStatus.Staged, tracker.GetFileStatus(tempFile));
+
+ repo.Index.CommitChanges("test", new Author("test", "test@test.test"));
+
+ tracker.Update();
+ Assert.AreEqual(GitFileStatus.Trackered, tracker.GetFileStatus(tempFile));
+
+ repo.Close();
+ }
+
+ File.WriteAllText(tempFile, "changed text");
+
+ tracker.Update();
+ Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));
+ }
+
+ [TestMethod]
+ public void GetFileContentTest()
+ {
+ var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_";
+ var tempFile = Path.Combine(tempFolder, "test");
+
+ Repository.Init(tempFolder);
+
+ string[] lines = { "First line", "Second line", "Third line" };
+ File.WriteAllLines(tempFile, lines);
+
+
+ using (var repo = new Repository(tempFolder))
+ {
+ repo.Index.Add(tempFile);
+ repo.Index.CommitChanges("test", new Author("test", "test@test.test"));
+ repo.Close();
+ }
+
+ GitFileStatusTracker tracker = new GitFileStatusTracker();
+ tracker.Open(tempFolder);
+
+ var fileContent = tracker.GetFileContent(tempFile);
+
+ using (var binWriter = new BinaryWriter(File.Open(tempFile + ".bk", FileMode.Create)))
+ {
+ binWriter.Write(fileContent);
+ }
+
+ var newlines = File.ReadAllLines(tempFile + ".bk");
+ Assert.AreEqual(lines[0], newlines[0]);
+ Assert.AreEqual(lines[1], newlines[1]);
+ Assert.AreEqual(lines[2], newlines[2]);
+ }
+ }
+}
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("BasicSccProvider.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("BasicSccProvider.Tests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c6686e46-d8d4-4f1c-8098-4b9d8bbaf537")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
@@ -16,7 +16,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core", "GitSharp.C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp", "GitSharp\GitSharp.csproj", "{7311850F-619A-4241-B09F-157792C75FBA}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicSccProvider.Tests", "BasicSccProvider.Tests\BasicSccProvider.Tests.csproj", "{AE3D1ACA-680D-4CDE-B71E-B7B135F32899}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9B2F3727-28C1-4D1B-951E-BA1AB452DA67}"
+ ProjectSection(SolutionItems) = preProject
+ BasicSccProvider.vsmdi = BasicSccProvider.vsmdi
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ EndProjectSection
+EndProject
Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = BasicSccProvider.vsmdi
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
@@ -34,6 +46,10 @@ Global
{7311850F-619A-4241-B09F-157792C75FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AE3D1ACA-680D-4CDE-B71E-B7B135F32899}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+ <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" />
+ </TestList>
+</TestLists>
View
@@ -76,11 +76,32 @@ public GitFileStatus GetFileStatus(string fileName)
}
}
- internal void Update()
+ public void Update()
{
if (this.repositoryStatus!=null)
this.repositoryStatus.Update();
}
+
+ public byte[] GetFileContent(string fileName)
+ {
+ if (!HasGitRepository || string.IsNullOrEmpty(fileName))
+ return null;
+
+ fileName = workingFolderUri.MakeRelativeUri(new Uri(fileName)).ToString();
+
+ Leaf leaf = null;
+
+ if (this.repositoryStatus != null &&
+ this.repositoryStatus.Repository != null &&
+ this.repositoryStatus.Repository.Head != null &&
+ this.repositoryStatus.Repository.Head.CurrentCommit != null &&
+ this.repositoryStatus.Repository.Head.CurrentCommit.Tree != null)
+ {
+ leaf = this.repositoryStatus.Repository.Head.CurrentCommit.Tree[fileName] as Leaf;
+ }
+
+ return leaf == null ? null : leaf.RawData;
+ }
}
public static class HashSetExt
View
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="Local" id="26b9a90c-6bd7-4fde-b33a-84e4da47125b" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are default test settings for a local test run.</Description>
+ <Deployment enabled="false" />
+ <Execution>
+ <TestTypeSpecific />
+ <AgentRule name="Execution Agents">
+ </AgentRule>
+ </Execution>
+</TestSettings>
View
@@ -15,9 +15,10 @@ Features
How to use
----------
-* Download and install Git and [Git Source Control Provider]:http://gitscc.codeplex.com/releases
-* Open Visual Studio and go to Tools -> Options.
-* Select Source Control in the tree view
+* Run Visual Studio.
+* Go to Tools | Extension Manager, search online gallary for Git Source Control Provider and install.
+* Go to Tools | Options.
+* Select Source Control in the tree view.
* Select Git Source Control Provider from the drop down list, and click OK.
* Open your solution controlled by Git to see the file's status.
@@ -27,4 +28,4 @@ If the file status is out of sync, right click solution explorer items and selec
What's coming
-----------------
-[Project Roadmap]:http://gitscc.codeplex.com/wikipage?title=Project%20Roadmap&referringTitle=Home
+[Project Roadmap](http://gitscc.codeplex.com/wikipage?title=Project%20Roadmap)
Oops, something went wrong.

0 comments on commit 733d37d

Please sign in to comment.