Files
UA-.NETStandard/Tests/Opc.Ua.PubSub.Tests/Configuration/PubSubStateMachineTests.StateChangeMethods.cs
Marc Schier 38227cbeab Fix boolean default should be false instead of true (#3679)
* Fix boolean default should be false instead of true
* Update MigrationGuide for boolean default value changes

Clarified the impact of the boolean default value change and updated the migration guide to reflect the correct initialization requirements.
2026-04-20 16:40:43 +02:00

134 lines
6.8 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System;
using NUnit.Framework;
using Opc.Ua.PubSub.Configuration;
using Opc.Ua.Tests;
namespace Opc.Ua.PubSub.Tests.Configuration
{
public partial class PubSubStateMachineTests
{
[Test(Description = "Validate Call Enable on Disabled object")]
public void ValidateEnableOnDisabled()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
PubSubConfigurationDataType pubSub = uaPubSubApplication.UaPubSubConfigurator
.PubSubConfiguration;
configurator.Disable(pubSub);
Assert.That(configurator.Enable(pubSub), Is.EqualTo(StatusCodes.Good));
}
[Test(Description = "Validate Call Enable on Enabled object")]
public void ValidateEnableOnOperational()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
PubSubConfigurationDataType pubSub = uaPubSubApplication.UaPubSubConfigurator
.PubSubConfiguration;
configurator.Enable(pubSub);
Assert.That(configurator.Enable(pubSub), Is.EqualTo(StatusCodes.BadInvalidState));
}
[Test(Description = "Validate Call Disable on Enabled object")]
public void ValidateDisableOnEnabled()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
PubSubConfigurationDataType pubSub = uaPubSubApplication.UaPubSubConfigurator
.PubSubConfiguration;
configurator.Enable(pubSub);
Assert.That(configurator.Disable(pubSub), Is.EqualTo(StatusCodes.Good));
}
[Test(Description = "Validate Call Disable on Disabled object")]
public void ValidateDisableOnDisabled()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
PubSubConfigurationDataType pubSub = uaPubSubApplication.UaPubSubConfigurator
.PubSubConfiguration;
configurator.Disable(pubSub);
Assert.That(configurator.Disable(pubSub), Is.EqualTo(StatusCodes.BadInvalidState));
}
[Test(Description = "Validate Call Enable on null object")]
public void ValidateEnableOnNUll()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
Assert.Throws<ArgumentException>(
() => configurator.Enable(null),
"The Enable method does not throw exception when called with null parameter.");
}
[Test(Description = "Validate Call Disable on null object")]
public void ValidateDisableOnNUll()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
Assert.Throws<ArgumentException>(
() => configurator.Disable(null),
"The Disable method does not throw exception when called with null parameter.");
}
[Test(Description = "Validate Call Enable on non existing object")]
public void ValidateEnableOnNonExisting()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
var nonExisting = new PubSubConfigurationDataType { Enabled = true };
Assert.Throws<ArgumentException>(
() => configurator.Enable(nonExisting),
"The Enable method does not throw exception when called with non existing parameter.");
}
[Test(Description = "Validate Call Disable on non existing object")]
public void ValidateDisableOnNonExisting()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
using var uaPubSubApplication = UaPubSubApplication.Create(m_publisherConfigurationFile, telemetry);
UaPubSubConfigurator configurator = uaPubSubApplication.UaPubSubConfigurator;
var nonExisting = new PubSubConfigurationDataType { Enabled = true };
Assert.Throws<ArgumentException>(
() => configurator.Disable(nonExisting),
"The Disable method does not throw exception when called with non existing parameter.");
}
}
}