-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathEntityInstanceIdTests.cs
More file actions
64 lines (55 loc) · 2 KB
/
Copy pathEntityInstanceIdTests.cs
File metadata and controls
64 lines (55 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.DurableTask.Entities;
namespace Microsoft.DurableTask.Abstractions.Tests.Entities;
public class EntityInstanceIdTests
{
[Fact]
public void TestValidEntityInstanceId()
{
var entityId = new EntityInstanceId("entity", "key1");
Assert.Equal("@entity@key1", entityId.ToString());
}
[Fact]
public void TestEntityNameLowercased()
{
var entityId = new EntityInstanceId("Entity", "key1");
Assert.Equal("entity", entityId.Name);
Assert.Equal("@entity@key1", entityId.ToString());
}
[Fact]
public void TestEntityNameWithAtSymbolThrows()
{
Assert.Throws<ArgumentException>(() => new EntityInstanceId("entity@name", "key1"));
}
[Fact]
public void TestEntityInstanceIdExceedsMaxLengthThrows()
{
string longName = new string('a', 50);
string longKey = new string('b', 51);
Assert.Throws<ArgumentException>(() => new EntityInstanceId(longName, longKey));
}
[Fact]
public void TestEntityInstanceIdEqualsMaxLength()
{
string longName = new string('a', 49);
string longKey = new string('b', 49);
var entityId = new EntityInstanceId(longName, longKey);
Assert.Equal($"@{longName}@{longKey}", entityId.ToString());
}
[Fact]
public void TestFromStringValid()
{
var entityId = EntityInstanceId.FromString("@entity@key1");
Assert.Equal("entity", entityId.Name);
Assert.Equal("key1", entityId.Key);
}
[Fact]
public void TestFromStringInvalidThrows()
{
Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("invalid"));
Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("@entitykey1"));
Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString("@@key1"));
Assert.Throws<ArgumentException>(() => EntityInstanceId.FromString($"@entity@{new string('a', 100)}"));
}
}