private static QAcidRunner<Unit> ClientFaults(Broadcaster broadcaster) { return from canAct in "broadcaster has clients".If( () => GetBroadcastersClients(broadcaster).Count > 0, from client in "faulting client".Input(MGen.ChooseFrom(GetBroadcastersClients(broadcaster))) from raise in "raise fault".Act(() => client.Raise(c => c.Faulted += null, client, EventArgs.Empty)) from spec in"client is removed from broadcaster" .Spec(() => !GetBroadcastersClients(broadcaster).Contains(client)) select Unit.Instance) select Unit.Instance; }
private static QAcidRunner<Unit> Broadcast(Broadcaster broadcaster, ThreadInfo info) { return from canact in "when threadswitch is false".If( () => info.ThreadSwitch == false, from start in "start broadcasting".Act( () => { info.ThreadSwitch = true; info.ExceptionFromThread = null; info.Thread = new Thread( () => info.ExceptionFromThread = GetExceptionThrownBy( () => broadcaster.Broadcast(null))); info.Thread.Start(); }) from spec in "Broadcast : No Exception is thrown".Spec(() => info.ExceptionFromThread == null) select Unit.Instance) select Unit.Instance; }
private static QAcidRunner<Unit> RegisterClient(IClientProxyFactory clientFactory, Broadcaster broadcaster) { return from sleepTime in "sleeptime".Input(MGen.Int(0, 10)) from client in "new client".Input(() => MockRepository.GenerateMock<IClientProxy>()) from register in "Broadcaster.Register".Act( () => { clientFactory .Stub(f => f.CreateClientProxyForCurrentContext(null)) .IgnoreArguments() .Return(client) .Repeat.Once(); client .Stub(c => c.SendNotificationAsynchronously(null)) .IgnoreArguments() .WhenCalled(obj => Thread.Sleep(sleepTime)); broadcaster.Register(); }) from spec in "client is added to broadcaster".Spec(() => GetBroadcastersClients(broadcaster).Contains(client)) select Unit.Instance; }
public static List<IClientProxy> GetBroadcastersClients(Broadcaster broadcaster) { var clientsFieldInfo = typeof(Broadcaster).GetField("clients", BindingFlags.NonPublic | BindingFlags.Instance); return (List<IClientProxy>)clientsFieldInfo.GetValue(broadcaster); }
private static QAcidRunner<Unit> StopBroadcasting(Broadcaster broadcaster, ThreadInfo info) { return from canact in "when threadswitch is true".If( () => info.ThreadSwitch, from stop in "stop broadcasting".Act( () => { info.Thread.Join(); info.Thread = null; info.ThreadSwitch = false; }) from spec in "StopBroadcasting : No Exception is thrown".Spec(() => info.ExceptionFromThread == null) select Unit.Instance) select Unit.Instance; }