mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 07:07:24 +08:00
Fix BaseEventState.MemberwiseClone() to pass Parent to Activator.CreateInstance (#3361)
* Fix BaseEventState.MemberwiseClone() to pass Parent to Activator.CreateInstance Co-authored-by: romanett <7413710+romanett@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
This commit is contained in:
@@ -83,7 +83,7 @@ namespace Opc.Ua
|
||||
/// </returns>
|
||||
public new object MemberwiseClone()
|
||||
{
|
||||
var clone = (BaseEventState)Activator.CreateInstance(GetType());
|
||||
var clone = (BaseEventState)Activator.CreateInstance(GetType(), Parent);
|
||||
return CloneChildren(clone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,4 +139,59 @@ namespace Opc.Ua.Core.Tests.Stack.State
|
||||
return CreateDefaultNodeStateType(systemType) is NodeState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for BaseEventState.MemberwiseClone.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Category("BaseEventState")]
|
||||
[SetCulture("en-us")]
|
||||
[SetUICulture("en-us")]
|
||||
[Parallelizable]
|
||||
public class BaseEventStateTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verify that MemberwiseClone works correctly for BaseEventState.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void MemberwiseCloneBaseEventStateSucceeds()
|
||||
{
|
||||
var parent = new BaseObjectState(null);
|
||||
var eventState = new BaseEventState(parent);
|
||||
|
||||
var clone = (BaseEventState)eventState.MemberwiseClone();
|
||||
|
||||
Assert.That(clone, Is.Not.Null);
|
||||
Assert.That(clone.Parent, Is.SameAs(parent));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that MemberwiseClone works correctly for BaseEventState with null parent.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void MemberwiseCloneBaseEventStateWithNullParentSucceeds()
|
||||
{
|
||||
var eventState = new BaseEventState(null);
|
||||
|
||||
var clone = (BaseEventState)eventState.MemberwiseClone();
|
||||
|
||||
Assert.That(clone, Is.Not.Null);
|
||||
Assert.That(clone.Parent, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that Clone works correctly for derived event types.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CloneNonExclusiveLimitAlarmStateSucceeds()
|
||||
{
|
||||
var parent = new BaseObjectState(null);
|
||||
var alarmState = new NonExclusiveLimitAlarmState(parent);
|
||||
|
||||
var clone = (NonExclusiveLimitAlarmState)alarmState.Clone();
|
||||
|
||||
Assert.That(clone, Is.Not.Null);
|
||||
Assert.That(clone.Parent, Is.SameAs(parent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user