RunnableSessionTokenTests.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Xunit.Abstractions;
  2. namespace UnitTests_Parallelizable.ApplicationTests.RunnableTests;
  3. /// <summary>
  4. /// Tests for RunnableSessionToken class.
  5. /// </summary>
  6. public class RunnableSessionTokenTests (ITestOutputHelper output)
  7. {
  8. private readonly ITestOutputHelper _output = output;
  9. [Fact]
  10. public void RunnableSessionToken_Constructor_SetsRunnable ()
  11. {
  12. // Arrange
  13. Runnable<int> runnable = new ();
  14. // Act
  15. RunnableSessionToken token = new (runnable);
  16. // Assert
  17. Assert.NotNull (token.Runnable);
  18. Assert.Same (runnable, token.Runnable);
  19. }
  20. [Fact]
  21. public void RunnableSessionToken_Runnable_CanBeSetToNull ()
  22. {
  23. // Arrange
  24. Runnable<int> runnable = new ();
  25. RunnableSessionToken token = new (runnable);
  26. // Act
  27. token.Runnable = null;
  28. // Assert
  29. Assert.Null (token.Runnable);
  30. }
  31. [Fact]
  32. public void RunnableSessionToken_Dispose_ThrowsIfRunnableNotNull ()
  33. {
  34. // Arrange
  35. Runnable<int> runnable = new ();
  36. RunnableSessionToken token = new (runnable);
  37. // Act & Assert
  38. Assert.Throws<InvalidOperationException> (() => token.Dispose ());
  39. }
  40. [Fact]
  41. public void RunnableSessionToken_Dispose_SucceedsIfRunnableIsNull ()
  42. {
  43. // Arrange
  44. Runnable<int> runnable = new ();
  45. RunnableSessionToken token = new (runnable);
  46. token.Runnable = null;
  47. // Act & Assert - should not throw
  48. token.Dispose ();
  49. }
  50. }