public void AnalyzeCombinedConstructor() { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasInjectAndNoInjectConstructor)); Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetCustomAttribute <InjectAttribute>(), Is.Not.Null); Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetParameters().Length, Is.EqualTo(1)); }
bool TryGenerate(TypeDefinition typeDef, List <DiagnosticMessage> diagnosticMessages) { var type = Type.GetType($"{typeDef.FullName}, {module.Assembly.FullName}"); if (type == null || !NeedsInjectType(type)) { return(false); } InjectTypeInfo injectTypeInfo; try { injectTypeInfo = TypeAnalyzer.Analyze(type); } catch (Exception ex) { diagnosticMessages.Add(new DiagnosticMessage { DiagnosticType = DiagnosticType.Warning, MessageData = $"Failed to analyze {type.FullName} : {ex.Message}" }); return(false); } GenerateInnerInjectorType(typeDef, injectTypeInfo); return(true); }
public void AnalyzeDuplicateAttributeConstructor() { Assert.Throws <VContainerException>(() => { TypeAnalyzer.Analyze(typeof(HasMultipleInjectConstructor)); }); }
bool TryGenerateType(TypeDefinition typeDef, List <DiagnosticMessage> diagnosticMessages) { Type type; try { type = GetTypeFromDef(typeDef); } catch (Exception ex) { diagnosticMessages.Add(new DiagnosticMessage { DiagnosticType = DiagnosticType.Warning, MessageData = $"Skip IL waving because cannot detect type: {typeDef.FullName}. {ex} {ex.Message}" }); return(false); } if (type == null) { diagnosticMessages.Add(new DiagnosticMessage { DiagnosticType = DiagnosticType.Warning, MessageData = $"Skip IL waving because cannot detect type: {typeDef.FullName}" }); return(false); } if (!NeedsInjectType(type)) { return(false); } InjectTypeInfo injectTypeInfo; try { injectTypeInfo = TypeAnalyzer.Analyze(type); } catch (Exception ex) { diagnosticMessages.Add(new DiagnosticMessage { DiagnosticType = DiagnosticType.Warning, MessageData = $"Failed to analyze {type.FullName} : {ex} {ex.Message}" }); return(false); } GenerateInnerInjectorType(typeDef, injectTypeInfo); return(true); }
public void Analyze() { { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasNoConstructor)); Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(0)); } { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasNoAttributeConstructor)); Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(2)); } { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasInjectConstructor)); // Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetCustomAttribute<InjectAttribute>(), Is.Not.Null); } }
public void Analyze_ShouldDetectErrorIfInvalidValueTypeRuleIsGiven( Widget widget, IList <ValueType> invalidTypes) { const string sampleQuestionName = "SampleQuestion"; foreach (var invalidType in invalidTypes) { var typeAnamyzer = new TypeAnalyzer(); var sampleQuestionMapings = new Dictionary <string, ValueType> { { sampleQuestionName, invalidType } }; var valueTypeRule = new ValueTypeRule(invalidType, widget, null); typeAnamyzer.Analyze(this.GetStyleSheetWrapper(valueTypeRule), sampleQuestionMapings); Assert.NotEmpty(typeAnamyzer.Report.AllMessages); Assert.IsType <InvalidWidgetTypeMessage>(typeAnamyzer.Report.Errors.FirstOrDefault()); Assert.Equal(1, typeAnamyzer.Report.AllMessages.Count()); } }
public void Analyze_ShouldThrowExceptionIfNullStyleRootNodeIsGiven() { var typeAnamyzer = new TypeAnalyzer(); Assert.Throws <ArgumentNullException>(() => typeAnamyzer.Analyze(null, new Dictionary <string, ValueType>())); }
public void Analyze_ShouldThrowExceptionIfNullQuestionMappingsAreGivenNodeIsGiven() { var typeAnamyzer = new TypeAnalyzer(); Assert.Throws <ArgumentNullException>(() => typeAnamyzer.Analyze(new StyleSheet("SampleStyleSheet"), null)); }
public void AnalyzeNoAttributeConstructor() { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasMultipleConstructor)); Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(2)); }
public void AnalyzeStaticConstructor() { var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasStaticConstructor)); Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.IsStatic, Is.False); }