public void EntityDiff_Loops_Over_Diffs() { // arrange var dbEntities = new HashSet <Dummy>(AllEntities.Select(e => new Dummy { Id = e.Id })); DiffableEntityHashSet <Dummy> diffs = new DiffableEntityHashSet <Dummy>(AllEntities, dbEntities, Relationships, null); // Assert & act foreach (EntityDiffPair <Dummy> diff in diffs.GetDiffs()) { Assert.Equal(diff.Entity.Id, diff.DatabaseValue.Id); Assert.NotEqual(diff.Entity, diff.DatabaseValue); Assert.Contains(diff.Entity, AllEntities); Assert.Contains(diff.DatabaseValue, dbEntities); } }
public void EntityDiff_GetAffected_Relationships() { // arrange var dbEntities = new HashSet <Dummy>(AllEntities.Select(e => new Dummy { Id = e.Id })); DiffableEntityHashSet <Dummy> diffs = new DiffableEntityHashSet <Dummy>(AllEntities, dbEntities, Relationships, null); // act var affectedThroughFirstToOne = diffs.GetAffected(d => d.FirstToOne).ToList(); var affectedThroughSecondToOne = diffs.GetAffected(d => d.SecondToOne).ToList(); var affectedThroughToMany = diffs.GetAffected(d => d.ToManies).ToList(); // assert affectedThroughFirstToOne.ForEach((entitiy) => Assert.Contains(entitiy, FirstToOnesEntities)); affectedThroughSecondToOne.ForEach((entitiy) => Assert.Contains(entitiy, SecondToOnesEntities)); affectedThroughToMany.ForEach((entitiy) => Assert.Contains(entitiy, ToManiesEntities)); }
public void EntityDiff_GetAffected_Attributes() { // arrange var dbEntities = new HashSet <Dummy>(AllEntities.Select(e => new Dummy { Id = e.Id })); var updatedAttributes = new Dictionary <PropertyInfo, HashSet <Dummy> > { { typeof(Dummy).GetProperty("SomeUpdatedProperty"), AllEntities } }; DiffableEntityHashSet <Dummy> diffs = new DiffableEntityHashSet <Dummy>(AllEntities, dbEntities, Relationships, updatedAttributes); // act var affectedThroughSomeUpdatedProperty = diffs.GetAffected(d => d.SomeUpdatedProperty).ToList(); var affectedThroughSomeNotUpdatedProperty = diffs.GetAffected(d => d.SomeNotUpdatedProperty).ToList(); // assert Assert.NotEmpty(affectedThroughSomeUpdatedProperty); Assert.Empty(affectedThroughSomeNotUpdatedProperty); }
public void EntityDiff_GetByRelationships() { // arrange var dbEntities = new HashSet <Dummy>(AllEntities.Select(e => new Dummy { Id = e.Id }).ToList()); DiffableEntityHashSet <Dummy> diffs = new DiffableEntityHashSet <Dummy>(AllEntities, dbEntities, Relationships, null); // act Dictionary <RelationshipAttribute, HashSet <Dummy> > toOnes = diffs.GetByRelationship <ToOne>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > toManies = diffs.GetByRelationship <ToMany>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > notTargeted = diffs.GetByRelationship <NotTargeted>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > allRelationships = diffs.AffectedRelationships; // Assert AssertRelationshipDictionaryGetters(allRelationships, toOnes, toManies, notTargeted); var allEntitiesWithAffectedRelationships = allRelationships.SelectMany(kvp => kvp.Value).ToList(); NoRelationshipsEntities.ToList().ForEach(e => { Assert.DoesNotContain(e, allEntitiesWithAffectedRelationships); }); var requestEntitiesFromDiff = diffs; requestEntitiesFromDiff.ToList().ForEach(e => { Assert.Contains(e, AllEntities); }); var databaseEntitiesFromDiff = diffs.GetDiffs().Select(d => d.DatabaseValue); databaseEntitiesFromDiff.ToList().ForEach(e => { Assert.Contains(e, dbEntities); }); }