Skip to content
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
15 changes: 0 additions & 15 deletions MobiFlight/ExecutionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,21 +815,6 @@ public void updateModuleSettings(Dictionary<string, ArcazeModuleSettings> arcaze
/// </summary>
private void ExecuteConfig()
{
if (
#if ARCAZE
!arcazeCache.Available() &&
#endif
#if MOBIFLIGHT
!mobiFlightCache.Available() &&

#endif
!joystickManager.JoysticksConnected() &&

!midiBoardManager.AreMidiBoardsConnected()
) return;



// this is kind of sempahore to prevent multiple execution
// in fact I don't know if this needs to be done in C#
if (isExecuting)
Expand Down
62 changes: 62 additions & 0 deletions MobiFlightUnitTests/MobiFlight/ExecutionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,67 @@ public void FrontendUpdateTimer_Execute_ConcurrentDictionaryModification_ShouldN
Assert.Fail($"Unexpected exceptions occurred: {exceptionSummary}");
}
}

[TestMethod]
public void ExecuteConfig_WithNoControllersConnected_ShouldStillExecuteConfigItems()
{
// Arrange
var outputConfigItem = new OutputConfigItem
{
GUID = Guid.NewGuid().ToString(),
Active = true,
Name = "TestOutput",
Source = new VariableSource()
{
MobiFlightVariable = new MobiFlightVariable() { Name = "TestVar", Number = 123.45 }
},
Device = new OutputConfig.CustomDevice() { CustomName = "TestDevice" },
DeviceType = "InputAction" // Special type that doesn't require physical devices
};

var project = new Project();
project.ConfigFiles.Add(new ConfigFile()
{
ConfigItems = { outputConfigItem }
});
_executionManager.Project = project;

// Verify no controllers are connected
Assert.IsFalse(_executionManager.ModulesAvailable(), "No MobiFlight modules and/or Arcaze Boards should be connected");
Assert.IsFalse(_executionManager.GetJoystickManager().JoysticksConnected(), "No joysticks should be connected");
Assert.IsFalse(_executionManager.GetMidiBoardManager().AreMidiBoardsConnected(), "No midi controllers should be connected.");

// Set up the variable so the config item has data to read
_executionManager.getMobiFlightModuleCache().SetMobiFlightVariable(
new MobiFlightVariable() { Name = "TestVar", Number = 123.45 });

// Get access to the updatedValues dictionary via reflection
var updatedValuesField = typeof(ExecutionManager).GetField("updatedValues",
BindingFlags.NonPublic | BindingFlags.Instance);
var updatedValues = (Dictionary<string, IConfigItem>)updatedValuesField.GetValue(_executionManager);

var initialUpdatedValuesCount = updatedValues.Count;

// Act - Instead of relying on timer, directly call ExecuteConfig via reflection
_executionManager.Start(); // This sets up the execution manager state

// Use reflection to call the private ExecuteConfig method directly
var executeConfigMethod = typeof(ExecutionManager).GetMethod("ExecuteConfig",
BindingFlags.NonPublic | BindingFlags.Instance);
Assert.IsNotNull(executeConfigMethod, "ExecuteConfig method should exist");

executeConfigMethod.Invoke(_executionManager, null);

// Assert - The config item should be processed and cloned into updatedValues
Assert.IsTrue(updatedValues.ContainsKey(outputConfigItem.GUID),
"Config item should be cloned and added to updatedValues when processed");

var clonedConfigItem = updatedValues[outputConfigItem.GUID] as OutputConfigItem;
Assert.IsNotNull(clonedConfigItem, "Updated config item should be an OutputConfigItem");
Assert.AreEqual("123.45", clonedConfigItem.Value,
"Cloned config item should display the correct variable value");
Assert.AreEqual("123.45", clonedConfigItem.RawValue,
"Cloned config item should have the correct raw value");
}
}
}
Loading