Beispiel #1
0
    public void WithOnChangedAbstract()
    {
        var instance = assembly.GetInstance("ClassWithOnChangedConcrete");

        Assert.IsFalse(instance.OnProperty1ChangedCalled);
        EventTester.TestProperty(instance, false);
        Assert.IsTrue(instance.OnProperty1ChangedCalled);
    }
Beispiel #2
0
    public void WithDoNotSetChanged()
    {
        var instance = assembly.GetInstance("ClassWithDoNotSetChanged");

        Assert.IsFalse(instance.IsChanged);
        EventTester.TestProperty(instance, false);
        Assert.IsFalse(instance.IsChanged);
    }
Beispiel #3
0
    public void Nested()
    {
        var instance1 = assembly.GetInstance("ClassWithNested+ClassNested");

        EventTester.TestProperty(instance1, false);
        var instance2 = assembly.GetInstance("ClassWithNested+ClassNested+ClassNestedNested");

        EventTester.TestProperty(instance2, false);
    }
Beispiel #4
0
    public void CaliburnOverriddenInvoker()
    {
        var instance = assembly.GetInstance("ClassCaliburnOverriddenInvoker");

        EventTester.TestProperty(instance, false);

        Assert.IsTrue(instance.BaseNotifyCalled);
        Assert.IsTrue(instance.OverrideCalled);
    }
Beispiel #5
0
    public virtual void Nested()
    {
        var instance1 = testResult.GetInstance("ClassWithNested+ClassNested");

        EventTester.TestProperty(instance1, false);
        var instance2 = testResult.GetInstance("ClassWithNested+ClassNested+ClassNestedNested");

        EventTester.TestProperty(instance2, false);
    }
Beispiel #6
0
    public void TestClassIsNotBlocked()
    {
        var weavingTask = new ModuleWeaver();
        var testResult  = weavingTask.ExecuteTestRun(
            "AssemblyWithBlockingClass.dll",
            ignoreCodes: new[] { "0x80131869" });
        var instance = testResult.GetInstance("B");

        EventTester.TestProperty(instance, false);
    }
    public void StaticEquals_Hierarchy()
    {
        Weave(true);
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.Hierarchy.ChildClass");

        EventTester.TestProperty(instance, true);
        Assert.NotNull(instance.Property2);
        Assert.True(instance.Property2.StaticEqualsCalled);
        instance.Property2.StaticEqualsCalled = false;
    }
    public void GenericBase_MultipleBaseClasses_GenericArgsMapping_BaseHasMoreArgs()
    {
        Weave(true);
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.StaticEqualsGenericParent.ArgsMapping2");

        EventTester.TestProperty(instance, true);
        Assert.NotNull(instance.Property2);
        Assert.True(instance.Property2.StaticEqualsCalled);
        instance.Property2.StaticEqualsCalled = false;
    }
    public void GenericBase_StaticEquals_BaseNotUsed()
    {
        Weave(false);
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.StaticEqualsGenericParent.StaticEqualsOnBase");

        EventTester.TestProperty(instance, true);
        Assert.NotNull(instance.Property2);
        Assert.False(instance.Property2.StaticEqualsCalled);
        instance.Property2.StaticEqualsCalled = false;
    }
    public void GenericBase_OwnStaticEquals()
    {
        Weave(true);
        var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.StaticEqualsGenericParent.OwnStaticEquals");

        EventTester.TestProperty(instance, true);
        Assert.NotNull(instance.Property2);
        Assert.True(instance.Property2.ChildStaticEqualsCalled);
        Assert.False(instance.Property2.StaticEqualsCalled);
        instance.Property2.ChildStaticEqualsCalled = false;
    }
    public void DoNotCheckEquality()
    {
        var instance = assembly.GetInstance("ClassDoNotCheckEquality");

        EventTester.TestProperty(instance, "Property1", "aString");
        instance.Property1 = "aString";
        Assert.AreEqual(1, instance.TimesProperty1Changed);

        EventTester.TestProperty(instance, "Property2", "aString", true);
        instance.Property2 = "aString";
        Assert.AreEqual(2, instance.TimesProperty2Changed);
    }
