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); }
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); }
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); }
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); }
public void TestSqlGuid() { var typeDefinition = DefinitionFinder.FindType <SqlGuid>(); var findNamedMethod = ModuleWeaver.FindNamedMethod(typeDefinition); Assert.Null(findNamedMethod); }
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); }
public void TestSqlGuid() { var typeDefinition = DefinitionFinder.FindType <SqlGuid>(); var findNamedMethod = TypeEqualityFinder.FindNamedMethod(typeDefinition); Assert.IsNull(findNamedMethod); }
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); }
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()); }
public void WithoutNotification() { var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithoutNotificationProperty); var propertyNames = propertyDefinition.GetAlreadyNotifies("OnPropertyChanging"); Assert.IsEmpty(propertyNames); }
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()); }
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); }
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); }
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); }
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'."); }