|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using Microsoft.DurableTask.Entities; |
| 5 | + |
| 6 | +namespace Microsoft.DurableTask.Abstractions.Tests.Entities; |
| 7 | + |
| 8 | +public class EntityInstanceIdTests |
| 9 | +{ |
| 10 | + [Fact] |
| 11 | + public void TestValidEntityInstanceId() |
| 12 | + { |
| 13 | + var entityId = new EntityInstanceId("entity", "key1"); |
| 14 | + Assert.Equal("@entity@key1", entityId.ToString()); |
| 15 | + } |
| 16 | + |
| 17 | + [Fact] |
| 18 | + public void TestEntityNameLowercased() |
| 19 | + { |
| 20 | + var entityId = new EntityInstanceId("Entity", "key1"); |
| 21 | + Assert.Equal("entity", entityId.Name); |
| 22 | + Assert.Equal("@entity@key1", entityId.ToString()); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void TestEntityNameWithAtSymbolThrows() |
| 27 | + { |
| 28 | + Assert.Throws<ArgumentException>(() => new EntityInstanceId("entity@name", "key1")); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void TestEntityInstanceIdExceedsMaxLengthThrows() |
| 33 | + { |
| 34 | + string longName = new string('a', 50); |
| 35 | + string longKey = new string('b', 51); |
| 36 | + Assert.Throws<ArgumentException>(() => new EntityInstanceId(longName, longKey)); |
| 37 | + } |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public void TestFromStringValid() |
| 41 | + { |
| 42 | + var entityId = EntityInstanceId.FromString("@entity@key1"); |
| 43 | + Assert.Equal("entity", entityId.Name); |
| 44 | + Assert.Equal("key1", entityId.Key); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void TestFromStringInvalidThrows() |
| 49 | + { |
| 50 | + Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("invalid")); |
| 51 | + Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("@entitykey1")); |
| 52 | + Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("@@key1")); |
| 53 | + Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString($"@entity@{new string('a', 100)}")); |
| 54 | + } |
| 55 | +} |
0 commit comments