Beispiel #12
0
    public void CheckIfFilterTypeExcludeRightTypes()
    {
        var weaverHelper = new WeaverHelper(@"AssemblyWithTypeFilter\AssemblyWithTypeFilter.csproj");

        var assembly = weaverHelper.Assembly;
        var instance = assembly.GetInstance("TestClassExclude");

        EventTester.TestPropertyNotCalled(instance);
        instance = assembly.GetInstance("PropertyChangedTest.TestClassInclude");
        EventTester.TestProperty(instance, false);
        Verifier.Verify(weaverHelper.BeforeAssemblyPath, weaverHelper.AfterAssemblyPath);
    }
Beispiel #13
0
    public void Equality()
    {
        var instance = assembly.GetInstance("ClassEquality");

        EventTester.TestProperty(instance, "StringProperty", "foo");
        EventTester.TestProperty(instance, "IntProperty", 2);
        EventTester.TestProperty(instance, "NullableIntProperty", 2);
        EventTester.TestProperty(instance, "BoolProperty", true);
        EventTester.TestProperty(instance, "NullableBoolProperty", true);
        EventTester.TestProperty(instance, "ObjectProperty", "foo");
        EventTester.TestProperty(instance, "ArrayProperty", new[] { "foo" });
    }
    public void DoNotCheckEqualityAppliesToWholeClassInherited()
    {
        var     propertyValue = "aString";
        dynamic instance      = assembly.GetInstance("ClassDoNotCheckEqualityWholeClassInherited");

        EventTester.TestProperty(instance, "Property1", propertyValue, true);
        instance.Property1 = propertyValue;
        Assert.AreEqual(2, instance.TimesProperty1Changed);

        EventTester.TestProperty(instance, "Property2", propertyValue, true);
        instance.Property2 = propertyValue;
        Assert.AreEqual(2, instance.TimesProperty2Changed);
    }
    public void BeforeAfter()
    {
        var weaverHelper = new WeaverHelper(@"AssemblyWithBeforeAfterInterceptor\AssemblyWithBeforeAfterInterceptor.csproj", true);
        var assembly     = weaverHelper.Assembly;
        var instance     = assembly.GetInstance("ClassToTest");

        EventTester.TestProperty(instance, false);
        var type         = assembly.GetType("PropertyNotificationInterceptor");
        var propertyInfo = type.GetProperty("InterceptCalled", BindingFlags.Static | BindingFlags.Public);
        var value        = (bool)propertyInfo.GetValue(null, null);

        Assert.IsTrue(value);
        Verifier.Verify(assembly.CodeBase.Replace("file:///", string.Empty));
    }
    public void BeforeAfter()
    {
        var weavingTask = new ModuleWeaver();
        var testResult  = weavingTask.ExecuteTestRun("AssemblyWithBeforeAfterInterceptor.dll");
        var assembly    = testResult.Assembly;
        var instance    = assembly.GetInstance("ClassToTest");

        EventTester.TestProperty(instance, false);
        var type         = assembly.GetType("PropertyChangedNotificationInterceptor");
        var propertyInfo = type.GetProperty("InterceptCalled", BindingFlags.Static | BindingFlags.Public);
        var value        = (bool)propertyInfo.GetValue(null, null);

        Assert.True(value);
    }
    public void BeforeAfter()
    {
        var weaverHelper = new WeaverHelper("AssemblyWithBeforeAfterInterceptor");
        var assembly     = weaverHelper.Assembly;
        var instance     = assembly.GetInstance("ClassToTest");

        EventTester.TestProperty(instance, false);
        var type         = assembly.GetType("PropertyChangedNotificationInterceptor");
        var propertyInfo = type.GetProperty("InterceptCalled", BindingFlags.Static | BindingFlags.Public);
        var value        = (bool)propertyInfo.GetValue(null, null);

        Assert.IsTrue(value);
        Verifier.Verify(weaverHelper.BeforeAssemblyPath, weaverHelper.AfterAssemblyPath);
    }
    public void Equality()
    {
        var instance = assembly.GetInstance("ClassEquality");

        EventTester.TestProperty(instance, "StringProperty", "foo");
        EventTester.TestProperty(instance, "IntProperty", 2);
        EventTester.TestProperty(instance, "NullableIntProperty", 2);
        EventTester.TestProperty(instance, "BoolProperty", true);
        EventTester.TestProperty(instance, "NullableBoolProperty", true);
        EventTester.TestProperty(instance, "ObjectProperty", "foo");
        EventTester.TestProperty(instance, "ShortProperty", (short)1);
        EventTester.TestProperty(instance, "UShortProperty", (ushort)1);
        EventTester.TestProperty(instance, "ByteProperty", (byte)1);
        EventTester.TestProperty(instance, "SByteProperty", (sbyte)1);
        EventTester.TestProperty(instance, "CharProperty", 'd');
    }
