25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

98 lines
2.1 KiB

  1. using System;
  2. using System.Reflection;
  3. using DotNetCore.CAP.Internal;
  4. using Xunit;
  5. namespace DotNetCore.CAP.Test
  6. {
  7. public class HelperTest
  8. {
  9. [Fact]
  10. public void ToTimestampTest()
  11. {
  12. //Arrange
  13. var time = DateTime.Parse("2018-01-01 00:00:00");
  14. //Act
  15. var result = Helper.ToTimestamp(time);
  16. //Assert
  17. Assert.Equal(1514764800, result);
  18. }
  19. [Fact]
  20. public void IsControllerTest()
  21. {
  22. //Arrange
  23. var typeInfo = typeof(HomeController).GetTypeInfo();
  24. //Act
  25. var result = Helper.IsController(typeInfo);
  26. //Assert
  27. Assert.True(result);
  28. }
  29. [Fact]
  30. public void IsControllerAbstractTest()
  31. {
  32. //Arrange
  33. var typeInfo = typeof(AbstractController).GetTypeInfo();
  34. //Act
  35. var result = Helper.IsController(typeInfo);
  36. //Assert
  37. Assert.False(result);
  38. }
  39. [Theory]
  40. [InlineData(typeof(string))]
  41. [InlineData(typeof(decimal))]
  42. [InlineData(typeof(DateTime))]
  43. [InlineData(typeof(DateTimeOffset))]
  44. [InlineData(typeof(Guid))]
  45. [InlineData(typeof(TimeSpan))]
  46. [InlineData(typeof(Uri))]
  47. public void IsSimpleTypeTest(Type type)
  48. {
  49. //Act
  50. var result = Helper.IsComplexType(type);
  51. //Assert
  52. Assert.False(result);
  53. }
  54. [Theory]
  55. [InlineData(typeof(HomeController))]
  56. [InlineData(typeof(Exception))]
  57. public void IsComplexTypeTest(Type type)
  58. {
  59. //Act
  60. var result = Helper.IsComplexType(type);
  61. //Assert
  62. Assert.True(result);
  63. }
  64. [Theory]
  65. [InlineData("10.0.0.1")]
  66. [InlineData("172.16.0.1")]
  67. [InlineData("192.168.1.1")]
  68. public void IsInnerIPTest(string ipAddress)
  69. {
  70. Assert.True(Helper.IsInnerIP(ipAddress));
  71. }
  72. }
  73. public class HomeController
  74. {
  75. }
  76. public abstract class AbstractController
  77. {
  78. }
  79. }