public IRule?Construct(ProjectReferenceRuleData data) { if (string.IsNullOrEmpty(data.Name)) { return(null); } return(new ProjectReferenceRule(data)); }
public void ProjectReferenceShouldNotBeConstructableWhenNameIsMissing() { // Arrange var data = new ProjectReferenceRuleData(); var sut = new RuleFactory(); // Act var actual = sut.Construct(data); // Assert Assert.Null(actual); }
public void ProjectReferenceRuleShouldBeConstructable() { // Arrange var data = new ProjectReferenceRuleData { Name = Guid.NewGuid().ToString() }; var sut = new RuleFactory(); // Act var actual = sut.Construct(data); // Assert Assert.NotNull(actual); }
public async Task ValidateShouldFailWhenRequiredReferenceIsMissing() { // Arrange var project = new ProjectBuilder().Build(); var data = new ProjectReferenceRuleData { Required = true, Name = "Project" }; var sut = new ProjectReferenceRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public async Task ValidateShouldSucceedWhenOptionalReferenceIsMissing() { // Arrange var project = new ProjectBuilder().Build(); var data = new ProjectReferenceRuleData { Required = false, Name = "Project" }; var sut = new ProjectReferenceRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.False(actual.IsError); }
public async Task ValidateShouldSucceedWhenOptionalProjectIsReferenced() { // Arrange var project = new ProjectBuilder() .WithItemGroup() .WithProjectReference("Project") .Build(); var data = new ProjectReferenceRuleData { Name = "Project", Required = false }; var sut = new ProjectReferenceRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.False(actual.IsError); }
public async Task ValidateShouldSucceedWhenNameMatchesButPathDoesNot() { // Arrange var project = new ProjectBuilder() .WithItemGroup() .WithProjectReference("Path/Project") .Build(); var data = new ProjectReferenceRuleData { Name = "Project", Required = true }; var sut = new ProjectReferenceRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.False(actual.IsError); }
public async Task ValidateShouldFailWhenForbiddenReferenceExists() { // Arrange var project = new ProjectBuilder() .WithItemGroup() .WithProjectReference("Project") .Build(); var data = new ProjectReferenceRuleData { Forbidden = true, Name = "Project" }; var sut = new ProjectReferenceRule(data); // Act var actual = await sut.Validate(project); // Assert Assert.True(actual.IsError); }
public ConfigBuilder WithProjectReference(ProjectReferenceRuleData data) { _projectReferences.Add(data); return(this); }
public ProjectReferenceRule(ProjectReferenceRuleData data) { _data = data; }