Beispiel #19
0
    public virtual void Equality()
    {
        var instance = testResult.GetInstance("ClassEquality");

        EventTester.TestProperty(instance, "StringProperty", "foo");
        EventTester.TestProperty(instance, "IntProperty", 2);
        EventTester.TestProperty(instance, "NullableIntProperty", 2);
        EventTester.TestProperty(instance, "BoolProperty", true);
        EventTester.TestProperty(instance, "NullableBoolProperty", true);
        EventTester.TestProperty(instance, "ObjectProperty", "foo");
        EventTester.TestProperty(instance, "ArrayProperty", new[] { "foo" });
        EventTester.TestProperty(instance, "ShortProperty", (short)1);
        EventTester.TestProperty(instance, "UShortProperty", (ushort)1);
        EventTester.TestProperty(instance, "ByteProperty", (byte)1);
        EventTester.TestProperty(instance, "SByteProperty", (sbyte)1);
        EventTester.TestProperty(instance, "CharProperty", 'd');
    }
    public void ClassWithGenericTypeInInheritanceChainUsesCorrectEventInvoker()
    {
        // Issue #477

        Weave(false);

        using (var module = ModuleDefinition.ReadModule(testResult.AssemblyPath))
        {
            var typeDef         = module.GetType(nameof(ClassWithGenericMiddleChildInDifferentModule));
            var setter          = typeDef.Methods.Single(m => m.Name == "set_" + nameof(ClassWithGenericMiddleChildInDifferentModule.Property));
            var callInstruction = setter.Body.Instructions.Single(i => i.OpCode == OpCodes.Callvirt);
            Assert.Equal(nameof(BaseClassWithGenericMiddleBase), ((MethodReference)callInstruction.Operand).DeclaringType.FullName);
        }

        var instance = testResult.GetInstance(nameof(ClassWithGenericMiddleChildInDifferentModule));

        EventTester.TestProperty(instance, nameof(ClassWithGenericMiddleChildInDifferentModule.Property), 42);
    }
Beispiel #21
0
    public void WithNotifyInBase()
    {
        var instance = assembly.GetInstance("ClassWithNotifyInBase");

        EventTester.TestProperty(instance, true);
    }
Beispiel #22
0
    public void WithPropertyImpOfAbstractProperty()
    {
        var instance = assembly.GetInstance("ClassWithPropertyImp");

        EventTester.TestProperty(instance, false);
    }
Beispiel #23
0
    public void GenericBaseWithPropertyOnChanged()
    {
        var instance = assembly.GetInstance("GenericBaseWithPropertyOnChanged.ClassWithGenericPropertyChild");

        EventTester.TestProperty(instance, false);
    }
Beispiel #24
0
    public void WithGenericAmdLambda()
    {
        var instance = assembly.GetInstance("ClassWithGenericAmdLambdaImp");

        EventTester.TestProperty(instance, false);
    }
Beispiel #25
0
    public void WithCustomEventInvoker()
    {
        var instance = assembly.GetInstance("ClassWithCustomEventInvoker");

        EventTester.TestProperty(instance, false);
    }
Beispiel #26
0
    public void ClassWithFieldGetButNoFieldSet()
    {
        var instance = assembly.GetInstance("ClassWithFieldGetButNoFieldSet");

        EventTester.TestProperty(instance, false);
    }
Beispiel #27
0
    public void WithLogicInSet()
    {
        var instance = assembly.GetInstance("ClassWithLogicInSet");

        EventTester.TestProperty(instance, false);
    }
Beispiel #28
0
    public void WithFields()
    {
        var instance = assembly.GetInstance("ClassWithFields");

        EventTester.TestProperty(instance, true);
    }
Beispiel #29
0
    public void DependsOn()
    {
        var instance = assembly.GetInstance("ClassDependsOn");

        EventTester.TestProperty(instance, true);
    }
Beispiel #30
0
    public void Child2()
    {
        var instance = assembly.GetInstance("ComplexHierachy.ClassChild2");

        EventTester.TestProperty(instance, false);
    }