public void Subrogation_SimpleSubrogateAndRestoreTest() { // Instantiate a dummy object referencing other objects to be subrogated var dummy = new DummyTwoSurrogates(); // Instantiate a new subrogation scope with the previous dummy object as the // scope's initial object var surrogateScope = new TestableDeepSubrogationScope(dummy, GetSurrogateFromType, GetObjectFromType); // Add the original referenced objects by dummy to be restored later _typeToObjectDictionary.Add(typeof(ICalculator), dummy.Calculator); _typeToObjectDictionary.Add(typeof(Vehicle), dummy.Vehicle); // Method under test surrogateScope.DeepSubrogate(); // Verify that the Calculator and Vehicule objects were subrogated Assert.AreSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreSame(GetSurrogateFromType(typeof(Vehicle)), dummy.Vehicle); Assert.AreNotSame(GetObjectFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreNotSame(GetObjectFromType(typeof(Vehicle)), dummy.Vehicle); // Method under test surrogateScope.DeepRestore(); // Verify that the original objects were all restored Assert.AreNotSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreNotSame(GetSurrogateFromType(typeof(Vehicle)), dummy.Vehicle); Assert.AreSame(GetObjectFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreSame(GetObjectFromType(typeof(Vehicle)), dummy.Vehicle); }
public void TypesToSubrogate_AllFieldsWithSubrogateAttributeTest() { var dummy = new DummyTwoSurrogates(); var surrogateScope = new TestableDeepSubrogationScope(dummy, type => null, type => null); // Since both the _calculator field (ICalculator), and the _vehicle field (Vehicle) // have the SubrogateAttribute then both fields must be subrogated. var expectedSet = new HashSet <Type>() { typeof(ICalculator), typeof(Vehicle) }; // Property under test Assert.AreEqual(expectedSet, surrogateScope.TypesToSubrogateSet); }