void ValidateComponentTypeAndToolboxItem(Type componentType, IDiagnosticScope scope, bool expected) { var typeCtx = scope.ElementAt(0); Assert.AreEqual(componentType.Assembly, typeCtx.Assembly); Assert.AreEqual(componentType, typeCtx.Type); Assert.IsNull(typeCtx.Member); var typeDiagnostics = cfg.Resolve(typeCtx); Assert.AreEqual(2, typeDiagnostics.Count()); Assert.IsTrue(typeDiagnostics.ElementAt(0) is ComponentShouldBeRegisteredAsToolboxItem); Assert.IsTrue(typeDiagnostics.ElementAt(1) is ComponentShouldHaveDescription); Assert.AreEqual(expected, typeDiagnostics.ElementAt(0).Validate(typeCtx)); Assert.AreEqual(expected, typeDiagnostics.ElementAt(1).Validate(typeCtx)); }
void ValidateComponentPropertiesAndAttributes(Type componentType, IDiagnosticScope scope, bool expected) { var props = scope.Where(x => x.Member is PropertyInfo); Assert.AreEqual(4, props.Count()); var propValueCtx = props.ElementAt(0); Assert.AreEqual(componentType.Assembly, propValueCtx.Assembly); Assert.AreEqual(componentType, propValueCtx.Type); Assert.AreEqual(componentType.GetProperty("Value"), propValueCtx.Member); var propHasValueCtx = props.ElementAt(1); Assert.AreEqual(componentType.Assembly, propHasValueCtx.Assembly); Assert.AreEqual(componentType, propHasValueCtx.Type); Assert.AreEqual(componentType.GetProperty("HasValue"), propHasValueCtx.Member); var propValueDiagnostics = cfg.Resolve(propValueCtx); Assert.AreEqual(5, propValueDiagnostics.Count()); Assert.IsTrue(propValueDiagnostics.ElementAt(0) is ComponentShouldBeRegisteredAsToolboxItem); Assert.IsTrue(propValueDiagnostics.ElementAt(1) is ComponentShouldHaveDescription); Assert.IsTrue(propValueDiagnostics.ElementAt(2) is MemberShouldHaveDescription); Assert.IsTrue(propValueDiagnostics.ElementAt(3) is MemberShouldBeCategorized); Assert.IsTrue(propValueDiagnostics.ElementAt(4) is MemberShouldHaveDefaultValue); Assert.AreEqual(expected, propValueDiagnostics.ElementAt(2).Validate(propValueCtx)); Assert.AreEqual(expected, propValueDiagnostics.ElementAt(3).Validate(propValueCtx)); Assert.AreEqual(expected, propValueDiagnostics.ElementAt(4).Validate(propValueCtx)); var propHasValueDiagnostics = cfg.Resolve(propHasValueCtx); Assert.AreEqual(4, propHasValueDiagnostics.Count()); Assert.IsTrue(propHasValueDiagnostics.ElementAt(0) is ComponentShouldBeRegisteredAsToolboxItem); Assert.IsTrue(propHasValueDiagnostics.ElementAt(1) is ComponentShouldHaveDescription); Assert.IsTrue(propHasValueDiagnostics.ElementAt(2) is MemberShouldHaveDescription); Assert.IsTrue(propHasValueDiagnostics.ElementAt(3) is MemberShouldNotBeBrowsable); Assert.AreEqual(expected, propHasValueDiagnostics.ElementAt(2).Validate(propHasValueCtx)); Assert.AreEqual(expected, propHasValueDiagnostics.ElementAt(3).Validate(propHasValueCtx)); }