public void Run()
    {
        var memberMappings = ModuleWeaver.GetMappings(DefinitionFinder.FindType <ClassWithLowerCaseBackingFields>()).ToList();

        Assert.Equal("property1", memberMappings.First(x => x.PropertyDefinition.Name == "Property1").FieldDefinition.Name);
        Assert.Equal("property2", memberMappings.First(x => x.PropertyDefinition.Name == "Property2").FieldDefinition.Name);
    }
示例#2
0
    public void Run()
    {
        var memberMappings = ModuleWeaver.GetMappings(DefinitionFinder.FindType <ClassWithSingleBackingFieldsGet>()).ToList();
        var memberMapping  = memberMappings.Single(x => x.PropertyDefinition.Name == "Property1");

        Assert.IsNull(memberMapping.FieldDefinition);
    }
    public void WithLowerUnderScoreBackingFields()
    {
        var memberMappings = MappingFinder.GetMappings(DefinitionFinder.FindType <ClassWithUnderScoreBackingFields>()).ToList();

        Assert.AreEqual("_property1", memberMappings.First(x => x.PropertyDefinition.Name == "Property1").FieldDefinition.Name);
        Assert.AreEqual("_property2", memberMappings.First(x => x.PropertyDefinition.Name == "Property2").FieldDefinition.Name);
    }
示例#4
0
    public void Run()
    {
        var memberMappings = ModuleWeaver.GetMappings(DefinitionFinder.FindType <ClassWithSingleBackingFieldsSet>()).ToList();

        Assert.AreEqual("propertyA", memberMappings.Single(x => x.PropertyDefinition.Name == "Property1").FieldDefinition.Name);
        Assert.AreEqual("propertyB", memberMappings.Single(x => x.PropertyDefinition.Name == "Property2").FieldDefinition.Name);
    }
    public void Run()
    {
        var memberMappings = ModuleWeaver.GetMappings(DefinitionFinder.FindType <ClassWithAutoPropertiesAndDodgyField>()).ToList();

        Assert.AreEqual("<Property1>k__BackingField", memberMappings.Single(x => x.PropertyDefinition.Name == "Property1").FieldDefinition.Name);
        Assert.AreEqual("<Property2>k__BackingField", memberMappings.Single(x => x.PropertyDefinition.Name == "Property2").FieldDefinition.Name);
    }
示例#6
0
    public void TestString()
    {
        var typeDefinition  = DefinitionFinder.FindType <string>();
        var findNamedMethod = ModuleWeaver.FindNamedMethod(typeDefinition);

        Assert.Equal("System.Boolean System.String::Equals(System.String,System.String)", findNamedMethod.FullName);
    }
示例#7
0
    public void TestSqlGuid()
    {
        var typeDefinition  = DefinitionFinder.FindType <SqlGuid>();
        var findNamedMethod = ModuleWeaver.FindNamedMethod(typeDefinition);

        Assert.Null(findNamedMethod);
    }
示例#8
0
    public void CanDetectIfGetterCallsVirtualBaseSetterWhenBaseClassInDifferentAssembly()
    {
        var propertyDefinition = DefinitionFinder.FindType <ChildWithBaseInDifferentAssembly>().Properties.First(x => x.Name == "Property1");
        var result             = stackOverflowChecker.CheckIfGetterCallsVirtualBaseSetter(propertyDefinition);

        Assert.AreEqual(true, result);
    }
    public void TestInt()
    {
        var typeDefinition  = DefinitionFinder.FindType <int>();
        var findNamedMethod = ModuleWeaver.FindNamedMethod(typeDefinition);

        Assert.IsNull(findNamedMethod);
    }
    public void CanDetectIfGetterCallsVirtualBaseSetter()
    {
        var propertyDefinition = DefinitionFinder.FindType <ChildClassWithOverflow>().Properties.First(x => x.Name == "Property1");
        var result             = stackOverflowChecker.CheckIfGetterCallsVirtualBaseSetter(propertyDefinition);

        Assert.True(result);
    }
示例#11
0
    public void TestSqlGuid()
    {
        var typeDefinition  = DefinitionFinder.FindType <SqlGuid>();
        var findNamedMethod = TypeEqualityFinder.FindNamedMethod(typeDefinition);

        Assert.IsNull(findNamedMethod);
    }
示例#12
0
    public void CanCheckIfGetterCallsSetter(string propertyName, bool expectedResult)
    {
        var propertyDefinition = DefinitionFinder.FindType <ClassWithStackOverflow>().Properties.First(x => x.Name == propertyName);
        var result             = stackOverflowChecker.CheckIfGetterCallsSetter(propertyDefinition);

        Assert.AreEqual(expectedResult, result);
    }
示例#13
0
        public void ValidateFindMethodsThatDoNotUsesArraySlicesInBody()
        {
            var typeToFind = DefinitionFinder.FindType(typeof(ArraySlice <>));
            var methods    = Weaver.FindMethodsUsingArraySlices(typeToFind)
                             .Where(x => x.Name.StartsWith("DoNot") && x.DeclaringType.Name == "ControlWeavingAtMethodLevel");

            Assert.Equal(2, methods.Count());
        }
