PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 1using System.Threading;
 2using Bifrost.Commands;
 3using Machine.Specifications;
 4
 5namespace Bifrost.Specs.Commands.for_CommandContextManager
 6{
 7	[Subject(Subjects.establishing_context)]
 8	public class when_establishing_on_different_threads_with_same_command : given.a_command_context_manager
 9	{
10		static ICommandContext firstCommandContext;
11		static ICommandContext secondCommandContext;
12
13		Establish context = () =>
14		                    	{
15		                    		var resetEvent = new ManualResetEvent(false);
16		                    		var command = new SimpleCommand();
17		                    		firstCommandContext = Manager.EstablishForCommand(command);
18		                    		var thread = new Thread(
19		                    			() =>
20		                    				{
21		                    					secondCommandContext = Manager.EstablishForCommand(command);
22		                    					resetEvent.Reset();
23		                    				}
24		                    			);
25		                    		thread.Start();
26		                    		resetEvent.WaitOne(1000);
27		                    	};
28
29		It should_return_different_contexts = () => firstCommandContext.ShouldNotEqual(secondCommandContext);
30	}
31}