public void Should_ReturnTrue_When_ValidPersonProvided() { var person = new Person { FirstName = "ValidName", LastName = "ValidLastName", Country = "ValidCountry", Age = 25 }; Assert.IsTrue(_objectUnderTest.IsValid(person)); }
public bool IsValid(out string message) { PersonValidator validator = new PersonValidator(this); bool flag = validator.IsValid(); message = validator.Message; return(flag); }
public void OverlapsRangeFails() { // Assert var start = new DateTime(1999, 1, 1); var finish = new DateTime(2020, 12, 31); var validity = new DateRange(start, finish); var system = new SourceSystem { Name = "Test" }; var personMapping = new PersonMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List <PersonMapping> { personMapping }; var repository = new Mock <IRepository>(); repository.Setup(x => x.Queryable <PersonMapping>()).Returns(list.AsQueryable()); var systemList = new List <SourceSystem>(); repository.Setup(x => x.Queryable <SourceSystem>()).Returns(systemList.AsQueryable()); var overlapsRangeIdentifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(10), EndDate = start.AddHours(15) }; var identifierValidator = new NexusIdValidator <PersonMapping>(repository.Object); var validatorEngine = new Mock <IValidatorEngine>(); validatorEngine.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny <IList <IRule> >())) .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList <IRule> y) => identifierValidator.IsValid(x, y)); var validator = new PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { overlapsRangeIdentifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
public void CannotAcceptInvalidPerson() { //given var person = new Person(); //when var result = _personValidator.IsValid(person); //then Assert.IsFalse(result); Assert.AreEqual(_personValidator.InvalidRules.Count, 2); Assert.IsNotNull(_personValidator.InvalidRules.FirstOrDefault(x => (PersonValidation)x == PersonValidation.InvalidName)); Assert.IsNotNull(_personValidator.InvalidRules.FirstOrDefault(x => (PersonValidation)x == PersonValidation.InvalidEmail)); }
static void Main(string[] args) { StandardMessages.WelcomeMessage(); Person user = PersonDataCapture.Capture(); var(isValid, msg) = PersonValidator.IsValid(user); if (isValid == false) { StandardMessages.EndApplication(msg); return; } AccountGenerator.Generate(user); StandardMessages.EndApplication(StandardMessages.PRESS_KEY_TO_EXIT); }
public void ValidPersonPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new SourceSystem { Name = "Test" }; var systemList = new List <SourceSystem> { system }; var systemRepository = new Mock <IRepository>(); systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var validatorEngine = new Mock <IValidatorEngine>(); var validator = new PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Surname = "Test" }, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count differs"); }
public void BadSystemFails() { // Assert var start = new DateTime(1999, 1, 1); var finish = new DateTime(2020, 12, 31); var validity = new DateRange(start, finish); var system = new SourceSystem { Name = "Test" }; var personMapping = new PersonMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List<PersonMapping> { personMapping }; var repository = new Mock<IRepository>(); repository.Setup(x => x.Queryable<PersonMapping>()).Returns(list.AsQueryable()); var badSystemIdentifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Jim", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var identifierValidator = new NexusIdValidator<PersonMapping>(repository.Object); var validatorEngine = new Mock<IValidatorEngine>(); validatorEngine.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny<IList<IRule>>())) .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList<IRule> y) => identifierValidator.IsValid(x, y)); var validator = new PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { badSystemIdentifier } }; // Act var violations = new List<IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
public void ValidPersonPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new SourceSystem { Name = "Test" }; var systemList = new List<SourceSystem> { system }; var systemRepository = new Mock<IRepository>(); systemRepository.Setup(x => x.Queryable<MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var validatorEngine = new Mock<IValidatorEngine>(); var validator = new PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails{Surname = "Test"}, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; // Act var violations = new List<IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count differs"); }