ExceptionHelperTest.cs 996 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Reactive;
  6. using Xunit;
  7. namespace ReactiveTests.Tests
  8. {
  9. public class ExceptionHelperTest
  10. {
  11. private Exception _errors;
  12. [Fact]
  13. public void ExceptionHelper_TrySetException_Empty()
  14. {
  15. var ex = new InvalidOperationException();
  16. Assert.True(ExceptionHelper.TrySetException(ref _errors, ex));
  17. Assert.Equal(ex, _errors);
  18. }
  19. [Fact]
  20. public void ExceptionHelper_TrySetException_Not_Empty()
  21. {
  22. var ex1 = new InvalidOperationException();
  23. _errors = ex1;
  24. var ex2 = new NotSupportedException();
  25. Assert.False(ExceptionHelper.TrySetException(ref _errors, ex2));
  26. Assert.Equal(ex1, _errors);
  27. }
  28. }
  29. }