public void InterceptTestHelper() { // Arrange string methodname = "IntOverloaded"; Type[] argumentTypes = new Type[] { typeof(string) }; IInterfaceMap interfaceMap = CreateIInterfaceMap(); MatchingInterceptor <TestClass> target = new MatchingInterceptor <TestClass>(interfaceMap); Mock <IInvocation> mock = new Mock <IInvocation>(); mock.SetupAllProperties(); mock.Setup(mocked => mocked.Arguments) .Returns(new object[] { "parameter" }); mock.Setup(mocked => mocked.Method) .Returns(typeof(TestClass) .GetMethod(methodname, argumentTypes)); IInvocation invocation = mock.Object; // Act target.Intercept(invocation); // Assert Verify.That(invocation.ReturnValue).IsEqualTo(TestClass.IntOverloadedStringReturn) .Now(); }
public void CanGetMappedMethodTestWithWithouhtGenericArguments() { // Arrange Type[] argTypes = new Type[] { typeof(double) }; IInterfaceMap target = CreateIInterfaceMap(); target.Subject = new TestClass(); const string name = "IntOverloaded"; MappedMethod actual; // Act actual = target.GetMappedMethod <TestClass>(name, argTypes); int result = (int)actual(1D); // Assert Verify.That(result).IsEqualTo(TestClass.IntOverloadedDoubleReturn).Now(); }
public void CanRemoveNonContained() { // Arrange IInterfaceMap target = CreateIInterfaceMap(); IMethodMapping mapping = CreateIMethodMapping(); mapping.Name = "test"; mapping.GenericArgumentTypes = Type.EmptyTypes; mapping.ArgumentTypes = Type.EmptyTypes; bool actual; // Act actual = target.Remove(mapping); // Assert Verify.That(actual).IsFalse() .Now(); }
public void CanGetMappedMethodTestWithReturnType() { // Arrange IInterfaceMap target = CreateIInterfaceMap(); target.Subject = new TestClass(); string name = "IntOverloaded"; Type[] argTypes = new Type[] { typeof(double) }; Type[] genericArgs = Type.EmptyTypes; MappedMethod <int> actual; // Act actual = target.GetMappedMethod <int, TestClass>(name, argTypes, genericArgs); // Assert Verify.That(actual(1.0)).IsEqualTo(TestClass.IntOverloadedDoubleReturn) .Now(); }
public void CanGetMappedMethodTestWithoutReturnType() { // Arrange Type[] argTypes = new Type[] { typeof(float) }; Type[] genericArgs = new Type[] { typeof(float) }; IInterfaceMap target = CreateIInterfaceMap(); target.Subject = new TestClass(); const string name = "IntOverloaded"; MappedMethod actual; // Act actual = target.GetMappedMethod <TestClass>(name, argTypes, genericArgs); // Assert int result = (int)actual(1F); Verify.That(result).IsEqualTo(TestClass.IntOverloadedGenericReturn).Now(); }
public void CanAddWithReplaceSetToFalse() { // Arrange IInterfaceMap target = CreateIInterfaceMap(); IMethodMapping mapping = CreateIMethodMapping(); mapping.Name = "test"; mapping.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) }; mapping.ArgumentTypes = new Type[] { typeof(bool) }; mapping.Subject = (arg, args) => { Console.Out.WriteLine("Subject called"); return(true); }; bool replace = false; // Act target.Add(mapping, replace); // Assert Verify.That(target.AsEnumerable()).DoesContain(mapping) .Now(); }
public void CanReplaceAMethodMapping() { // Arrange IInterfaceMap target = CreateIInterfaceMap(); IMethodMapping mapping = CreateIMethodMapping(); mapping.Name = "test"; mapping.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) }; mapping.ArgumentTypes = new Type[] { typeof(bool) }; mapping.Subject = (arg, args) => { Console.Out.WriteLine("Subject called"); return(true); }; IMethodMapping replacement = CreateIMethodMapping(); replacement.Name = "test"; replacement.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) }; replacement.ArgumentTypes = new Type[] { typeof(bool) }; replacement.Subject = (arg, args) => { Console.Out.WriteLine("Subject replacement called"); return(true); }; // Act target.Add(mapping, false); target.Add(replacement, true); // Assert Verify.That(target.AsEnumerable()).DoesContain(replacement, "Should contain the replacement") .Now(); Verify.That(target.AsEnumerable()).DoesNotContain(mapping, "Should not contain the original mapping") .Now(); }
/// <summary> /// Initializes a new instance of the <see cref="MatchingInterceptor<T>"/> class. /// </summary> /// <param name="proxy">The proxy.</param> public MatchingInterceptor(IInterfaceMap interfaceMap) { Contract.Requires(interfaceMap != null); Contract.Ensures(this.interfaceMap == interfaceMap); this.interfaceMap = interfaceMap; }