Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Aug 27, 2024
2 parents fa62c90 + 9679c27 commit a373fcb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.5
8.0.6
25 changes: 15 additions & 10 deletions src/Moryx.AbstractionLayer.Products.Endpoints/ProductConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public IProductType ConvertProductBack(ProductModel source, ProductType converte
private void UpdateCollection(IList value, IEnumerable<PartModel> parts)
{
// Track which part links are still represented by the models
var unused = new List<IProductPartLink>(value.OfType<IProductPartLink>());
var oldParts = new List<IProductPartLink>(value.OfType<IProductPartLink>());
// Iterate over the part models
// Create or update the part links
var elemType = value.GetType().GetInterfaces()
Expand All @@ -269,22 +269,27 @@ private void UpdateCollection(IList value, IEnumerable<PartModel> parts)
if (partModel is null)
continue;

var match = unused.Find(r => r.Id == partModel?.Id);
if (match == null)
var oldPartMatch = oldParts.Find(r => r.Id == partModel.Id);
// new partlink
if (oldPartMatch == null)
{
match = (IProductPartLink)Activator.CreateInstance(elemType);
value.Add(match);
oldPartMatch = (IProductPartLink)Activator.CreateInstance(elemType);
oldPartMatch.Product = _productManagement.LoadType(partModel.Product.Id);
value.Add(oldPartMatch);
}
//modified reference
else if (oldPartMatch.Product.Id != partModel.Product.Id)
oldPartMatch.Product = _productManagement.LoadType(partModel.Product.Id);
else
unused.Remove(match);
// existing unchanged partlink: do not delete at the end
oldParts.Remove(oldPartMatch);

EntryConvert.UpdateInstance(match, partModel.Properties);
match.Product = _productManagement.LoadType(partModel.Product.Id);
EntryConvert.UpdateInstance(oldPartMatch, partModel.Properties);
}

// Clear all values no longer present in the model
foreach (var link in unused)
value.Remove(link);
foreach (var part in oldParts)
value.Remove(part);
}

private void UpdateReference(IProductPartLink value, PartModel part)
Expand Down
12 changes: 4 additions & 8 deletions src/Moryx.Model/Repositories/Proxy/RepositoryProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static RepositoryProxyBuilder()
public Type Build(Type repoApi)
{
// Check interface
ValidateRepositoryApi(repoApi, false);
ValidateRepositoryApi(repoApi);

var proxyName = CreateProxyName(repoApi);

Expand Down Expand Up @@ -86,7 +86,7 @@ public Type Build(Type repoApi)
public Type Build(Type repoApi, Type repoImpl)
{
// Check interface
ValidateRepositoryApi(repoApi, false);
ValidateRepositoryApi(repoApi);

var proxyName = CreateProxyName(repoImpl);

Expand Down Expand Up @@ -198,19 +198,15 @@ private static bool IsModificationTracked(Type entityType)
return typeof(IModificationTrackedEntity).IsAssignableFrom(entityType);
}

private static void ValidateRepositoryApi(Type repoApi, bool additionalApis)
private static void ValidateRepositoryApi(Type repoApi)
{
if (!repoApi.IsInterface)
{
throw new InvalidOperationException($"'{repoApi.Name}' is not an interface");
}

var repoInterfaces = repoApi.GetInterfaces();
if (additionalApis && (repoInterfaces.Length > 2 || repoInterfaces.First().GetGenericTypeDefinition() != typeof(IRepository<>)))
{
throw new InvalidOperationException($"'{repoApi.Name}' API does not inherit from IRepository<T>");
}
else if (repoInterfaces.Length != 2 || repoInterfaces.First().GetGenericTypeDefinition() != typeof(IRepository<>))
if (!repoInterfaces.Any(rI => rI.IsGenericType && rI.GetGenericTypeDefinition() == typeof(IRepository<>)))
{
throw new InvalidOperationException($"'{repoApi.Name}' API does not inherit from IRepository<T>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public IProductType LoadType(ProductIdentity identity)
public long SaveType(IProductType modifiedInstance)
{
var saved = Storage.SaveType(modifiedInstance);
RaiseProductChanged(modifiedInstance);
//reload the object for correct references
var loadedType = Storage.LoadType(saved);
RaiseProductChanged(loadedType);

return saved;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ public void ForwardBackwardProductConversionWithoutInformationLoss(DummyProductT
// - If there are ProductPartLinks the ProductManagement should be called
var targetDummyTypeWithParts = recoveredOriginal as DummyProductTypeWithParts;
if (targetDummyTypeWithParts?.ProductPartLink?.Product is not null)
{
_productManagerMock.Verify(pm => pm.LoadType(targetDummyTypeWithParts.ProductPartLink.Product.Id));
_productManagerMock.Verify(pm => pm.LoadType(targetDummyTypeWithParts.ProductPartLinkEnumerable.First().Product.Id));
}
}

private static bool HasChangedProperties<T>(object A, object B)
Expand Down

0 comments on commit a373fcb

Please sign in to comment.