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 Subrogation_NoSurrogatesTest() { // Instantiate a dummy object referencing other objects to be potentially // subrogated var dummy = new DummyNoSurrogate(); // 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.Execute(() => { // Verify that neither the Calculator nor the Vehicule object were subrogated // as the fields that reference them do not have the SubrogateAttribute. Assert.AreSame(GetObjectFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreNotSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreSame(GetObjectFromType(typeof(Vehicle)), dummy.Vehicle); Assert.AreNotSame(GetSurrogateFromType(typeof(Vehicle)), dummy.Vehicle); }); }
public void TypesToSubrogate_NoFieldWithSubrogateAttributeTest() { var dummy = new DummyNoSurrogate(); var surrogateScope = new TestableDeepSubrogationScope(dummy, type => null, type => null); // Since none of the fields have the SubrogateAttribute, then nothing must be subrogated. var expectedSet = new HashSet <Type>(); // Property under test Assert.AreEqual(expectedSet, surrogateScope.TypesToSubrogateSet); }
public void SubrogationDisabledTest() { var dummy = new DummySubrogationDisabled(); var surrogateScope = new TestableDeepSubrogationScope(dummy, type => null, type => null); // Since the DummySubrogationDisabled class has the [DeepSubrogate] attribute with the // Enabled flag set to false, then the scope's TypesToSubrogateSet must be empty. var expectedSet = new HashSet <Type>(); // Property under test Assert.AreEqual(expectedSet, surrogateScope.TypesToSubrogateSet); }
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); }
public void TypesToSubrogate_SomeFieldsWithSubrogateAttributeTest() { var dummy = new DummyOneSurrogate(); var surrogateScope = new TestableDeepSubrogationScope(dummy, type => null, type => null); // Since only the _calculator field (ICalculator type), has the SubrogateAttribute then // only the ICalculator type fields must be subrogated. var expectedSet = new HashSet <Type>() { typeof(ICalculator) }; // Property under test Assert.AreEqual(expectedSet, surrogateScope.TypesToSubrogateSet); }
public void Subrogation_DeepReferencesSubrogateAndRestoreTest() { // Instantiate a dummy object referencing other objects to be potentially // subrogated var dummy = new DummyOneSurrogate(); // 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.Execute(() => { // Verify that the Calculator objects was subrogated Assert.AreSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreNotSame(GetObjectFromType(typeof(ICalculator)), dummy.Calculator); // Verify that the Vehicle object was Not subrogated (it does not contain the SubrogateAttribute) Assert.AreSame(GetObjectFromType(typeof(Vehicle)), dummy.Vehicle); // Verify that the Calculator object referenced by the Vehicle object was subrogated Assert.AreSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Vehicle.Calculator); Assert.AreNotSame(GetObjectFromType(typeof(ICalculator)), dummy.Vehicle.Calculator); }); // Verify that the original objects were all restored Assert.AreSame(GetObjectFromType(typeof(ICalculator)), dummy.Calculator); Assert.AreNotSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Calculator); // Verify that the Calculator object referenced by the Vehicle object was restored Assert.AreSame(GetObjectFromType(typeof(ICalculator)), dummy.Vehicle.Calculator); Assert.AreNotSame(GetSurrogateFromType(typeof(ICalculator)), dummy.Vehicle.Calculator); }