public IRule?Construct(PropertyRuleData data) { if (string.IsNullOrEmpty(data.Name)) { return(null); } return(new PropertyRule(data)); }
public void PropertyRuleShouldNotBeConstructableWhenNameIsMissing() { // Arrange var data = new PropertyRuleData(); var sut = new RuleFactory(); // Act var actual = sut.Construct(data); // Assert Assert.Null(actual); }
public void PropertyRuleShouldBeConstructable() { // Arrange var data = new PropertyRuleData { Name = Guid.NewGuid().ToString() }; var sut = new RuleFactory(); // Act var actual = sut.Construct(data); // Assert Assert.NotNull(actual); }
public async Task ValidateShouldFailWhenNonOptionalPropertyIsMissing() { // Arrange var project = new ProjectBuilder().Build(); var data = new PropertyRuleData { Name = "Required-Property", Required = true }; var sut = new PropertyRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public async Task ValidateShouldFailWhenForbiddenPropertyIsFound() { // Arrange var project = new ProjectBuilder() .WithPropertyGroup().WithProperty("Forbidden-Property", "true").Build(); var data = new PropertyRuleData { Forbidden = true, Name = "Forbidden-Property" }; var sut = new PropertyRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public async Task ValidateShouldFailWhenPropertyHasWrongValue() { // Arrange var project = new ProjectBuilder() .WithPropertyGroup() .WithProperty("Property", "invalid") .Build(); var data = new PropertyRuleData { Name = "Property", Value = "valid" }; var sut = new PropertyRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public async Task ValidateShouldSucceedWhenPropertyExists() { // Arrange var project = new ProjectBuilder() .WithPropertyGroup() .WithProperty("TreatWarningsAsErrors", "true") .Build(); var data = new PropertyRuleData { Name = "TreatWarningsAsErrors", Required = true }; var sut = new PropertyRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.False(actual.IsError); }
public async Task ValidateShouldFailWhenPropertyIsFoundTooFewTimes() { // Arrange var project = new ProjectBuilder() .WithPropertyGroup() .WithProperty("Property", "value") .WithPropertyGroup() .WithProperty("Property", "value") .Build(); var data = new PropertyRuleData { Name = "Property", MinimumOccurrences = 3 }; var sut = new PropertyRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public ConfigBuilder WithProperty(PropertyRuleData data) { _properties.Add(data); return(this); }
public PropertyRule(PropertyRuleData data) { _data = data; }