PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Examples/Example.Clr4/AsyncSpecs.cs

https://github.com/machine/machine.specifications
C# | 35 lines | 28 code | 7 blank | 0 comment | 0 complexity | e5626b7c635258a8000017e37d6868a7 MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using FluentAssertions;
  5. using Machine.Specifications;
  6. namespace Example.Clr4
  7. {
  8. public class AsyncWorker
  9. {
  10. public Task<string> DoWorkAsync()
  11. {
  12. return Task.Factory.StartNew(() =>
  13. {
  14. Thread.Sleep(TimeSpan.FromMilliseconds(500));
  15. return "done";
  16. });
  17. }
  18. }
  19. class when_using_tasks_to_do_async_work
  20. {
  21. static AsyncWorker Worker;
  22. static string Result;
  23. Establish context = () => { Worker = new AsyncWorker(); };
  24. Because of = () => { Result = Worker.DoWorkAsync().Await(); };
  25. It should_wait_for_the_async_work_to_complete =
  26. () => Result.Should().Be("done");
  27. }
  28. }