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.
 
 
 

63 line
1.6 KiB

  1. using System;
  2. using DotNetCore.CAP.Internal;
  3. using DotNetCore.CAP.Models;
  4. using Newtonsoft.Json;
  5. using Xunit;
  6. namespace DotNetCore.CAP.Test
  7. {
  8. public class JsonContentSerializerTest
  9. {
  10. [Fact]
  11. public void CanSerialize()
  12. {
  13. //Arrange
  14. var fixtrue = Create();
  15. var message = new CapMessageDto
  16. {
  17. Id = "1",
  18. Content = "Content",
  19. CallbackName = "Callback",
  20. Timestamp = DateTime.Now
  21. };
  22. //Act
  23. var ret = fixtrue.Serialize(message);
  24. //Assert
  25. var expected = JsonConvert.SerializeObject(message);
  26. Assert.NotNull(ret);
  27. Assert.Equal(expected, ret);
  28. }
  29. [Fact]
  30. public void CanDeSerialize()
  31. {
  32. //Arrange
  33. var fixtrue = Create();
  34. var message = new CapMessageDto
  35. {
  36. Id = "1",
  37. Content = "Content",
  38. CallbackName = "Callback",
  39. Timestamp = DateTime.Now
  40. };
  41. var messageJson = JsonConvert.SerializeObject(message);
  42. //Act
  43. var ret = fixtrue.DeSerialize<CapMessageDto>(messageJson);
  44. //Assert
  45. Assert.NotNull(ret);
  46. Assert.Equal(message.Id, ret.Id);
  47. Assert.Equal(message.Content, ret.Content);
  48. Assert.Equal(message.CallbackName, ret.CallbackName);
  49. Assert.Equal(message.Timestamp, ret.Timestamp);
  50. }
  51. private JsonContentSerializer Create() => new JsonContentSerializer();
  52. }
  53. }