UuidTests.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Jint.Tests.Runtime.Domain;
  2. namespace Jint.Tests.Runtime
  3. {
  4. public class UuidTests : IDisposable
  5. {
  6. private readonly Engine _engine;
  7. public UuidTests()
  8. {
  9. _engine = new Engine(o => o.AddObjectConverter(new UuidConverter()))
  10. .SetValue("copy", new Func<Guid, Guid>(v => new Guid(v.ToByteArray())))
  11. ;
  12. UuidConstructor.CreateUuidConstructor(_engine);
  13. }
  14. void IDisposable.Dispose()
  15. {
  16. }
  17. private object RunTest(string source)
  18. {
  19. return _engine.Evaluate(source).ToObject();
  20. }
  21. [Fact]
  22. public void Empty()
  23. {
  24. Assert.Equal(Guid.Empty, RunTest($"Uuid.parse('{Guid.Empty}')"));
  25. Assert.Equal(Guid.Empty, RunTest($"Uuid.Empty"));
  26. }
  27. [Fact]
  28. public void Random()
  29. {
  30. var actual = RunTest($"new Uuid()");
  31. Assert.NotEqual(Guid.Empty, actual);
  32. Assert.IsType<Guid>(actual);
  33. }
  34. [Fact]
  35. public void Copy()
  36. {
  37. _engine.Evaluate("const g = new Uuid();");
  38. Assert.Equal(_engine.Evaluate("copy(g).toString()").AsString(), _engine.Evaluate("g.toString()").AsString());
  39. }
  40. }
  41. }