public void ConcurrentBeginWritesSecondFails() { // GIVEN: a QueuedStream var m = new Mock <Stream>(MockBehavior.Strict); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var c = new MockAsyncResult("C"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, trace); m.SetupBeginWrite(b, new ApplicationException("**ERROR**"), trace); m.SetupBeginWrite(c, trace); m.SetupEndWrite(c, trace); // WHEN: i make three concurrent calls to BeginWrite // AND : the second concurrent operation fails in BeginWrite q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null); q.BeginWrite(b.Data, 0, b.Data.Length, ar => { var ex = Assert.Throws <ApplicationException>(() => q.EndWrite(ar)); trace.AppendFormat("EndWrite({0})", ex.Message); }, null); q.BeginWrite(c.Data, 0, c.Data.Length, q.EndWrite, null); a.Complete(trace); c.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other // AND : and EndWrite of the second operation fails with and exception Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(**ERROR**)EndWrite(**ERROR**)BeginWrite(C) Complete(C) EndWrite(C)")); m.VerifyAll(); }
public void ConcurrentBeginWritesFirstEndWriteFails() { // GIVEN: a QueuedStream var m = new Mock <Stream>(MockBehavior.Strict); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, new ApplicationException("**ERROR**"), trace); m.SetupBeginWrite(b, trace); m.SetupEndWrite(b, trace); // WHEN: i make two concurrent calls to BeginWrite // AND : the first concurrent operation fails in EndWrite q.BeginWrite(a.Data, 0, a.Data.Length, ar => Assert.Throws <ApplicationException>(() => q.EndWrite(ar)), null); q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null); a.Complete(trace); b.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other // AND : and EndWrite of the first operation fails with an exception Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(**ERROR**)BeginWrite(B) Complete(B) EndWrite(B)")); m.VerifyAll(); }
public void EndWrite() { var q = new QueuedStream(new MemoryStream()); var a = new MockAsyncResult("A"); Assert.Throws <ArgumentException>(() => q.EndWrite(a)); }
public static void SetupBeginWrite(this Mock <Stream> mock, MockAsyncResult ar, StringBuilder trace) { mock.Setup(x => x.BeginWrite(ar.Data, 0, ar.Data.Length, It.IsAny <AsyncCallback>(), It.IsAny <object>())) .Returns <byte[], int, int, AsyncCallback, object>((b, o, l, cb, os) => { trace.AppendFormat("BeginWrite({0})", ar); ar.Callback = cb; return(ar); }); }
public void EndRead() { var m = new Mock <Stream>(); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); m.Setup(x => x.EndRead(a)); q.EndRead(a); m.VerifyAll(); }
public void BeginRead() { var m = new Mock <Stream>(); var q = new QueuedStream(m.Object); var d = new byte[] { 1, 2, 3 }; var a = new MockAsyncResult("A"); m.Setup(x => x.BeginRead(d, 0, d.Length, It.IsAny <AsyncCallback>(), null)) .Returns <byte[], int, int, AsyncCallback, object>((b, o, l, c, s) => a); Assert.That(q.BeginRead(d, 0, d.Length, ar => { }, null), Is.EqualTo(a)); m.VerifyAll(); }
public void ConcurrentBeginWrites() { // GIVEN: a QueuedStream var m = new Mock <Stream>(); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, trace); m.SetupBeginWrite(b, trace); m.SetupEndWrite(b, trace); // WHEN: i make two concurrent calls to BeginWrite q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null); q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null); a.Complete(trace); b.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(B) Complete(B) EndWrite(B)")); m.VerifyAll(); }
public void ConcurrentBeginWritesSecondFails() { // GIVEN: a QueuedStream var m = new Mock<Stream>(MockBehavior.Strict); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var c = new MockAsyncResult("C"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, trace); m.SetupBeginWrite(b, new ApplicationException("**ERROR**"), trace); m.SetupBeginWrite(c, trace); m.SetupEndWrite(c, trace); // WHEN: i make three concurrent calls to BeginWrite // AND : the second concurrent operation fails in BeginWrite q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null); q.BeginWrite(b.Data, 0, b.Data.Length, ar => { var ex = Assert.Throws<ApplicationException>(() => q.EndWrite(ar)); trace.AppendFormat("EndWrite({0})", ex.Message); }, null); q.BeginWrite(c.Data, 0, c.Data.Length, q.EndWrite, null); a.Complete(trace); c.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other // AND : and EndWrite of the second operation fails with and exception Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(**ERROR**)EndWrite(**ERROR**)BeginWrite(C) Complete(C) EndWrite(C)")); m.VerifyAll(); }
public void ConcurrentBeginWritesFirstEndWriteFails() { // GIVEN: a QueuedStream var m = new Mock<Stream>(MockBehavior.Strict); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, new ApplicationException("**ERROR**"), trace); m.SetupBeginWrite(b, trace); m.SetupEndWrite(b, trace); // WHEN: i make two concurrent calls to BeginWrite // AND : the first concurrent operation fails in EndWrite q.BeginWrite(a.Data, 0, a.Data.Length, ar => Assert.Throws<ApplicationException>(() => q.EndWrite(ar)), null); q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null); a.Complete(trace); b.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other // AND : and EndWrite of the first operation fails with an exception Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(**ERROR**)BeginWrite(B) Complete(B) EndWrite(B)")); m.VerifyAll(); }
public void ConcurrentBeginWrites() { // GIVEN: a QueuedStream var m = new Mock<Stream>(); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); var b = new MockAsyncResult("B"); var trace = new StringBuilder(); m.SetupBeginWrite(a, trace); m.SetupEndWrite(a, trace); m.SetupBeginWrite(b, trace); m.SetupEndWrite(b, trace); // WHEN: i make two concurrent calls to BeginWrite q.BeginWrite(a.Data, 0, a.Data.Length, q.EndWrite, null); q.BeginWrite(b.Data, 0, b.Data.Length, q.EndWrite, null); a.Complete(trace); b.Complete(trace); // THEN: i expect BeginWrite of the underlying stream to be called one after each other Assert.That(trace.ToString(), Is.EqualTo("BeginWrite(A) Complete(A) EndWrite(A)BeginWrite(B) Complete(B) EndWrite(B)")); m.VerifyAll(); }
public void EndWrite() { var q = new QueuedStream(new MemoryStream()); var a = new MockAsyncResult("A"); Assert.Throws<ArgumentException>(() => q.EndWrite(a)); }
public void EndRead() { var m = new Mock<Stream>(); var q = new QueuedStream(m.Object); var a = new MockAsyncResult("A"); m.Setup(x => x.EndRead(a)); q.EndRead(a); m.VerifyAll(); }
public static void SetupEndWrite(this Mock<Stream> mock, MockAsyncResult ar, StringBuilder rec) { mock.Setup(x => x.EndWrite(ar)).Callback(() => rec.AppendFormat("EndWrite({0})", ar)); }
public static void SetupEndWrite(this Mock <Stream> mock, MockAsyncResult ar, StringBuilder rec) { mock.Setup(x => x.EndWrite(ar)).Callback(() => rec.AppendFormat("EndWrite({0})", ar)); }
public static void SetupBeginWrite(this Mock <Stream> mock, MockAsyncResult ar, Exception error, StringBuilder trace) { mock.Setup(x => x.BeginWrite(ar.Data, 0, ar.Data.Length, It.IsAny <AsyncCallback>(), It.IsAny <object>())) .Callback(() => trace.AppendFormat("BeginWrite({0})", error.Message)) .Throws(error); }
public static void SetupBeginWrite(this Mock<Stream> mock, MockAsyncResult ar, StringBuilder trace) { mock.Setup(x => x.BeginWrite(ar.Data, 0, ar.Data.Length, It.IsAny<AsyncCallback>(), It.IsAny<object>())) .Returns<byte[], int, int, AsyncCallback, object>((b, o, l, cb, os) => { trace.AppendFormat("BeginWrite({0})", ar); ar.Callback = cb; return ar; }); }
public static void SetupBeginWrite(this Mock<Stream> mock, MockAsyncResult ar, Exception error, StringBuilder trace) { mock.Setup(x => x.BeginWrite(ar.Data, 0, ar.Data.Length, It.IsAny<AsyncCallback>(), It.IsAny<object>())) .Callback(() => trace.AppendFormat("BeginWrite({0})", error.Message)) .Throws(error); }
public static void SetupEndWrite(this Mock <Stream> mock, MockAsyncResult ar, Exception error, StringBuilder trace) { mock.Setup(x => x.EndWrite(ar)).Callback(() => trace.AppendFormat("EndWrite({0})", error.Message)).Throws(error); }
public static void SetupEndWrite(this Mock<Stream> mock, MockAsyncResult ar, Exception error, StringBuilder trace) { mock.Setup(x => x.EndWrite(ar)).Callback(() => trace.AppendFormat("EndWrite({0})", error.Message)).Throws(error); }
public void BeginRead() { var m = new Mock<Stream>(); var q = new QueuedStream(m.Object); var d = new byte[] { 1, 2, 3 }; var a = new MockAsyncResult("A"); m.Setup(x => x.BeginRead(d, 0, d.Length, It.IsAny<AsyncCallback>(), null)) .Returns<byte[], int, int, AsyncCallback, object>((b, o, l, c, s) => a); Assert.That(q.BeginRead(d, 0, d.Length, ar => { }, null), Is.EqualTo(a)); m.VerifyAll(); }