protected override void EstablishContext() { controlDevice = A.Fake <IControlDevice>(); 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()); }
public void Should_it_write_the_max_speed_in_Hz_to_the_control_device() { UInt32 speed = SPEED_IN_HZ; controlDevice .CallsTo(device => device.Control(NativeSpiConnection.SPI_IOC_WR_MAX_SPEED_HZ, ref speed)) .MustHaveHappened(Repeated.Exactly.Once); controlDevice .CallsTo(device => device.Control(NativeSpiConnection.SPI_IOC_RD_MAX_SPEED_HZ, ref speed)) .MustHaveHappened(Repeated.Exactly.Once); }
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 <IControlDevice>(); 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); }
public void Should_the_buffers_control_structure_be_sent_to_the_IOCTL_device() { controlDevice .CallsTo(device => device.Control(SPI_IOC_MESSAGE_1, A <SpiTransferControlStructure[]> .That.Matches(s => Predicate(s)))) .MustHaveHappened(Repeated.Exactly.Once); }
public void Should_the_buffers_control_structure_be_sent_to_the_IOCTL_device() { controlDevice .CallsTo(device => device.Control(SPI_IOC_MESSAGE_1, ref controlStructure)) .MustHaveHappened(Repeated.Exactly.Once); }
protected override void EstablishContext() { controlDevice = A.Fake<IControlDevice>(); 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() { // 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<IControlDevice>(); 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); }