internal ComparisonConstraint SaveConstraint(ComparisonConstraint constraint, DataContainer container) { //Contract.Requires(); Contract.Requires(container != null); Contract.Ensures(Contract.Result <ComparisonConstraint>() != null && Contract.Result <ComparisonConstraint>().Id >= 0); constraint.DataContainer = container; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <ComparisonConstraint> repo = uow.GetRepository <ComparisonConstraint>(); repo.Put(constraint); uow.Commit(); } return(constraint); }
internal ComparisonConstraint Update(ComparisonConstraint entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result <ComparisonConstraint>() != null && Contract.Result <ComparisonConstraint>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <ComparisonConstraint> repo = uow.GetRepository <ComparisonConstraint>(); repo.Merge(entity); var merged = repo.Get(entity.Id); repo.Put(merged); uow.Commit(); } return(entity); }
internal bool Delete(ComparisonConstraint entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <ComparisonConstraint> repo = uow.GetRepository <ComparisonConstraint>(); entity = repo.Reload(entity); //delete the unit repo.Delete(entity); // commit changes uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return(true); }
public void AddConstraint(ComparisonConstraint constraint, DataContainer container) { helper.SaveConstraint(constraint, container); }
public void RemoveConstraint(ComparisonConstraint constraint) { constraint.DataContainer = null; helper.Delete(constraint); }
public void RemoveConstraint(ComparisonConstraint constraint) { constraint.DataContainer = null; helper.Delete(constraint); }
public void AddConstraint(ComparisonConstraint constraint, DataContainer container) { helper.SaveConstraint(constraint, container); }
public void RemoveConstraint(ComparisonConstraint constraint) { helper.Delete(constraint); }
private void addConstraintsTo() { DataContainerManager dcManager = new DataContainerManager(); var attr = dcManager.DataAttributeRepo.Get(1); var c1 = new RangeConstraint(ConstraintProviderSource.Internal, "", "en-US", "should be between 1 and 12 meter", true, null, null, null, 1.00, true, 12.00, true); dcManager.AddConstraint(c1, attr); var v1 = c1.IsSatisfied(14); var c2 = new PatternConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple email validation constraint", false, null, null, null, @"^\S+@\S+$", false); dcManager.AddConstraint(c2, attr); var v2 = c2.IsSatisfied("*****@*****.**"); List<DomainItem> items = new List<DomainItem>() { new DomainItem () {Key = "A", Value = "This is A" }, new DomainItem () {Key = "B", Value = "This is B" }, new DomainItem () {Key = "C", Value = "This is C" }, new DomainItem () {Key = "D", Value = "This is D" }, }; var c3 = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, items); dcManager.AddConstraint(c3, attr); var v3 = c3.IsSatisfied("A"); v3 = c3.IsSatisfied("E"); c3.Negated = true; v3 = c3.IsSatisfied("A"); var c4 = new ComparisonConstraint(ConstraintProviderSource.Internal, "", "en-US", "a comparison validation constraint", false, null, null, null , ComparisonOperator.GreaterThanOrEqual, ComparisonTargetType.Value, "", ComparisonOffsetType.Ratio, 1.25); dcManager.AddConstraint(c4, attr); var v4 = c4.IsSatisfied(14, 10); }
internal ComparisonConstraint Update(ComparisonConstraint entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result<ComparisonConstraint>() != null && Contract.Result<ComparisonConstraint>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<ComparisonConstraint> repo = uow.GetRepository<ComparisonConstraint>(); repo.Put(entity); // Merge is required here!!!! uow.Commit(); } return (entity); }
internal ComparisonConstraint SaveConstraint(ComparisonConstraint constraint, DataContainer container) { //Contract.Requires(); Contract.Requires(container != null); Contract.Ensures(Contract.Result<ComparisonConstraint>() != null && Contract.Result<ComparisonConstraint>().Id >= 0); constraint.DataContainer = container; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<ComparisonConstraint> repo = uow.GetRepository<ComparisonConstraint>(); repo.Put(constraint); uow.Commit(); } return (constraint); }
internal bool Delete(ComparisonConstraint entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<ComparisonConstraint> repo = uow.GetRepository<ComparisonConstraint>(); entity = repo.Reload(entity); //delete the unit repo.Delete(entity); // commit changes uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return (true); }
public void RemoveConstraint(ComparisonConstraint constraint) { helper.Delete(constraint); }
static void AssertThat <TParam1, TResult>(Func <TParam1, TResult> invocation, TParam1 arg, ComparisonConstraint comparisonConstraint) { long startTime = DateTime.Now.Ticks; TResult retVal = invocation.Invoke(arg); Assert.That(retVal, Is.EqualTo(METHOD_RESPONSE_ELEMENT + arg)); long durationInTicks = DateTime.Now.Ticks - startTime; long durationInMilliseconds = durationInTicks / TimeSpan.TicksPerMillisecond; Assert.That(durationInMilliseconds, comparisonConstraint); }