PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Commands/for_CommandContextManager/when_establishing_on_different_threads_with_same_command.cs

#
C# | 31 lines | 28 code | 3 blank | 0 comment | 0 complexity | e68d4334c552cb74f63e3d7057cb247e MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System.Threading;
  2. using Bifrost.Commands;
  3. using Machine.Specifications;
  4. namespace Bifrost.Specs.Commands.for_CommandContextManager
  5. {
  6. [Subject(Subjects.establishing_context)]
  7. public class when_establishing_on_different_threads_with_same_command : given.a_command_context_manager
  8. {
  9. static ICommandContext firstCommandContext;
  10. static ICommandContext secondCommandContext;
  11. Establish context = () =>
  12. {
  13. var resetEvent = new ManualResetEvent(false);
  14. var command = new SimpleCommand();
  15. firstCommandContext = Manager.EstablishForCommand(command);
  16. var thread = new Thread(
  17. () =>
  18. {
  19. secondCommandContext = Manager.EstablishForCommand(command);
  20. resetEvent.Reset();
  21. }
  22. );
  23. thread.Start();
  24. resetEvent.WaitOne(1000);
  25. };
  26. It should_return_different_contexts = () => firstCommandContext.ShouldNotEqual(secondCommandContext);
  27. }
  28. }