Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderedItemList is not properly cloned. Assembler preserves the state… #59

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using CDP4Common.EngineeringModelData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing header

using NUnit.Framework;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using statements go inside namespace

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace CDP4Common.NetCore.Tests.Poco
{
class PossibleFiniteStateListTestFixture
{
[Test]
public void OrderedItemListIsNotClonedCorrectlyTest()
{
var pfs1 = new PossibleFiniteState(Guid.NewGuid(), null, null);
pfs1.Name = "state1";
pfs1.ShortName = "s1";

var pfs2 = new PossibleFiniteState(Guid.NewGuid(), null, null);
pfs2.Name = "state1";
pfs2.ShortName = "s1";

var pfsList = new PossibleFiniteStateList(Guid.NewGuid(), null, null);
pfsList.Name = "PossibleFiniteStateList1";
pfsList.ShortName = "PFSL1";

pfsList.PossibleState.Add(pfs1);
pfsList.PossibleState.Add(pfs2);

var dtoOrderedItemListOriginal = pfsList.PossibleState.ToDtoOrderedItemList().ToList();

var pfsListClone = pfsList.Clone(true);
var dtoOrderedItemListClone = pfsListClone.PossibleState.ToDtoOrderedItemList().ToList();

Assert.AreNotEqual(dtoOrderedItemListOriginal[0].K, dtoOrderedItemListClone[0].K);
Assert.AreEqual(dtoOrderedItemListOriginal[0].V, dtoOrderedItemListClone[0].V);
Assert.AreNotEqual(dtoOrderedItemListOriginal[1].K, dtoOrderedItemListClone[1].K);
Assert.AreEqual(dtoOrderedItemListOriginal[1].V, dtoOrderedItemListClone[1].V);
}
}
}
41 changes: 41 additions & 0 deletions CDP4Dal.NetCore.Tests/AssemblerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,46 @@ public async Task VerifyThatModelIsDeletedWhenSetupIsDeleted()
await assembler.Synchronize(new List<Dto.Thing> { sitedirdto });
Assert.AreEqual(1, assembler.Cache.Count);
}

[Test]
public async Task VerifyThatSynchronizationPreservesKeysOfOrderedItemList()
{
var assembler = new Assembler(this.uri);

var simpleUnit = new Dto.SimpleUnit(Guid.NewGuid(), 1) { Name = "Unit", ShortName = "unit" };
var ratioScale = new Dto.RatioScale(Guid.NewGuid(), 1) { Name = "Ration", ShortName = "ratio", NumberSet = NumberSetKind.INTEGER_NUMBER_SET };
ratioScale.Unit = simpleUnit.Iid;

var simpleQuantityKind1 = new Dto.SimpleQuantityKind(Guid.NewGuid(), 1) { Name = "Kind1", ShortName = "kind1", Symbol = "symbol" };
simpleQuantityKind1.DefaultScale = ratioScale.Iid;
var orderedItem1 = new OrderedItem() { K = 1, V = simpleQuantityKind1.Iid };

var simpleQuantityKind2 = new Dto.SimpleQuantityKind(Guid.NewGuid(), 1) { Name = "Kind2", ShortName = "kind2", Symbol = "symbol" };
simpleQuantityKind2.DefaultScale = ratioScale.Iid;
var orderedItem2 = new OrderedItem() { K = 2, V = simpleQuantityKind2.Iid };

this.siteRdl.Unit.Add(simpleUnit.Iid);
this.siteRdl.Scale.Add(ratioScale.Iid);
this.siteRdl.BaseQuantityKind.Add(orderedItem1);
this.siteRdl.BaseQuantityKind.Add(orderedItem2);

this.testInput.Add(simpleUnit);
this.testInput.Add(ratioScale);
this.testInput.Add(simpleQuantityKind1);
this.testInput.Add(simpleQuantityKind2);

await assembler.Synchronize(this.testInput);

Lazy<Thing> lazySiteRdl;
assembler.Cache.TryGetValue(new CacheKey(this.siteRdl.Iid, null), out lazySiteRdl);
var siteRdl = lazySiteRdl.Value as SiteReferenceDataLibrary;
var orderedItemList = siteRdl.BaseQuantityKind.ToDtoOrderedItemList();

Assert.AreEqual(1, orderedItemList.ToList()[0].K);
Assert.AreEqual(simpleQuantityKind1.Iid, orderedItemList.ToList()[0].V);

Assert.AreEqual(2, orderedItemList.ToList()[1].K);
Assert.AreEqual(simpleQuantityKind2.Iid, orderedItemList.ToList()[1].V);
}
}
}