PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Ninject.Test/Unit/FormatTests.cs

https://github.com/wjkhappy14/ninject
C# | 94 lines | 82 code | 12 blank | 0 comment | 0 complexity | f294c61de22cedfa7346710bb75f5f8f MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. using System;
  2. using FluentAssertions;
  3. using Ninject.Infrastructure.Introspection;
  4. using Ninject.Tests.Fakes;
  5. using Xunit;
  6. class TypeWithNoNamespace
  7. {
  8. }
  9. namespace Ninject.Tests.Unit
  10. {
  11. public class TestGenericType<TOuter>
  12. {
  13. public class InnerType {}
  14. public class InnerGenericType<TInner> {}
  15. }
  16. public class FormatTypeTests
  17. {
  18. public class InnerType {}
  19. [Fact]
  20. public void BuiltInTypesFormatttedAsCSharpName()
  21. {
  22. typeof(bool).Format().Should().Be("bool");
  23. typeof(char).Format().Should().Be("char");
  24. typeof(sbyte).Format().Should().Be("sbyte");
  25. typeof(short).Format().Should().Be("short");
  26. typeof(ushort).Format().Should().Be("ushort");
  27. typeof(int).Format().Should().Be("int");
  28. typeof(uint).Format().Should().Be("uint");
  29. typeof(long).Format().Should().Be("long");
  30. typeof(ulong).Format().Should().Be("ulong");
  31. typeof(float).Format().Should().Be("float");
  32. typeof(double).Format().Should().Be("double");
  33. typeof(decimal).Format().Should().Be("decimal");
  34. typeof(DateTime).Format().Should().Be("DateTime");
  35. typeof(string).Format().Should().Be("string");
  36. }
  37. [Fact]
  38. public void SimpleTypeFormattedAsShortName()
  39. {
  40. typeof(Sword).Format().Should().Be("Sword");
  41. typeof(TypeWithNoNamespace).Format().Should().Be("TypeWithNoNamespace");
  42. }
  43. [Fact]
  44. public void InnerTypeFormattedWithOuterTypeName()
  45. {
  46. typeof(InnerType).Format().Should().Be("FormatTypeTests+InnerType");
  47. typeof(TestGenericType<>.InnerType).Format().Should().Be("TestGenericType{TOuter}+InnerType");
  48. typeof(TestGenericType<int>.InnerType).Format().Should().Be("TestGenericType{int}+InnerType");
  49. }
  50. [Fact]
  51. public void GenericTypeFormattedWithGenericArguments()
  52. {
  53. typeof(TestGenericType<>).Format().Should().Be("TestGenericType{TOuter}");
  54. typeof(TestGenericType<int>).Format().Should().Be("TestGenericType{int}");
  55. }
  56. [Fact]
  57. public void GenericInnerTypeFormattedWithOuterTypeNameAndGenericArguments()
  58. {
  59. typeof(TestGenericType<>.InnerGenericType<>).Format().Should().Be("TestGenericType{TOuter}+InnerGenericType{TInner}");
  60. typeof(TestGenericType<int>.InnerGenericType<long>).Format().Should().Be("TestGenericType{int}+InnerGenericType{long}");
  61. }
  62. [Fact]
  63. public void AnonymousTypeFormattedSimply()
  64. {
  65. var o = new {
  66. Hello = "World!",
  67. a = 1,
  68. b = false,
  69. c = DateTime.MinValue,
  70. d = new Uri("http://example.org"),
  71. e = new {
  72. x = 0,
  73. },
  74. f = 3,
  75. g = 4,
  76. h = 5,
  77. i = 15,
  78. };
  79. o.GetType().Format().Should().Be("AnonymousType");
  80. }
  81. }
  82. }