|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | +using System; |
| 3 | +using Unity.Extension; |
| 4 | + |
| 5 | +namespace Unity.Tests.v5 |
| 6 | +{ |
| 7 | + [TestClass] |
| 8 | + public class LegacyExtensionFixture |
| 9 | + { |
| 10 | + [TestMethod] |
| 11 | + public void Register() |
| 12 | + { |
| 13 | + // Setup |
| 14 | + var container = new UnityContainer(); |
| 15 | + container.AddNewExtension<Legacy>(); |
| 16 | + |
| 17 | + // Act |
| 18 | + var config = container.Configure<Legacy>(); |
| 19 | + |
| 20 | + // Validate |
| 21 | + Assert.IsNotNull(config); |
| 22 | + } |
| 23 | + |
| 24 | + [TestMethod] |
| 25 | + public void SmartByDefault() |
| 26 | + { |
| 27 | + // Setup |
| 28 | + var container = new UnityContainer(); |
| 29 | + |
| 30 | + // Act |
| 31 | + var result = container.Resolve<ObjectWithMultipleConstructors>(); |
| 32 | + |
| 33 | + // Validate |
| 34 | + Assert.IsNotNull(result); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + [ExpectedException(typeof(ResolutionFailedException))] |
| 39 | + public void LegacySelection() |
| 40 | + { |
| 41 | + // Setup |
| 42 | + var container = new UnityContainer(); |
| 43 | + container.AddNewExtension<Legacy>(); |
| 44 | + |
| 45 | + // Act |
| 46 | + container.Resolve<ObjectWithMultipleConstructors>(); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + #region Test Data |
| 51 | + |
| 52 | + public class ObjectWithMultipleConstructors |
| 53 | + { |
| 54 | + public const string One = "1"; |
| 55 | + public const string Two = "2"; |
| 56 | + public const string Three = "3"; |
| 57 | + public const string Four = "4"; |
| 58 | + public const string Five = "5"; |
| 59 | + |
| 60 | + public string Signature { get; } |
| 61 | + |
| 62 | + public ObjectWithMultipleConstructors(int first) |
| 63 | + { |
| 64 | + Signature = One; |
| 65 | + } |
| 66 | + |
| 67 | + public ObjectWithMultipleConstructors(object first, IUnityContainer second) |
| 68 | + { |
| 69 | + Signature = Two; |
| 70 | + } |
| 71 | + |
| 72 | + public ObjectWithMultipleConstructors(object first, string second, IUnityContainer third) |
| 73 | + { |
| 74 | + Signature = Three; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + #endregion |
| 79 | +} |
0 commit comments