Permalink
Browse files

Move TfsApiBridge to the core project.

This will let me drop one of the test projects without dropping any tests.
  • Loading branch information...
1 parent ff364f8 commit f38e84db766cb78d2b684c97c632ff00f7bd94bb @spraints spraints committed Aug 31, 2012
@@ -62,9 +62,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="..\GitTfs.VsCommon\TfsApiBridge.cs">
- <Link>TfsApiBridge.cs</Link>
- </Compile>
<Compile Include="..\GitTfs.VsCommon\TfsHelper.Common.cs">
<Link>TfsHelper.Common.cs</Link>
</Compile>
@@ -110,9 +110,6 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
- <Compile Include="..\GitTfs.VsCommon\TfsApiBridge.cs">
- <Link>TfsApiBridge.cs</Link>
- </Compile>
<Compile Include="..\GitTfs.VsCommon\TfsHelper.Common.cs">
<Link>TfsHelper.Common.cs</Link>
</Compile>
@@ -97,9 +97,6 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
- <Compile Include="..\GitTfs.VsCommon\TfsApiBridge.cs">
- <Link>TfsApiBridge.cs</Link>
- </Compile>
<Compile Include="..\GitTfs.VsCommon\TfsHelper.Common.cs">
<Link>TfsHelper.Common.cs</Link>
</Compile>
View
@@ -146,6 +146,7 @@
<Compile Include="Core\TfsInterop\ICheckinNote.cs" />
<Compile Include="Core\TfsInterop\IVersionControlServer.cs" />
<Compile Include="Core\TfsInterop\IWorkItemCheckedInfo.cs" />
+ <Compile Include="Core\TfsInterop\TfsApiBridge.cs" />
<Compile Include="Core\TfsInterop\TfsChangeType.cs" />
<Compile Include="Core\TfsInterop\TfsCheckinEvaluationOptions.cs" />
<Compile Include="Core\TfsInterop\TfsExt.cs" />
@@ -0,0 +1,128 @@
+using Sep.Git.Tfs.Core.TfsInterop;
+using Sep.Git.Tfs.VsCommon;
+using StructureMap.AutoMocking;
+using Xunit;
+
+namespace GitTfsTest.Core
+{
+ public class TfsApiBridgeTest
+ {
+ private RhinoAutoMocker<TfsApiBridge> _mocks;
+
+ public TfsApiBridgeTest()
+ {
+ _mocks = new RhinoAutoMocker<TfsApiBridge>();
+ _mocks.MockObjectFactory();
+ }
+
+ [Fact]
+ public void ConvertsEnum()
+ {
+ Assert.Equal(OriginalEnum.Value2, _mocks.ClassUnderTest.Convert<OriginalEnum>(WrappedEnum.Value2));
+ }
+
+ [Fact]
+ public void WrapsAndUnwrapsObject()
+ {
+ var originalObject = new OriginalType();
+ var wrappedObject = _mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(originalObject);
+ Assert.Equal(originalObject, _mocks.ClassUnderTest.Unwrap<OriginalType>(wrappedObject));
+ }
+
+ [Fact]
+ public void WrapsObjectWithBridge()
+ {
+ var originalObject = new OriginalType();
+ var wrappedObject = _mocks.ClassUnderTest.Wrap<WrapperForOriginalTypeWithBridge, OriginalType>(originalObject);
+ Assert.NotNull(wrappedObject.Bridge);
+ }
+
+ [Fact]
+ public void WrapsAndUnwrapsArray()
+ {
+ var originalObjects = new [] { new OriginalType() };
+ var wrappedObjects = _mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(originalObjects);
+ Assert.Equal(1, wrappedObjects.Length);
+ Assert.Equal(originalObjects[0], _mocks.ClassUnderTest.Unwrap<OriginalType>(wrappedObjects)[0]);
+ }
+
+ [Fact]
+ public void WrapsNullAsNull()
+ {
+ OriginalType obj = null;
+ Assert.Null(_mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(obj));
+ }
+
+ [Fact]
+ public void WrapsNullArrayAsNull()
+ {
+ OriginalType [] obj = null;
+ Assert.Null(_mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(obj));
+ }
+
+ [Fact]
+ public void UnwrapsNullAsNull()
+ {
+ WrapperForOriginalType obj = null;
+ Assert.Null(_mocks.ClassUnderTest.Unwrap<OriginalType>(obj));
+ }
+
+ [Fact]
+ public void UnwrapsNullArrayAsNull()
+ {
+ WrapperForOriginalType[] obj = null;
+ Assert.Null(_mocks.ClassUnderTest.Unwrap<OriginalType>(obj));
+ }
+
+ public class OriginalType
+ {
+ public static int counter;
+ public static object lockObject = new object();
+ private readonly int _id;
+ public OriginalType()
+ {
+ lock (lockObject)
+ {
+ _id = ++counter;
+ }
+ }
+ public override bool Equals(object obj)
+ {
+ return obj is OriginalType && ((OriginalType) obj)._id == _id;
+ }
+ public override int GetHashCode()
+ {
+ return _id;
+ }
+ public override string ToString()
+ {
+ return "OriginalObject:" + _id;
+ }
+ }
+ interface IOriginalType {}
+ public class WrapperForOriginalType : WrapperFor<OriginalType>, IOriginalType
+ {
+ public WrapperForOriginalType(OriginalType o) : base(o) {}
+ }
+ public class WrapperForOriginalTypeWithBridge : WrapperFor<OriginalType>, IOriginalType
+ {
+ public WrapperForOriginalTypeWithBridge(OriginalType o, TfsApiBridge b) : base(o)
+ {
+ Bridge = b;
+ }
+ public TfsApiBridge Bridge { get; private set; }
+ }
+
+ public enum OriginalEnum
+ {
+ Value1,
+ Value2,
+ };
+
+ public enum WrappedEnum
+ {
+ Value1,
+ Value2,
+ };
+ }
+}
@@ -92,6 +92,7 @@
<Compile Include="Core\ExtTests.cs" />
<Compile Include="Core\GitChangeInfoTests.cs" />
<Compile Include="Core\ModeTests.cs" />
+ <Compile Include="Core\TfsApiBridgeTest.cs" />
<Compile Include="GitTfsRegexTests.cs" />
<Compile Include="Integration\CloneTests.cs" />
<Compile Include="Integration\IntegrationHelper.cs" />

0 comments on commit f38e84d

Please sign in to comment.