Skip to content

Commit

Permalink
merge manually pull #143
Browse files Browse the repository at this point in the history
merge manually pull #143
  • Loading branch information
JonathanMagnan committed Apr 23, 2020
1 parent d7631c6 commit 41ad939
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
20 changes: 20 additions & 0 deletions GraphDiff/GraphDiff.Tests.Shared/Models/TestModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ public class NullableKeyModel
public Guid? Id { get; set; }
}

public class TestNodeForIListMultiAddition : Entity
{
// If you change this to ICollection, then test TestIListOwnedCollectionAdditionDoesNotMultiAdd will pass
public IList<TestSubNodeForIListMultiAddition> SubNodes { get; set; }
}

public class TestSubNodeForIListMultiAddition
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 1)]
public int TestNodeForIListMultiAdditionId { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 2)]
public int OtherKeyId { get; set; }

public string Title { get; set; }
}

// Generic Collection models:
public class SimpleTitleModel
{
Expand Down
8 changes: 7 additions & 1 deletion GraphDiff/GraphDiff.Tests.Shared/TestDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class TestDbContext : DbContext
public IDbSet<OneToManyAssociatedModel> OneToManyAssociatedModels { get; set; }
public IDbSet<OneToManyOwnedModel> OneToManyOwnedModels { get; set; }



public IDbSet<MultiKeyModel> MultiKeyModels { get; set; }

public IDbSet<RootEntity> RootEntities { get; set; }
Expand All @@ -26,10 +28,14 @@ public class TestDbContext : DbContext
public IDbSet<InternalKeyModel> InternalKeyModels { get; set; }
public IDbSet<NullableKeyModel> NullableKeyModels { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
public IDbSet<TestNodeForIListMultiAddition> TestNodesForIListMultiAddition { get; set; }
public IDbSet<TestSubNodeForIListMultiAddition> TestSubNodesForIListMultiAddition { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// second tier mappings

modelBuilder.Entity<TestNodeForIListMultiAddition>().HasMany(p => p.SubNodes).WithRequired().HasForeignKey(s => s.TestNodeForIListMultiAdditionId).WillCascadeOnDelete(true);
modelBuilder.Entity<TestNode>().HasOptional(p => p.OneToOneAssociated).WithOptionalPrincipal(p => p.OneParent);
modelBuilder.Entity<TestNode>().HasMany(p => p.OneToManyAssociated).WithOptional(p => p.OneParent);
modelBuilder.Entity<TestNode>().HasOptional(p => p.OneToOneOwned).WithRequired(p => p.OneParent).WillCascadeOnDelete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ namespace RefactorThis.GraphDiff.Tests.Tests
[TestClass]
public class OwnedCollectionBehaviours : TestBase
{
[TestMethod]
public void TestIListOwnedCollectionAdditionDoesNotMultiAdd()
{
TestNodeForIListMultiAddition rootNode = new TestNodeForIListMultiAddition()
{
Title = "rootnode",
SubNodes = new List<TestSubNodeForIListMultiAddition>()
};


using (TestDbContext context = new TestDbContext())
{
context.TestNodesForIListMultiAddition.Add(rootNode);
context.SaveChanges();
}

rootNode.SubNodes.Add(new TestSubNodeForIListMultiAddition() { TestNodeForIListMultiAdditionId = rootNode.Id, OtherKeyId = 1, Title = "sub1" });
rootNode.SubNodes.Add(new TestSubNodeForIListMultiAddition() { TestNodeForIListMultiAdditionId = rootNode.Id, OtherKeyId = 2, Title = "sub2" });

using (TestDbContext context = new TestDbContext())
{
var result = context.UpdateGraph(rootNode, mapping => mapping.OwnedCollection(p => p.SubNodes));

Assert.AreEqual(2, result.SubNodes.Count);
Assert.AreEqual(1, result.SubNodes.Count(s => s.Title.Equals("sub1")));
Assert.AreEqual(1, result.SubNodes.Count(s => s.Title.Equals("sub2")));
}
}

[TestMethod]
public void ShouldUpdateItemInOwnedCollection()
{
Expand Down
4 changes: 3 additions & 1 deletion GraphDiff/GraphDiff.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "GraphDiff.Tests.Shared", "G
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphDiff.Tests.NetStandard21", "GraphDiff.Tests.NetStandard21\GraphDiff.Tests.NetStandard21.csproj", "{082C0151-CBE3-476B-B40C-0D909E83D198}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z.EntityFrameworkGraphDiff.labEF6", "Z.EntityFrameworkGraphDiff.labEF6\Z.EntityFrameworkGraphDiff.labEF6.csproj", "{1AD6B94A-4A02-4DD9-8AEB-76AE73A6E20A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Z.EntityFrameworkGraphDiff.labEF6", "Z.EntityFrameworkGraphDiff.labEF6\Z.EntityFrameworkGraphDiff.labEF6.csproj", "{1AD6B94A-4A02-4DD9-8AEB-76AE73A6E20A}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
GraphDiff.Tests.Shared\GraphDiff.Tests.Shared.projitems*{082c0151-cbe3-476b-b40c-0d909e83d198}*SharedItemsImports = 5
GraphDiff.Shared\GraphDiff.Shared.projitems*{13fca06a-1cb3-4584-8421-f15730d0a0f7}*SharedItemsImports = 5
GraphDiff.Tests.Shared\GraphDiff.Tests.Shared.projitems*{36762487-8275-440b-8e19-aada325652e4}*SharedItemsImports = 4
GraphDiff.Shared\GraphDiff.Shared.projitems*{c97b2c2c-b005-438b-8d0c-ee3557d03041}*SharedItemsImports = 13
GraphDiff.Shared\GraphDiff.Shared.projitems*{d9725b00-669c-409d-9ab8-c674710c8e5d}*SharedItemsImports = 4
Expand Down

0 comments on commit 41ad939

Please sign in to comment.