public void SetUp() { ValidationRepository.GetMandatoryXmlElements().Returns(new List <string> { "<total>" }); }
public void LoadDocumentValid() { var store = new DocumentStore { ConnectionStringName = AppSettings.DataBaseName }; store.Initialize(); var repo = new ValidationRepository(store); var customer = new Customer { City = "Almaville", EMail = "*****@*****.**", Name = "Customer, Anna", Number = "34", Street = "Lohengrin", }; customer.Orders.Add(new Order { Amount = 23, Name = "Order 1" }); customer.Orders.Add(new Order { Amount = 245, Name = "Order 2" }); customer.Orders.Add(new Order { Amount = 5, Name = "Order 3" }); customer.Orders.Add(new Order { Amount = 5476, Name = "Order 4" }); repo.SaveDocument(customer); var loadDocument = repo.LoadDocument<Customer>(customer.Id); Assert.IsNotNull(loadDocument); }
public void ShouldBeAbleToSaveAndGetAValidation() { var validation = new Validation<Person>() .Setup(v => v.IsNotNull(p => p.Name, "Name is mandatory")); var validationRepository = new ValidationRepository(); validationRepository.Save(validation); var fetchedValidation = validationRepository.Get<Person>("Default_Validation"); Assert.AreEqual(validation, fetchedValidation); }
public void MessageContentWithMandatoryXmlElementsDoesNotThrowException(string messageContent) { List <string> mandatoryXmlElements = new List <string> { "<test>" }; ValidationRepository.GetMandatoryXmlElements().Returns(mandatoryXmlElements); Assert.DoesNotThrow(() => MandatoryXmlElementsValidator.Validate(messageContent)); }
public void JObject_Test() { var obj = JObject.FromObject(new { field = " name " }); var validation = new ValidationRepository().Create <JObject>(obj); validation.JObjectRuleFor(x => x["field"].Type <string>()).Trim(); validation.Fix(obj); obj["field"].Value <string>().Should().Be("name"); }
public void MessageContentWithMissingMandatoryXmlElementsThrowsException(string messageContent) { List <string> mandatoryXmlElements = new List <string> { "<test1>", "<test2>" }; ValidationRepository.GetMandatoryXmlElements().Returns(mandatoryXmlElements); AssertXmlContentParserExceptionIsThrown(messageContent, mandatoryXmlElements); }
public void MessageContentWithNoContentForMandatoryXmlElementThrowsException() { List <string> mandatoryXmlElements = new List <string> { "<test>" }; ValidationRepository.GetMandatoryXmlElements().Returns(mandatoryXmlElements); const string messageContent = "<test></test>"; AssertXmlContentParserExceptionIsThrown(messageContent, mandatoryXmlElements); }
public void ShouldNotBeAbleToSaveMultipleValidationsForTheATypeWithTheSameName() { var validation1 = new Validation<Person>() .Setup(v => v.IsNotNull(p => p.Name, "Name is mandatory")); var validation2 = new Validation<Person>() .Setup(v => v.IsNotNull(p => p.Name, "Name is mandatory")); var validationRepository = new ValidationRepository(); TestDelegate testCode = () => { validationRepository.Save(validation1); validationRepository.Save(validation2); }; Assert.Throws<ArgumentException>(testCode); }
private bool BeforeSavePerson(Person person, EntityInfo info) { if (info.EntityState == EntityState.Added) { person.UserId = UserId; // assign a new color if necessary if (string.IsNullOrEmpty(person.Color)) { // default to first color person.Color = Colors.List[0]; // try to assign a color that hasn't yet been assigned var colors = People.Select(p => p.Color).Distinct(); for (int i = 0; i < Colors.List.Count; i++) { if (!colors.Contains(Colors.List[i])) { person.Color = Colors.List[i]; break; } } } return(true); } if (info.EntityState == EntityState.Deleted) { // reassign all devices to Shared var shared = ValidationRepository.People.FirstOrDefault(p => p.Name == "Shared"); if (shared != null) { var devices = ValidationRepository.Devices.Where(d => d.PersonId == person.PersonId); foreach (var d in devices) { d.PersonId = shared.PersonId; } ValidationRepository.SaveChanges(); } return(true); } return(UserId == person.UserId || throwCannotSaveEntityForThisUser(person.UserId)); }
private bool BeforeSaveDevice(Device device, EntityInfo info) { if (info.EntityState == EntityState.Deleted) { // when the client tries to delete a device, instead of deleting it we mark it with an // enabled status of NULL. this is so that the next time the client Posts records, the // ControlMessage returned can instruct the device to dissasociate. at that point, the // device is actually removed. var dbDevice = ValidationRepository.Devices.FirstOrDefault(d => d.DeviceId == device.DeviceId); if (dbDevice != null) { dbDevice.Enabled = null; ValidationRepository.SaveChanges(); return(false); } } var person = device.PersonId.HasValue ? ValidationContext.People.Find(device.PersonId) : null; return((null != person) ? UserId == person.UserId || throwPersonDoesNotBelongToThisUser(person.UserId) : UserId == device.UserId || throwCannotSaveEntityForThisUser(device.UserId)); }
public ClientesController(ValidationRepository validation, ClientesRepository repo) { this.validation = validation; this.repo = repo; }
public ValidationController(ValidationRepository repository) { this.repo = repository; }
public void PurgeDocumentValid() { var store = new DocumentStore { ConnectionStringName = AppSettings.DataBaseName }; store.Initialize(); var repo = new ValidationRepository(store); repo.Purge<Customer>(); }