示例#14
0
    public void WithoutNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithoutNotificationProperty);

        var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanging");

        Assert.IsEmpty(propertyNames);
    }
示例#15
0
    public void ContainsNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotificationProperty);

        var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanging");

        Assert.Single(propertyNames);
    }
    public void ContainsNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotifactionProperty);

        var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanged");

        Assert.AreEqual(1, propertyNames.Count());
    }
    public void AlreadyContainsNotificationNonVirtual()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotifactionProperty);

        var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanged");

        Assert.IsNotEmpty(propertyNames);
    }
    public void ContainsNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotifactionProperty);

        var message = TypeProcessor.AlreadyContainsNotification(propertyDefinition, "OnPropertyChanged");

        Assert.IsTrue(message);
    }
    public void ContainsNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotificationProperty);

        var moduleWeaver  = new ModuleWeaver();
        var propertyNames = moduleWeaver.GetAlreadyNotifies(propertyDefinition);

        Assert.AreEqual(1, propertyNames.Count());
    }
示例#20
0
    public void MultipleNotifications()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new Multiple().Property);

        var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanging").ToList();

        Assert.Contains("Property1", propertyNames);
        Assert.Contains("Property2", propertyNames);
    }
    public void AlreadyContainsNotificationNonVirtual()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotificationProperty);

        var moduleWeaver  = new ModuleWeaver();
        var propertyNames = moduleWeaver.GetAlreadyNotifies(propertyDefinition).ToList();

        Assert.IsNotEmpty(propertyNames);
    }
        public void SurveyViewModel_Should_Have_CommandInitialization_Injected()
        {
            var instance       = Assembly.GetInstance("WpfMvvmSample.SurveyViewModel");
            var objectInstance = (object)instance;
            var type           = DefinitionFinder.FindType(objectInstance.GetType());
            var method         = type.FindMethod("<Commander_Fody>InitializeCommands");

            method.Should().NotBeNull();
        }
    public void MultipleNotifications()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new Multiple().Property);

        var moduleWeaver  = new ModuleWeaver();
        var propertyNames = moduleWeaver.GetAlreadyNotifies(propertyDefinition).ToList();

        Assert.Contains("Property1", propertyNames);
        Assert.Contains("Property2", propertyNames);
    }
示例#24
0
    public void PropertyThatDoesNotExist()
    {
        var reader = new ModuleWeaver();
        var node   = new TypeNode
        {
            TypeDefinition = DefinitionFinder.FindType <ClassWithInvalidDepends>(),
        };

        reader.ProcessDependsOnAttributes(node);
    }
 public void Run()
 {
     var typeDefinition = DefinitionFinder.FindType<Person>();
     var node = new TypeNode
     {
         TypeDefinition = typeDefinition,
         Mappings = ModuleWeaver.GetMappings(typeDefinition).ToList()
     };
     new IlGeneratedByDependencyReader(node).Process();
     Assert.Empty(node.PropertyDependencies);
 }
    public void IsAbstract()
    {
        var checker            = new ModuleWeaver();
        var propertyDefinition = DefinitionFinder.FindType <BaseClass>().Properties.First(x => x.Name == "AbstractProperty");

        var message = checker.CheckForWarning(new PropertyData
        {
            PropertyDefinition = propertyDefinition,
        }, false);

        Assert.IsNotNull(message);
    }
示例#27
0
    public void Run()
    {
        var typeDefinition = DefinitionFinder.FindType <Person>();
        var node           = new TypeNode
        {
            TypeDefinition = typeDefinition,
            Mappings       = MappingFinder.GetMappings(typeDefinition).ToList()
        };

        new IlGeneratedByDependencyReader(node).Process();
        Assert.AreEqual(0, node.PropertyDependencies.Count);
    }
    public void IsIndexer()
    {
        var checker            = new ModuleWeaver();
        var propertyDefinition = DefinitionFinder.FindType <IndexerClass>().Properties.First();

        var message = checker.CheckForWarning(new PropertyData
        {
            PropertyDefinition = propertyDefinition,
        }, false);

        Assert.IsNotNull(message);
    }
示例#29
0
    public void WithGet()
    {
        var checker = new ModuleWeaver();

        var propertyDefinition = DefinitionFinder.FindProperty <PropertyChangingArgWithNoGetInfoCheckerTest>("PropertyWithGet");

        var message = checker.CheckForWarning(new PropertyData
        {
            PropertyDefinition = propertyDefinition,
        }, InvokerTypes.PropertyChangingArg);

        Assert.IsNull(message);
    }
    public void PropertyThatDoesNotExist()
    {
        var logger = Substitute.For <Logger>();
        var reader = new DependsOnDataAttributeReader(null, logger);
        var node   = new TypeNode
        {
            TypeDefinition = DefinitionFinder.FindType <ClassWithInvalidDepends>(),
        };

        reader.Process(node);
        logger.Received().LogError("Could not find property 'NotAProperty2' for DependsOnAttribute assinged to 'FullName'.");
        logger.Received().LogError("Could not find property 'NotAProperty1' for DependsOnAttribute assinged to 'FullName'.");
    }