protected override void EstablishContext() { controlDevice = A.Fake <ISpiControlDevice>(); controlDevice .CallsTo(device => device.Control(A <uint> .Ignored, A <SpiTransferControlStructure[]> .Ignored)) .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; buffer = A.Fake <ISpiTransferBuffer>(); buffer .CallsTo(b => b.ControlStructure) .Returns(controlStructure); // setup fake collection to return our "prepared" fake buffer collection = A.Fake <ISpiTransferBufferCollection>(); collection .CallsTo(c => c.Length) .Returns(1); collection .CallsTo(c => c.GetEnumerator()) .ReturnsLazily(call => new List <ISpiTransferBuffer> { buffer }.GetEnumerator()); }
protected override void EstablishContext() { controlDeviceMock = new Mock <ISpiControlDevice>(); controlDevice = controlDeviceMock.Object; controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; bufferMock = new Mock <ISpiTransferBuffer>(); buffer = bufferMock.Object; bufferMock.Setup(x => x.ControlStructure).Returns(controlStructure); // setup fake collection to return our "prepared" fake buffer collectionMock = new Mock <ISpiTransferBufferCollection>(); collection = collectionMock.Object; collectionMock.Setup(x => x.Length).Returns(1); collectionMock.Setup(x => x.GetEnumerator()).Returns(new List <ISpiTransferBuffer> { buffer }.GetEnumerator()); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDevice = A.Fake <ISpiControlDevice>(); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDevice = new Mock <ISpiControlDevice>().Object; connection = new NativeSpiConnection(controlDevice, settings); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDeviceMock = new Mock <ISpiControlDevice>(); controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <uint> .IsAny)).Callback((uint a, uint b) => { controlRequest = a; controlData = b; }); controlDevice = controlDeviceMock.Object; }
protected override void EstablishContext() { // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; controlDeviceMock = new Mock <ISpiControlDevice>(); controlDevice = controlDeviceMock.Object; controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); bufferMock = new Mock <ISpiTransferBuffer>(); buffer = bufferMock.Object; bufferMock.Setup(x => buffer.ControlStructure).Returns(controlStructure); }
protected override void EstablishContext() { // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; controlDevice = A.Fake <ISpiControlDevice>(); A.CallTo(() => controlDevice.Control(A <uint> .Ignored, ref controlStructure)) .WithAnyArguments() .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); buffer = A.Fake <ISpiTransferBuffer>(); A.CallTo(() => buffer.ControlStructure) .Returns(controlStructure); }
/// <summary> /// Creates a new instance of the <see cref="NativeSpiConnection"/> class and initializes it. /// </summary> /// <param name="deviceFile">A control device (IOCTL) to the device file (e.g. /dev/spidev0.0).</param> /// <param name="settings">Connection settings</param> public NativeSpiConnection(ISpiControlDevice deviceFile, SpiConnectionSettings settings) : this(deviceFile) { Init(settings); }
/// <summary> /// Creates a new instance of the <see cref="NativeSpiConnection"/> class. /// </summary> /// <param name="deviceFile">A control device (IOCTL) to the device file (e.g. /dev/spidev0.0).</param> public NativeSpiConnection(ISpiControlDevice deviceFile) { this.deviceFile = deviceFile; }
protected override void EstablishContext() { // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; controlDevice = A.Fake<ISpiControlDevice>(); controlDevice .CallsTo(device => device.Control(A<uint>.Ignored, ref controlStructure)) .WithAnyArguments() .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); buffer = A.Fake<ISpiTransferBuffer>(); buffer .CallsTo(b => b.ControlStructure) .Returns(controlStructure); }
protected override void EstablishContext() { controlDevice = A.Fake<ISpiControlDevice>(); controlDevice .CallsTo(device => device.Control(A<uint>.Ignored, A<SpiTransferControlStructure[]>.Ignored)) .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; buffer = A.Fake<ISpiTransferBuffer>(); buffer .CallsTo(b => b.ControlStructure) .Returns(controlStructure); // setup fake collection to return our "prepared" fake buffer collection = A.Fake<ISpiTransferBufferCollection>(); collection .CallsTo(c => c.Length) .Returns(1); collection .CallsTo(c => c.GetEnumerator()) .ReturnsLazily(call => new List<ISpiTransferBuffer>{buffer}.GetEnumerator()); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDevice = A.Fake<ISpiControlDevice>(); connection = new NativeSpiConnection(controlDevice, settings); }