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

Adds the AllowMultiple flag to the ResourceAvailableAs attribute #222

Merged
merged 1 commit into from
Feb 20, 2024
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
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;
}
}
}
16 changes: 16 additions & 0 deletions src/Tests/Moryx.Resources.Management.Tests/TypeControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void Setup()
typeof(DerivedResource),
typeof(ReferenceResource),
typeof(NonPublicResource),
typeof(DerivedResourceWithNewProxy),
typeof(ResourceWithImplicitApi)
});

Expand Down Expand Up @@ -79,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
Loading