public void ClassesDerivedFromPureComponentMustNotHaveNonEmptyInstanceConstructors()
{
var testContent = @"
using Bridge.React;
namespace TestCase
{
public class LabelComponent : PureComponent<LabelComponent.Props>
{
private readonly int _otherValue;
public LabelComponent(Props props, int otherValue) : base(props)
{
_otherValue = otherValue;
}
public override ReactElement Render()
{
return DOM.Label(
new LabelAttributes { ClassName = props.ClassName },
props.Text + "" ("" + _otherValue + "")""
);
}
public class Props
{
public string ClassName;
public string Text;
}
}
}";
var expected = new DiagnosticResult
{
Id = ComponentAnalyzer.DiagnosticId,
Message = string.Format(ComponentAnalyzer.EmptyConstructorRule.MessageFormat.ToString(), "LabelComponent", "PureComponent"),
Severity = DiagnosticSeverity.Error,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 9, 7)
}
};
VerifyCSharpDiagnostic(testContent, expected);
}