Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 125 lines (113 sloc) 4.321 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sep.Git.Tfs.Core.TfsInterop;
using Sep.Git.Tfs.VsCommon;
using StructureMap.AutoMocking;

namespace GitTfsTest.Vs2010
{
[TestClass]
    public class TfsApiBridgeTest
    {
        private RhinoAutoMocker<TfsApiBridge> _mocks;

[TestInitialize]
        public void Setup()
        {
            _mocks = new RhinoAutoMocker<TfsApiBridge>();
            _mocks.MockObjectFactory();
        }

[TestMethod]
        public void ConvertsEnumToTfsEnum()
        {
            Assert.AreEqual(ItemType.Folder, _mocks.ClassUnderTest.Convert<ItemType>(TfsItemType.Folder));
        }

[TestMethod]
        public void ConvertsTfsEnumToEnum()
        {
            Assert.AreEqual(TfsItemType.Folder, _mocks.ClassUnderTest.Convert<TfsItemType>(ItemType.Folder));
        }

[TestMethod]
        public void WrapsAndUnwrapsObject()
        {
            var originalObject = new OriginalType();
            var wrappedObject = _mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(originalObject);
            Assert.AreEqual(originalObject, _mocks.ClassUnderTest.Unwrap<OriginalType>(wrappedObject), "unwrap(wrap(object))");
        }

[TestMethod]
        public void WrapsObjectWithBridge()
        {
            var originalObject = new OriginalType();
            var wrappedObject = _mocks.ClassUnderTest.Wrap<WrapperForOriginalTypeWithBridge, OriginalType>(originalObject);
            Assert.IsNotNull(wrappedObject.Bridge, "wrappedObject.Bridge");
        }

[TestMethod]
        public void WrapsAndUnwrapsArray()
        {
            var originalObjects = new [] { new OriginalType() };
            var wrappedObjects = _mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(originalObjects);
            Assert.AreEqual(1, wrappedObjects.Length, "wrappedObject.Length");
            Assert.AreEqual(originalObjects[0], _mocks.ClassUnderTest.Unwrap<OriginalType>(wrappedObjects)[0], "unwrap(wrap(objects))[0]");
        }

[TestMethod]
        public void WrapsNullAsNull()
        {
            OriginalType obj = null;
            Assert.IsNull(_mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(obj), "wrap(null)");
        }

[TestMethod]
        public void WrapsNullArrayAsNull()
        {
            OriginalType [] obj = null;
            Assert.IsNull(_mocks.ClassUnderTest.Wrap<WrapperForOriginalType, OriginalType>(obj), "wrap(null[])");
        }

[TestMethod]
        public void UnwrapsNullAsNull()
        {
            WrapperForOriginalType obj = null;
            Assert.IsNull(_mocks.ClassUnderTest.Unwrap<OriginalType>(obj), "unwrap(null)");
        }

[TestMethod]
        public void UnwrapsNullArrayAsNull()
        {
            WrapperForOriginalType[] obj = null;
            Assert.IsNull(_mocks.ClassUnderTest.Unwrap<OriginalType>(obj), "unwrap(null[])");
        }

        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; }
        }
    }
}
Something went wrong with that request. Please try again.