public void CanDuckChainNullableDirectlyWithNonNullNullable() { var instance = new GenericTestClass { MyTestStruct = new TestStruct() }; var proxy = instance.DuckCast <GenericProxyStruct>(); }
public void TestReducedNumberOfTypeParameters() { var s = new XmSerializerModel(); s.AddType(typeof(GenericTestClass <, ,>)); var s2 = new XmSerializerModel(); s2.AddType(typeof(GenericTestClass2 <,>)); var s3 = new XmSerializerModel(); s3.AddType(typeof(GenericTestClass3)); var obj = new GenericTestClass <string, int, bool> { Field1 = "foobar", Field2 = 42, Field3 = true }; var xml = s.Serialize(obj); var result = (GenericTestClass2 <string, int>)s2.Deserialize <object>(xml); Assert.AreEqual(result.Field1, obj.Field1); Assert.AreEqual(result.Field2, obj.Field2); Assert.AreEqual(result.Field3, obj.Field3); var result2 = s3.Deserialize <GenericTestClass3>(xml); Assert.AreEqual(result2.Field1, obj.Field1); Assert.AreEqual(result2.Field2, obj.Field2); Assert.AreEqual(result2.Field3, obj.Field3); }
public void ReadToEndGeneric_MultipleLines_ReturnsMultipleObjects() { SetupReader( "myInt;myDouble;myString;myDateTime;myIntProperty;myNullableIntProperty\n1;2.3;some text;2018-01-01 12:34;5;null\n1;2.3;some text;2018-01-01 12:34;5;null" + (char)3 ); var reader = GetReader(CsvFormat.SemicolonSeparatedWithHeaders); var expectedResult = new GenericTestClass { myInt = 1, myDouble = 2.3, myString = "some text", myDateTime = new DateTime(2018, 1, 1, 12, 34, 00), MyIntProperty = 5, MyNullableIntProperty = null }; var result = reader.ReadToEnd <GenericTestClass>(); var count = 0; foreach (var item in result) { count++; Assert.AreEqual(expectedResult, item); } Assert.AreEqual(2, count); }
public void GenericPrependDollarOnGet() { var o = new GenericTestClass <string>(); o.Amount = "100"; o.Amount.ShouldBe("$100"); }
public void TestNestedGeneric() { var s = new XmSerializerModel(); s.AddType(typeof(GenericTestClass <, ,>)); var obj = new GenericTestClass <string, int, bool>(); obj.Field1 = "test"; obj.Field2 = 5; obj.Field3 = true; var obj2 = new GenericTestClass <string, GenericTestClass <string, int, bool>, int> { Field1 = "ff", Field2 = obj, Field3 = 12 }; var result = BasicTest.TestSerialization(obj2, s); Assert.AreEqual(result.Field1, obj2.Field1); Assert.AreEqual(result.Field2.Field1, obj.Field1); Assert.AreEqual(result.Field2.Field2, obj.Field2); Assert.AreEqual(result.Field2.Field3, obj.Field3); Assert.AreEqual(result.Field3, obj2.Field3); }
public void VerifyChangeNotificationOnGenericClassValueType() { var o = new GenericTestClass <int>(); var newValue = 0; o.PropertyChanged += (sender, args) => newValue = o.Property; o.Property = 1; newValue.ShouldBe(1); }
public void VerifyChangeNotificationOnGenericClass() { var o = new GenericTestClass <string>(); var newValue = ""; o.PropertyChanged += (sender, args) => newValue = o.Property; o.Property = "foobar"; newValue.ShouldBe("foobar"); }
public void CanMockGenericMethodInGenericClass() { MockRepository mocks = new MockRepository(); GenericTestClass <string> t = mocks.StrictMock <GenericTestClass <string> >(); Expect.Call(t.GenericMethod <int>("foo")).Return(42); mocks.ReplayAll(); Assert.Equal(42, t.GenericMethod <int>("foo")); mocks.VerifyAll(); }
public void CanMockGenericClass() { MockRepository mocks = new MockRepository(); GenericTestClass <string> t = (GenericTestClass <string>)mocks.StrictMock(typeof(GenericTestClass <string>)); Expect.Call(t.Method("foo")).Return(42); mocks.ReplayAll(); Assert.Equal(42, t.Method("foo")); mocks.VerifyAll(); }
public void CanMockGenericMethodInGenericClass() { GenericTestClass <string> t = MockRepository.Mock <GenericTestClass <string> >(); t.Expect(x => x.GenericMethod <int>("foo")) .Return(42); Assert.Equal(42, t.GenericMethod <int>("foo")); t.VerifyAllExpectations(); }
public void Aspect_On_GenericClass_Initialized() { var t = new GenericTestClass <int>(); t.TestMethod(42); Assert.True(callsBag.Contains("genericClass")); var t2 = new GenericTestClass <int, string>(); t2.TestMethod(42, "a"); Assert.True(callsBag.Contains("genericClass2")); }
public void CanMockGenericMethodInGenericClass() { GenericTestClass <string> t = MockRepository.Mock <GenericTestClass <string> >(); t.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); t.Expect(x => x.GenericMethod <int>("foo")) .Return(42); Assert.Equal(42, t.GenericMethod <int>("foo")); t.VerifyAllExpectations(); }
public virtual void TestMultipleGenerics() //bug 18947 { IUnityContainer container = this.GetContainer(); GenericTestClass <ReflectionTestClass> testClass1 = container.Resolve <GenericTestClass <ReflectionTestClass> >(); GenericTestClass <ReflectionTestClass1> testClass2 = container.Resolve <GenericTestClass <ReflectionTestClass1> >(); GenericTestClass <ReflectionTestClass2> testClass3 = container.Resolve <GenericTestClass <ReflectionTestClass2> >(); Assert.IsNotNull(testClass1); Assert.IsNotNull(testClass2); Assert.IsNotNull(testClass3); }
public void WithGenerics_ShouldThrowWithValidClassName() { // Arrange var sut = new GenericTestClass <TestClass>(); // Pre-Assert // Act Assert.That(() => { Expect(sut).To.Be.An.Instance.Of <AnotherTestClass>(); }, Throws.Exception.InstanceOf <UnmetExpectationException>() .With.Message .EqualTo( "Expected\n<TestingInstanceOfInterfaceOrBaseClass+GenericTestClass<NExpect.Tests.Types.TestingInstanceOfInterfaceOrBaseClass+TestClass>>\nto be an instance of\n<NExpect.Tests.Types.TestingInstanceOfInterfaceOrBaseClass+AnotherTestClass>" )); // Assert }
public void TestGeneric() { var s = new XmSerializerModel(); s.AddType(typeof(GenericTestClass <, ,>)); var obj = new GenericTestClass <string, int, bool> { Field1 = "test", Field2 = 5, Field3 = true }; var result = BasicTest.TestSerialization(obj, s); Assert.AreEqual(result.Field1, obj.Field1); Assert.AreEqual(result.Field2, obj.Field2); Assert.AreEqual(result.Field3, obj.Field3); }
public void NullEventHandlersTest() { // When the aspect works, this shouldn't throw NullReferenceException's. // Make sure it works for multiple instances. Array.ForEach(new[] { new TestClass(), new TestClass() }, test => { test.InvokeActionUnsafe(); test.InvokePrivateUnsafe(); test.InvokeProtectedUnsafe(); test.InvokeStaticUnsafe(); test.InvokeParameterActionUnsafe(); test.InvokeEventHandlerUnsafe(); }); var generic = new GenericTestClass <object>(); generic.InvokeActionUnsafe(); var generic2 = new GenericTestClass <string>(); generic2.InvokeActionUnsafe(); }
public virtual void TestGenerics() //bug 18952 { IUnityContainer container = this.GetContainer(); GenericTestClass <ReflectionTestClass> testClass = container.Resolve <GenericTestClass <ReflectionTestClass> >(); Type interceptedType = testClass.GetType(); Type genericInterceptedType = interceptedType.GetGenericTypeDefinition(); Assert.IsFalse(interceptedType.ContainsGenericParameters); Assert.IsTrue(interceptedType.IsGenericType); Assert.IsFalse(interceptedType.IsGenericTypeDefinition); Assert.IsTrue(genericInterceptedType.ContainsGenericParameters); Assert.IsTrue(genericInterceptedType.IsGenericType); Assert.IsTrue(genericInterceptedType.IsGenericTypeDefinition); //verify class generic arguments Assert.AreEqual(1, interceptedType.GetGenericArguments().Length); Assert.AreEqual(typeof(ReflectionTestClass), interceptedType.GetGenericArguments()[0]); Assert.AreEqual("T", genericInterceptedType.GetGenericArguments()[0].Name); Assert.AreEqual(GenericParameterAttributes.ReferenceTypeConstraint, genericInterceptedType.GetGenericArguments()[0].GenericParameterAttributes); MethodInfo methodInfo; Type[] genericArgs; Type[] constraints; //verify testMethod1 generic arguments this.GetMethodInfo(interceptedType, "TestMethod1", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual("T1", genericArgs[0].Name); Assert.AreEqual(GenericParameterAttributes.None, genericArgs[0].GenericParameterAttributes); //verify testMethod2 generic arguments this.GetMethodInfo(interceptedType, "TestMethod2", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual("T2", genericArgs[0].Name); Assert.AreEqual(GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint, genericArgs[0].GenericParameterAttributes); //verify testMethod3 generic arguments this.GetMethodInfo(interceptedType, "TestMethod3", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual("T3", genericArgs[0].Name); Assert.AreEqual(GenericParameterAttributes.ReferenceTypeConstraint, genericArgs[0].GenericParameterAttributes); //verify testMethod4 generic arguments this.GetMethodInfo(interceptedType, "TestMethod4", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual("T4", genericArgs[0].Name); Assert.AreEqual(GenericParameterAttributes.ReferenceTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint, genericArgs[0].GenericParameterAttributes); //verify testMethod5 generic arguments this.GetMethodInfo(interceptedType, "TestMethod5", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual(1, constraints.Length); Assert.AreEqual("T5", genericArgs[0].Name); Assert.AreEqual(GenericParameterAttributes.None, genericArgs[0].GenericParameterAttributes); Assert.IsTrue(constraints[0].IsClass); Assert.AreEqual(typeof(InjectionPolicy), constraints[0]); //verify testMethod6 generic arguments this.GetMethodInfo(interceptedType, "TestMethod6", out methodInfo, out genericArgs, out constraints); Assert.AreEqual(1, genericArgs.Length); Assert.AreEqual(1, constraints.Length); Assert.AreEqual("T6", genericArgs[0].Name); Assert.IsTrue(constraints[0].IsInterface); Assert.AreEqual(typeof(IMatchingRule), constraints[0]); }
public void CanDuckChainNullableDirectly_WithNullNullable() { var instance = new GenericTestClass(); var proxy = instance.DuckCast <GenericProxyStruct>(); }