Deleting an instance only undeployed it from the site and set the state to NotDeployed, leaving an orphan record that could never be removed — the state-transition matrix rejected delete from NotDeployed. Delete now removes the instance record entirely (deployment history, snapshot, attribute/alarm overrides, and connection bindings go with it), and is permitted from any state.
119 lines
3.2 KiB
C#
119 lines
3.2 KiB
C#
using ScadaLink.Commons.Types.Enums;
|
|
|
|
namespace ScadaLink.DeploymentManager.Tests;
|
|
|
|
/// <summary>
|
|
/// WP-4: Tests for instance state transition matrix.
|
|
/// </summary>
|
|
public class StateTransitionValidatorTests
|
|
{
|
|
// ── Deploy transitions ──
|
|
|
|
[Theory]
|
|
[InlineData(InstanceState.NotDeployed)]
|
|
[InlineData(InstanceState.Enabled)]
|
|
[InlineData(InstanceState.Disabled)]
|
|
public void CanDeploy_AllStates_ReturnsTrue(InstanceState state)
|
|
{
|
|
Assert.True(StateTransitionValidator.CanDeploy(state));
|
|
}
|
|
|
|
// ── Disable transitions ──
|
|
|
|
[Fact]
|
|
public void CanDisable_WhenEnabled_ReturnsTrue()
|
|
{
|
|
Assert.True(StateTransitionValidator.CanDisable(InstanceState.Enabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanDisable_WhenDisabled_ReturnsFalse()
|
|
{
|
|
Assert.False(StateTransitionValidator.CanDisable(InstanceState.Disabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanDisable_WhenNotDeployed_ReturnsFalse()
|
|
{
|
|
Assert.False(StateTransitionValidator.CanDisable(InstanceState.NotDeployed));
|
|
}
|
|
|
|
// ── Enable transitions ──
|
|
|
|
[Fact]
|
|
public void CanEnable_WhenDisabled_ReturnsTrue()
|
|
{
|
|
Assert.True(StateTransitionValidator.CanEnable(InstanceState.Disabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanEnable_WhenEnabled_ReturnsFalse()
|
|
{
|
|
Assert.False(StateTransitionValidator.CanEnable(InstanceState.Enabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanEnable_WhenNotDeployed_ReturnsFalse()
|
|
{
|
|
Assert.False(StateTransitionValidator.CanEnable(InstanceState.NotDeployed));
|
|
}
|
|
|
|
// ── Delete transitions ──
|
|
|
|
[Fact]
|
|
public void CanDelete_WhenEnabled_ReturnsTrue()
|
|
{
|
|
Assert.True(StateTransitionValidator.CanDelete(InstanceState.Enabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanDelete_WhenDisabled_ReturnsTrue()
|
|
{
|
|
Assert.True(StateTransitionValidator.CanDelete(InstanceState.Disabled));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanDelete_WhenNotDeployed_ReturnsTrue()
|
|
{
|
|
Assert.True(StateTransitionValidator.CanDelete(InstanceState.NotDeployed));
|
|
}
|
|
|
|
// ── ValidateTransition ──
|
|
|
|
[Fact]
|
|
public void ValidateTransition_ValidDeploy_ReturnsNull()
|
|
{
|
|
var error = StateTransitionValidator.ValidateTransition(InstanceState.NotDeployed, "deploy");
|
|
Assert.Null(error);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateTransition_InvalidEnable_ReturnsError()
|
|
{
|
|
var error = StateTransitionValidator.ValidateTransition(InstanceState.Enabled, "enable");
|
|
Assert.NotNull(error);
|
|
Assert.Contains("not allowed", error);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateTransition_InvalidDisable_ReturnsError()
|
|
{
|
|
var error = StateTransitionValidator.ValidateTransition(InstanceState.Disabled, "disable");
|
|
Assert.NotNull(error);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateTransition_ValidDeleteOnNotDeployed_ReturnsNull()
|
|
{
|
|
var error = StateTransitionValidator.ValidateTransition(InstanceState.NotDeployed, "delete");
|
|
Assert.Null(error);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateTransition_UnknownOperation_ReturnsError()
|
|
{
|
|
var error = StateTransitionValidator.ValidateTransition(InstanceState.Enabled, "unknown");
|
|
Assert.NotNull(error);
|
|
}
|
|
}
|