mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 10:58:28 +00:00
- Introduced `FakeCrestronEnvironment` and `FakeEthernetHelper` for testing purposes. - Implemented `InMemoryCrestronDataStore` to facilitate unit tests for data storage. - Created `DebugServiceTests` to validate the behavior of debug-related services. - Added project files for unit tests targeting .NET 9.0 with necessary dependencies. - Developed production adapters (`CrestronConsoleAdapter`, `CrestronDataStoreAdapter`, `CrestronEnvironmentAdapter`, `CrestronEthernetAdapter`) to interface with the Crestron SDK. - Updated `Debug` class to utilize injected service abstractions instead of direct SDK calls. - Enhanced `ControlSystem` initialization to register service adapters before usage.
59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using PepperDash.Core.Abstractions;
|
|
|
|
namespace PepperDash.Core.Tests.Fakes;
|
|
|
|
/// <summary>
|
|
/// In-memory ICrestronDataStore backed by a dictionary.
|
|
/// Use in unit tests to verify that keys are read from and written to the store correctly.
|
|
/// </summary>
|
|
public class InMemoryCrestronDataStore : ICrestronDataStore
|
|
{
|
|
private readonly Dictionary<string, object> _store = new();
|
|
|
|
public bool Initialized { get; private set; }
|
|
|
|
public void InitStore() => Initialized = true;
|
|
|
|
public bool TryGetLocalInt(string key, out int value)
|
|
{
|
|
if (_store.TryGetValue(key, out var raw) && raw is int i)
|
|
{
|
|
value = i;
|
|
return true;
|
|
}
|
|
value = 0;
|
|
return false;
|
|
}
|
|
|
|
public bool SetLocalInt(string key, int value)
|
|
{
|
|
_store[key] = value;
|
|
return true;
|
|
}
|
|
|
|
public bool SetLocalUint(string key, uint value)
|
|
{
|
|
_store[key] = (int)value;
|
|
return true;
|
|
}
|
|
|
|
public bool TryGetLocalBool(string key, out bool value)
|
|
{
|
|
if (_store.TryGetValue(key, out var raw) && raw is bool b)
|
|
{
|
|
value = b;
|
|
return true;
|
|
}
|
|
value = false;
|
|
return false;
|
|
}
|
|
|
|
public bool SetLocalBool(string key, bool value)
|
|
{
|
|
_store[key] = value;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Seeds a key for testing read paths.</summary>
|
|
public void Seed(string key, object value) => _store[key] = value;
|
|
}
|