MapperTest.cs 831 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Xunit;
  4. namespace PetaPoco.Tests.Unit.Core
  5. {
  6. public class MapperTest
  7. {
  8. private class StringMapperTest : ConventionMapper
  9. {
  10. public StringMapperTest()
  11. {
  12. Thread.Sleep(2000);
  13. }
  14. }
  15. [Fact]
  16. public void Register_Ok()
  17. {
  18. NoThrowExceptionMethod();
  19. }
  20. private void NoThrowExceptionMethod()
  21. {
  22. var t1 = Task.Run(() => RegisterMethod());
  23. var t2 = Task.Run(() => RegisterMethod());
  24. Task.WaitAll(t1, t2);
  25. }
  26. private void RegisterMethod()
  27. {
  28. if (Mappers.GetMapper(typeof(string), null) == null) Mappers.Register(typeof(string), new StringMapperTest());
  29. }
  30. }
  31. }