From 0a2edef1125e9be07097ecd8ceb4d02b03ba4baa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 16:50:25 +0000 Subject: [PATCH 1/3] Initial plan From fb7d3ae70407f4230daa95b99ed5bb8a89802156 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 16:54:41 +0000 Subject: [PATCH 2/3] Fix build error: static property cannot access instance fields Co-authored-by: krwq <660048+krwq@users.noreply.github.com> --- .../Mcp23xxx/tests/EnableDisableTests.cs | 69 ++++++++++++------- src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs | 21 ++++++ 2 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs index 1c49a2e861..5e89f5e67b 100644 --- a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs +++ b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs @@ -10,27 +10,21 @@ namespace Iot.Device.Mcp23xxx.Tests { public class EnableDisableTests : Mcp23xxxTest { - private readonly GpioDriverMock _driverMock; - private readonly GpioController _gpioMock; - - public EnableDisableTests() - { - _driverMock = new GpioDriverMock(); - _gpioMock = new GpioController(_driverMock); - } - [Theory] [MemberData(nameof(ResetTestDevices))] public void InitialResetState(TestDevice testDevice) { - _gpioMock.OpenPin(1, PinMode.Input); - Assert.Equal(PinValue.Low, _gpioMock.Read(1)); - _gpioMock.SetPinMode(1, PinMode.Output); + GpioController gpioMock = testDevice.ResetController!; + GpioDriverMock driverMock = testDevice.ResetDriverMock!; + + gpioMock.OpenPin(1, PinMode.Input); + Assert.Equal(PinValue.Low, gpioMock.Read(1)); + gpioMock.SetPinMode(1, PinMode.Output); testDevice.Device.Enable(); - _gpioMock.SetPinMode(1, PinMode.Input); - Assert.Equal(PinValue.High, _gpioMock.Read(1)); - _gpioMock.ClosePin(1); - _driverMock.Reset(); + gpioMock.SetPinMode(1, PinMode.Input); + Assert.Equal(PinValue.High, gpioMock.Read(1)); + gpioMock.ClosePin(1); + driverMock.Reset(); } [Theory] @@ -89,24 +83,51 @@ public static TheoryData ResetTestDevices { TheoryData devices = new TheoryData(); + // Create separate driver mock for each device to avoid parallel test issues + GpioDriverMock driverMock; + GpioController gpioController; + // Don't want to use the same bus mock for each I2cDeviceMock i2c = new I2cDeviceMock(1); - devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(_driverMock)), i2c.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + i2c = new I2cDeviceMock(1); - devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(_driverMock)), i2c.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + i2c = new I2cDeviceMock(2); - devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(_driverMock)), i2c.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + i2c = new I2cDeviceMock(2); - devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(_driverMock)), i2c.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); SpiDeviceMock spi = new SpiDeviceMock(1); - devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(_driverMock)), spi.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + spi = new SpiDeviceMock(1); - devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(_driverMock)), spi.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + spi = new SpiDeviceMock(2); - devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(_driverMock)), spi.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + spi = new SpiDeviceMock(2); - devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(_driverMock)), spi.DeviceMock)); + driverMock = new GpioDriverMock(); + gpioController = new GpioController(driverMock); + devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + return devices; } } diff --git a/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs b/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs index d787000d44..5e7d09e696 100644 --- a/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs +++ b/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs @@ -48,11 +48,32 @@ public struct TestDevice public Mcp23xxxChipMock ChipMock { get; } public GpioController Controller { get; } + /// + /// Optional GpioDriverMock for tests that use reset pin functionality. + /// + public GpioDriverMock? ResetDriverMock { get; } + + /// + /// Optional GpioController (backed by ResetDriverMock) for tests that use reset pin functionality. + /// + public GpioController? ResetController { get; } + public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock) { Device = device; ChipMock = chipMock; Controller = new GpioController(Device); + ResetDriverMock = null; + ResetController = null; + } + + public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock, GpioDriverMock resetDriverMock, GpioController resetController) + { + Device = device; + ChipMock = chipMock; + Controller = new GpioController(Device); + ResetDriverMock = resetDriverMock; + ResetController = resetController; } } From 212b0358e2e57a807a642a92b508d35b08901269 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 16:56:37 +0000 Subject: [PATCH 3/3] Address code review: use same GpioController for device and test Co-authored-by: krwq <660048+krwq@users.noreply.github.com> --- src/devices/Mcp23xxx/tests/EnableDisableTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs index 5e89f5e67b..ca7bc376ce 100644 --- a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs +++ b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs @@ -91,42 +91,42 @@ public static TheoryData ResetTestDevices I2cDeviceMock i2c = new I2cDeviceMock(1); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: gpioController), i2c.DeviceMock, driverMock, gpioController)); i2c = new I2cDeviceMock(1); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: gpioController), i2c.DeviceMock, driverMock, gpioController)); i2c = new I2cDeviceMock(2); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: gpioController), i2c.DeviceMock, driverMock, gpioController)); i2c = new I2cDeviceMock(2); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: gpioController), i2c.DeviceMock, driverMock, gpioController)); SpiDeviceMock spi = new SpiDeviceMock(1); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: gpioController), spi.DeviceMock, driverMock, gpioController)); spi = new SpiDeviceMock(1); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: gpioController), spi.DeviceMock, driverMock, gpioController)); spi = new SpiDeviceMock(2); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: gpioController), spi.DeviceMock, driverMock, gpioController)); spi = new SpiDeviceMock(2); driverMock = new GpioDriverMock(); gpioController = new GpioController(driverMock); - devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock, gpioController)); + devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: gpioController), spi.DeviceMock, driverMock, gpioController)); return devices; }