public async Task <IParent?> GetParentAsync(ParentPath?parentPath) { // TODO: heavily cache this. traversing the parent tree per call could be very expensive (and is now possible) var parent = default(ParentEntity); if (parentPath == null) { return(parent); } foreach (var(repositoryAlias, id) in parentPath) { var repo = _repositoryResolver.GetRepository(repositoryAlias); var entity = await repo.GetByIdAsync(id, parent); if (entity == null) { break; } parent = new ParentEntity(parent, entity, repositoryAlias); } return(parent); }
public async Task In_multiple() { var query = @" { parentEntities (where: {path: 'Property', comparison: 'In', value: ['Value1', 'Value2']}, orderBy: {path: ""property""}) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public ParentEntity Update(int id, string columnA, string columnB) { ParentEntity _entity = null; using (var context = CreateContext()) { bool isNew = false; _entity = context.ParentEntity .Include("ChildEntity") .SingleOrDefault(e => e.parent_id == id); ChildEntity entityChild = ParentEntity.ChildEntity.SingleOrDefault(); if (entityChild == null) { entityChild = new ChildEntity(); isNew = true; } entityChild.ColumnA = columnA; entityChild.ColumnB = columnB; if (isNew) { ParentEntity.ChildEntity.Add(entityChild); } context.SaveChanges(); } return(_entity); }
public static List <ParentEntity> GetGeneratedParents() { var Random = new Random(); var values = new List <ParentEntity>(); for (int i = 0; i < stringValues.Count - 1; i++) { var entity = new ParentEntity() { Id = i, Header = stringValues[Random.Next(stringValues.Count - 1)], }; for (int j = 0; j < Random.Next(10); j++) { var child = new ChildEntity() { Id = j, Name = stringValues[Random.Next(stringValues.Count - 1)], Score = Random.Next(10000) / 5, IsImp = Random.Next(2) > 1 }; entity.ChildEntity.Add(child); } entity.Score = entity.ChildEntity.Sum(c => c.Score); values.Add(entity); } return(values); }
public async Task Id_multiple() { var query = @" { parentEntities (ids: ['00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002']) { property } }"; var entity1 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), Property = "Value1" }; var entity2 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Property = "Value2" }; var entity3 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000003"), Property = "Value3" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2, entity3); await Verifier.Verify(result); }
protected override void Initialize() { var p1 = new ParentEntity(); var p2 = new ParentEntity(); var c1_1 = new Child1Entity(); var c1_2 = new Child1Entity(); var c2_1 = new Child2Entity(); var c2_2 = new Child2Entity(); allowNullInMiddleTable(); //rev 1 using (var tx = Session.BeginTransaction()) { p1_id = (int)Session.Save(p1); p2_id = (int)Session.Save(p2); c1_1_id = (int)Session.Save(c1_1); c1_2_id = (int)Session.Save(c1_2); c2_1_id = (int)Session.Save(c2_1); c2_2_id = (int)Session.Save(c2_2); tx.Commit(); } //rev 2 - (p1: c1_1, p2: c2_1) using (var tx = Session.BeginTransaction()) { p1.Children1.Add(c1_1); p2.Children2.Add(c2_1); tx.Commit(); } // Rev 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) using (var tx = Session.BeginTransaction()) { p1.Children1.Add(c1_2); p1.Children2.Add(c2_2); p2.Children1.Add(c1_1); tx.Commit(); } // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) using (var tx = Session.BeginTransaction()) { p1.Children1.Remove(c1_1); p2.Children2.Add(c2_2); tx.Commit(); } // Rev 5 - (p1: c2_2, p2: c1_1, c2_1) Session.Clear(); using (var tx = Session.BeginTransaction()) { c1_2 = Session.Get <Child1Entity>(c1_2.Id); c2_2 = Session.Get <Child2Entity>(c2_2.Id); c2_2.Parents.Remove(p2); c1_2.Parents.Remove(p1); tx.Commit(); } }
public async Task Where_default_comparison() { var query = @" { parentEntities (where: {path: 'Property', value: 'value2'}) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task In_case_sensitive() { var query = @" { parentEntities (where: {path: 'Property', comparison: 'In', value: 'Value2', case: 'Ordinal' }) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task SingleNullable_Found() { var query = @" { parentEntityNullable(id: ""00000000-0000-0000-0000-000000000001"") { property } }"; var entity1 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), Property = "Value1" }; var entity2 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task Where_multiple() { var query = @" { parentEntities (where: [ {path: 'Property', comparison: 'startsWith"", value: 'Valu'} {path: 'Property', comparison: 'endsWith"", value: 'ue3'} ] ) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; var entity3 = new ParentEntity { Property = "Value3" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2, entity3); await Verifier.Verify(result); }
public async Task Where_with_variable() { var query = @" query ($value: String!) { parentEntities (where: {path: 'Property', comparison: 'equal', value: [$value]}) { property } } "; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; var inputs = new Inputs( new Dictionary <string, object> { { "value", "value2" } }); await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, inputs, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task Single_Found_NoTracking() { var query = @" { parentEntity(id: ""00000000-0000-0000-0000-000000000001"", orderBy: {path: ""property""}) { property } }"; var entity1 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), Property = "Value1" }; var entity2 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, true, entity1, entity2); await Verifier.Verify(result); }
public async Task OrderByDescending() { var query = @" { parentEntities (orderBy: {path: 'Property', descending: true}) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task Skip() { var query = @" { parentEntities (skip: 1, orderBy: {path: ""property""}) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2); await Verifier.Verify(result); }
public async Task Take() { var queryString = @" { parentEntities (take: 1) { property } }"; var entity1 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), Property = "Value1" }; var entity2 = new ParentEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Property = "Value2" }; var result = await RunQuery(queryString, null, true, entity1, entity2); ObjectApprover.VerifyWithJson(result); }
public void deleteCascadeParentEntity() { using (UnitOfWork worker = new UnitOfWork(new SqliteTestDbContext())) { ChildEntity newChild = new ChildEntity(); var createDateChild = new DateTime(2022, 4, 8, 4, 35, 11); newChild.createdDate = createDateChild; newChild.name = "NewChild"; newChild.sequenceNo = 32; ParentEntity newParent = new ParentEntity(); var createDateParent = new DateTime(2020, 1, 10, 11, 25, 20); newParent.createdDate = createDateParent; newParent.name = "NewParent"; newParent.sequenceNo = 32; newParent.ChildEntity.Add(newChild); worker.ParentEntityRepository.Add(newParent); var newParentDb = worker.ParentEntityRepository.GetAll().ToList(); worker.ParentEntityRepository.Remove(newParentDb.FirstOrDefault()); newParentDb = worker.ParentEntityRepository.GetAll().ToList(); Assert.AreEqual(0, newParentDb.Count); var newChildDb = worker.ChildEntityRepository.GetAll().ToList(); Assert.AreEqual(0, newChildDb.Count); var newSubClassDb = worker.SubClassEntityRepository.GetAll().ToList(); Assert.AreEqual(0, newSubClassDb.Count); } }
public async Task Connection_parent_child() { var query = @" { parentEntitiesConnection(first:2, after: '0') { totalCount edges { cursor node { property children { property } } } items { property children { property } } } } "; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ChildEntity { Property = "Value2" }; var entity3 = new ChildEntity { Property = "Value3" }; entity1.Children.Add(entity2); entity1.Children.Add(entity3); var entity4 = new ParentEntity { Property = "Value4" }; var entity5 = new ChildEntity { Property = "Value5" }; entity4.Children.Add(entity5); using (var database = await sqlInstance.Build()) { var result = await RunQuery(database, query, null, null, entity1, entity2, entity3, entity4, entity5); ObjectApprover.Verify(result); } }
public void Entity_updates_StateModel_by_events() { var id = ParentEntityId.Generate(); var parent = new ParentEntity(new ParentCreated(id, "test parent", DateTime.UtcNow)); parent.StateModel.Id.Should().Be(id); parent.StateModel.Name.Should().Be("test parent"); }
public virtual void OnDeath() { for (int i = 0; i < appliedEffects.Count; i++) { appliedEffects[i].OnDeath(); } ParentEntity.OnDeath(); }
public string SummarizeToString() { string Ret = ""; Ret += ParentEntity.GetName() + "." + Attribute.Name; return(Ret); }
public void Entity_updates_StateModel() { var id = ParentEntityId.Generate(); var parent = new ParentEntity(id, "test parent"); parent.StateModel.Id.Should().Be(id); parent.StateModel.Name.Should().Be("test parent"); }
public EntityNavigator(ParentEntity Entity, DataPersistance Dp, bool CallSetDefault) { _Entity = Entity; _Entity.CurrentNavigator = this; _Entity._Original = (ParentEntity)MetaData.Clone(_Entity); _Entity.Dp = Dp; DoInit(CallSetDefault); }
public void VerifyPolymorphicQuery() { var childVersion1 = new ParentEntity { Id = id1, Data = "x" }; Assert.AreEqual(childVersion1, AuditReader().CreateQuery().ForEntitiesAtRevision(typeof(ParentEntity), 1).GetSingleResult()); CollectionAssert.IsEmpty(AuditReader().CreateQuery().ForEntitiesAtRevision(typeof(ChildEntity), 1).GetResultList()); }
public EntityNavigator(IBaseUINavigator BaseUINavigator, ParentEntity Entity, bool CallSetDefault) { _Entity = Entity; _Entity.CurrentNavigator = this; _Entity.BaseUINavigator = BaseUINavigator; _Entity._Original = (ParentEntity)MetaData.Clone(_Entity); DoInit(CallSetDefault); }
public void DeleteSelf() { var ms = this.GetMappingSet(); ms.RemoveMapping(ms.GetMappingFor(this)); ParentEntity.RemoveComponent(this); Specification.RemoveImplementation(this); }
public PaymentMethodAccounting Calculate(Func <PaymentEntity, bool> paymentPredicate = null) { paymentPredicate = paymentPredicate ?? new Func <PaymentEntity, bool>((p) => true); var paymentMethods = ParentEntity.GetPaymentMethods(); var totalDue = ParentEntity.ProductInformation.Price / Rate; var paid = 0m; var cryptoPaid = 0.0m; int precision = 8; var totalDueNoNetworkCost = Money.Coins(Extensions.RoundUp(totalDue, precision)); bool paidEnough = paid >= Extensions.RoundUp(totalDue, precision); int txRequired = 0; _ = ParentEntity.GetPayments() .Where(p => p.Accounted && paymentPredicate(p)) .OrderBy(p => p.ReceivedTime) .Select(_ => { var txFee = _.GetValue(paymentMethods, GetId(), _.NetworkFee); paid += _.GetValue(paymentMethods, GetId()); if (!paidEnough) { totalDue += txFee; } paidEnough |= Extensions.RoundUp(paid, precision) >= Extensions.RoundUp(totalDue, precision); if (GetId() == _.GetPaymentMethodId()) { cryptoPaid += _.GetCryptoPaymentData().GetValue(); txRequired++; } return(_); }).ToArray(); var accounting = new PaymentMethodAccounting(); accounting.TxCount = txRequired; if (!paidEnough) { txRequired++; totalDue += GetTxFee(); } accounting.TotalDue = Money.Coins(Extensions.RoundUp(totalDue, precision)); accounting.Paid = Money.Coins(Extensions.RoundUp(paid, precision)); accounting.TxRequired = txRequired; accounting.CryptoPaid = Money.Coins(Extensions.RoundUp(cryptoPaid, precision)); accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero); accounting.DueUncapped = accounting.TotalDue - accounting.Paid; accounting.NetworkFee = accounting.TotalDue - totalDueNoNetworkCost; var minimumTotalDueSatoshi = Math.Max(1.0m, accounting.TotalDue.Satoshi * (1.0m - ((decimal)ParentEntity.PaymentTolerance / 100.0m))); accounting.MinimumTotalDue = Money.Satoshis(minimumTotalDueSatoshi); return(accounting); }
public void GetHashCode_should_be_the_state_hashcode() { var id = ParentEntityId.Generate(); var state = new ParentState().Apply(new ParentCreated(id, "test parent", DateTime.UtcNow)); var parent = new ParentEntity(Enumerable.Empty <IEvent>(), state); parent.GetHashCode().Should().Be(parent.StateModel.GetHashCode()); }
public async Task Query_Cyclic() { var query = @" { childEntities (orderBy: {path: ""property""}) { property parent { property children { property parent { property } } } } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ChildEntity { Property = "Value2", Parent = entity1 }; var entity3 = new ChildEntity { Property = "Value3", Parent = entity1 }; entity1.Children.Add(entity2); entity1.Children.Add(entity3); var entity4 = new ParentEntity { Property = "Value4" }; var entity5 = new ChildEntity { Property = "Value5", Parent = entity4 }; entity4.Children.Add(entity5); await using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, false, entity1, entity2, entity3, entity4, entity5); await Verifier.Verify(result); }
/* * Act * * Returns: true: Any additional derived Act methods can be executed. False: the * derived act methods should not be executed. * Purpose: This is the main method where this behavior modifies its parent. This should * be overridden for each base class, and the value of the super Act() methods needs to be * true for the derived class to execute. This moves the player in the direction of the waypoint */ public override bool Act() { if (!base.Act()) { return(false); } // If we have made it here, then a waypoint has been set, // and this enemy is in a patrol state. We can then focus on // moving to our set waypoint // If the player is stuck if (lastPosition.x == ParentEntity.Rigidbody2D.position.x && lastPosition.y == ParentEntity.Rigidbody2D.position.y) { // increment a count of this stuckCount++; // If stuck for more than 5 frames, shift it up to break free if (stuckCount > 5) { ParentEntity.ShiftUp(); } } // reset this counter else { stuckCount = 0; } // get the last position for comparisons if we are not stuck // used to compared with the next frame if (stuckCount == 0) { lastPosition = ParentEntity.Rigidbody2D.position; } // Since we do not know anything meaningful about the map right now, we always jump ParentEntity.Jump(); // We need to determine which direction to move in. Vector2 currentPosition = ParentEntity.transform.position; Vector2 waypoint = ParentEntity.MovementWaypoint; // We move to the right if (waypoint.x > currentPosition.x) { ParentEntity.MoveRight(); } // we move to the left else { ParentEntity.MoveLeft(); } return(true); }
public static BaseEntity CloneAll(BaseEntity SourceObj) { TableDef td = GetTableDef(SourceObj.GetType()); BaseEntity DestObj = (BaseEntity)BaseFactory .CreateInstance(td._ClassType); IRuleInitUI px = DestObj as IRuleInitUI; //CallLoadRule = CallLoadRule && px != null; DestObj.EntityOnLoad = true; try { DestObj = SourceObj.ShallowClone(); if (td.ChildEntities.Count > 0) { foreach (EntityCollDef ecd in td.ChildEntities) { //IEntityCollection cols = (IEntityCollection) // Activator.CreateInstance(ecd.ConstructionType); //if (ecd.mi.MemberType == MemberTypes.Field) // ((FieldInfo)ecd.mi).SetValue(DestObj, cols); //else // ((PropertyInfo)ecd.mi).SetValue(DestObj, cols, null); IList SrcCols = ecd.GetValue(SourceObj); IList DestCols = (IList)ecd.CreateNew((BusinessEntity)DestObj); ((IEntityCollection)DestCols).OnLoad = true; foreach (BusinessEntity obj in SrcCols) { DestCols.Add(CloneAll(obj)); } ((IEntityCollection)DestCols).OnLoad = false; } } //if (CallLoadRule) //{ // px.AfterLoadFound(); // BaseFramework.DoEntityAction(DestObj, enEntityActionMode.AfterLoadFound); //} ParentEntity pe = DestObj as ParentEntity; if (pe != null) { pe.AfterClone((ParentEntity)SourceObj); } } finally { DestObj.EntityOnLoad = false; DestObj.DataChanged(); } return(DestObj); }
public void Issue194Repro() { using (var context = GetContext()) { var parent = new ParentEntity(); parent.Id = "parent"; var child = context.ChildEntities.Create(); child.Code = "child"; child.Description = "Some description"; child.Parent = parent; context.ChildEntities.Add(child); context.SaveChanges(); } using (var context = GetContext()) { var parent = context.ParentEntities.First(); var modifiedChild = new ChildEntity { Parent = parent, Code = "child", Description = "A new description for the existing child" }; var existingChild = context.ChildEntities.First(); context.DeleteObject(existingChild); context.ChildEntities.Add(modifiedChild); context.SaveChanges(); } }