Skip to content
Draft
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
43 changes: 25 additions & 18 deletions src/devices/Mcp23xxx/tests/EnableDisableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ namespace Iot.Device.Mcp23xxx.Tests
{
public class EnableDisableTests : Mcp23xxxTest
{
private static readonly GpioDriverMock s_driverMock = new GpioDriverMock();
private static readonly GpioController s_gpioMock = new GpioController(s_driverMock);

[Theory]
[MemberData(nameof(ResetTestDevices))]
public void InitialResetState(TestDevice testDevice)
{
s_gpioMock.OpenPin(1, PinMode.Input);
Assert.Equal(PinValue.Low, s_gpioMock.Read(1));
s_gpioMock.SetPinMode(1, PinMode.Output);
GpioDriverMock driverMock = testDevice.ResetDriverMock!;
GpioController gpioMock = new GpioController(driverMock);
gpioMock.OpenPin(1, PinMode.Input);
Assert.Equal(PinValue.Low, gpioMock.Read(1));
gpioMock.SetPinMode(1, PinMode.Output);
testDevice.Device.Enable();
s_gpioMock.SetPinMode(1, PinMode.Input);
Assert.Equal(PinValue.High, s_gpioMock.Read(1));
s_gpioMock.ClosePin(1);
s_driverMock.Reset();
gpioMock.SetPinMode(1, PinMode.Input);
Assert.Equal(PinValue.High, gpioMock.Read(1));
gpioMock.ClosePin(1);
driverMock.Reset();
}

[Theory]
Expand Down Expand Up @@ -84,23 +83,31 @@ public static TheoryData<TestDevice> ResetTestDevices
TheoryData<TestDevice> devices = new TheoryData<TestDevice>();

// Don't want to use the same bus mock for each
GpioDriverMock driverMock = new GpioDriverMock();
I2cDeviceMock i2c = new I2cDeviceMock(1);
devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock));
devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
i2c = new I2cDeviceMock(1);
devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock));
devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
i2c = new I2cDeviceMock(2);
devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock));
devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
i2c = new I2cDeviceMock(2);
devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock));
devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock));

driverMock = new GpioDriverMock();
SpiDeviceMock spi = new SpiDeviceMock(1);
devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock));
devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
spi = new SpiDeviceMock(1);
devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock));
devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
spi = new SpiDeviceMock(2);
devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock));
devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock));
driverMock = new GpioDriverMock();
spi = new SpiDeviceMock(2);
devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock));
devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock));
return devices;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,22 @@ public struct TestDevice
public Mcp23xxx Device { get; }
public Mcp23xxxChipMock ChipMock { get; }
public GpioController Controller { get; }
public GpioDriverMock? ResetDriverMock { get; }

public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock)
{
Device = device;
ChipMock = chipMock;
Controller = new GpioController(Device);
ResetDriverMock = null;
}

public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock, GpioDriverMock resetDriverMock)
{
Device = device;
ChipMock = chipMock;
Controller = new GpioController(Device);
ResetDriverMock = resetDriverMock;
}
}

Expand Down
Loading