You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageExtensionTest.cs 2.5 KiB

5 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using DotNetCore.CAP.Messages;
  4. using Xunit;
  5. namespace DotNetCore.CAP.Test
  6. {
  7. public class MessageExtensionTest
  8. {
  9. [Fact]
  10. public void GetIdTest()
  11. {
  12. var msgId = Guid.NewGuid().ToString();
  13. var header = new Dictionary<string, string>()
  14. {
  15. [Headers.MessageId] = msgId
  16. };
  17. var message = new Message(header, null);
  18. Assert.NotNull(message.GetId());
  19. Assert.Equal(msgId,message.GetId());
  20. }
  21. [Fact]
  22. public void GetNameTest()
  23. {
  24. var msgName = Guid.NewGuid().ToString();
  25. var header = new Dictionary<string, string>()
  26. {
  27. [Headers.MessageName] = msgName
  28. };
  29. var message = new Message(header, null);
  30. Assert.NotNull(message.GetName());
  31. Assert.Equal(msgName, message.GetName());
  32. }
  33. [Fact]
  34. public void GetCallbackNameTest()
  35. {
  36. var callbackName = Guid.NewGuid().ToString();
  37. var header = new Dictionary<string, string>()
  38. {
  39. [Headers.CallbackName] = callbackName
  40. };
  41. var message = new Message(header, null);
  42. Assert.NotNull(message.GetCallbackName());
  43. Assert.Equal(callbackName, message.GetCallbackName());
  44. }
  45. [Fact]
  46. public void GetGroupTest()
  47. {
  48. var group = Guid.NewGuid().ToString();
  49. var header = new Dictionary<string, string>()
  50. {
  51. [Headers.Group] = group
  52. };
  53. var message = new Message(header, null);
  54. Assert.NotNull(message.GetGroup());
  55. Assert.Equal(group, message.GetGroup());
  56. }
  57. [Fact]
  58. public void GetCorrelationSequenceTest()
  59. {
  60. var seq = 1;
  61. var header = new Dictionary<string, string>()
  62. {
  63. [Headers.CorrelationSequence] = seq.ToString()
  64. };
  65. var message = new Message(header, null);
  66. Assert.Equal(seq, message.GetCorrelationSequence());
  67. }
  68. [Fact]
  69. public void HasExceptionTest()
  70. {
  71. var exception = "exception message";
  72. var header = new Dictionary<string, string>()
  73. {
  74. [Headers.Exception] = exception
  75. };
  76. var message = new Message(header, null);
  77. Assert.True(message.HasException());
  78. }
  79. }
  80. }