Skip to content

Commit

Permalink
Merge pull request #372 from PHOENIXCONTACT/fix/missing-allow-multiple
Browse files Browse the repository at this point in the history
Port #371 to release 8
  • Loading branch information
Toxantron authored Feb 16, 2024
2 parents f63bce0 + 62ef8d8 commit 0867b24
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Moryx.AbstractionLayer.Resources
/// <summary>
/// Members of the given interfaces are available outside of the resource management
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ResourceAvailableAsAttribute : Attribute
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Moryx.AbstractionLayer.Resources;

namespace Moryx.Resources.Management.Tests
{
public interface ISecondNonResourceInterface
{
}

[ResourceAvailableAs(typeof(ISecondNonResourceInterface))]
public class DerivedResourceWithNewProxy : SimpleResource, ISecondNonResourceInterface
{
public override int MultiplyFoo(int factor)
{
return Foo *= factor + 2;
}
}
}
15 changes: 15 additions & 0 deletions src/Tests/Moryx.Resources.Management.Tests/TypeControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ public void UseBaseProxyForDerivedType()
Assert.AreEqual(baseProxy.GetType(), proxy.GetType());
}

[Test]
public void UseNewProxyForDerivedTypeWithNewInterface()
{
// Arrange: Create instance
var baseInstance = new SimpleResource { Id = 2 };
var instance = new DerivedResourceWithNewProxy { Id = 3 };

// Act: Build Proxy
var baseProxy = _typeController.GetProxy(baseInstance);
var proxy = _typeController.GetProxy(instance);

// Assert: Make sure proxy is still the base type
Assert.That(baseProxy.GetType(), Is.Not.EqualTo(proxy.GetType()));
}

[Test]
public void CallMethodOnProxy()
{
Expand Down

0 comments on commit 0867b24

Please sign in to comment.