public void ReceiveOrSend_GivenTheThreadIsAbortedBeforePreparationCompletes_JustThrowsTheException() { // Arrange preparationInlet.Setup(p => p.Send(It.IsAny <string>())).Throws <ThreadInterruptedException>(); // Act ThreadInterruptedException exception = null; try { valve.ReceiveOrSend("Not gonna make it..."); } catch (ThreadInterruptedException e) { exception = e; } // Assert preparationInlet.Verify(p => p.Send(It.IsAny <string>()), Times.Once); resultOutlet.Verify(r => r.Receive(), Times.Never); exception.Should().NotBeNull(); }
public void ReceiveOrSend_GivenTheThreadIsAbortedDuringReceivingAResult_FlushesTheMessageToBeSentAndThrowsTheException() { // Arrange resultOutlet.Setup(r => r.Receive()).Throws <ThreadInterruptedException>(); // Act ThreadInterruptedException exception = null; try { valve.ReceiveOrSend("Not gonna make it..."); } catch (ThreadInterruptedException e) { exception = e; } // Assert preparationInlet.Verify(p => p.Send(It.IsAny <string>()), Times.Once); resultOutlet.Verify(r => r.Receive(), Times.Once); flushOutlet.Verify(f => f.ReceiveImmediately(), Times.Once); exception.Should().NotBeNull(); }
public void ReceiveOrSend_GivenThereIsNeitherASenderNorAReceiver_BlocksIndefinitely() { // Act ThreadInterruptedException exception = null; var thread = ThreadHelpers.RunInThread(() => { try { valvedPipe.Valve.ReceiveOrSend("Hello"); } catch (ThreadInterruptedException e) { exception = e; } }); Thread.Sleep(1000); thread.Interrupt(); Thread.Sleep(500); // Assert exception.Should().NotBeNull(); }