/
Id_for_String_specs.cs
114 lines (101 loc) · 2.44 KB
/
Id_for_String_specs.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
namespace Identifiers.Id_for_String_specs;
public class Is_comparable
{
[Test]
public void to_null_is_1() => Svo.StringId.CompareTo(Nil.Object).Should().Be(1);
[Test]
public void to_StringId_as_object()
{
object obj = Svo.StringId;
Svo.StringId.CompareTo(obj).Should().Be(0);
}
[Test]
public void to_StringId_only()
=> new object().Invoking(Svo.StringId.CompareTo).Should().Throw<ArgumentException>();
[Test]
public void can_be_sorted_using_compare()
{
var sorted = new[]
{
StringId.Empty,
StringId.Parse("33ef5805c472"),
StringId.Parse("58617a652a14"),
StringId.Parse("853634b4e474"),
StringId.Parse("93ca7b438fb3"),
StringId.Parse("f5e6c39aadcf"),
};
var list = new List<StringId> { sorted[3], sorted[4], sorted[5], sorted[2], sorted[0], sorted[1] };
list.Sort();
list.Should().BeEquivalentTo(sorted);
}
}
public class Supports_type_conversion
{
[Test]
public void via_TypeConverter_registered_with_attribute()
=> typeof(StringId).Should().HaveTypeConverterDefined();
[Test]
public void from_null_string()
{
using (TestCultures.en_GB.Scoped())
{
Converting.FromNull<string>().To<StringId>().Should().Be(StringId.Empty);
}
}
[Test]
public void from_empty_string()
{
using (TestCultures.en_GB.Scoped())
{
Converting.From(string.Empty).To<StringId>().Should().Be(StringId.Empty);
}
}
[Test]
public void from_string()
{
using (TestCultures.en_GB.Scoped())
{
Converting.From("Qowaiv-ID").To<StringId>().Should().Be(Svo.StringId);
}
}
[Test]
public void to_string()
{
using (TestCultures.en_GB.Scoped())
{
Converting.ToString().From(Svo.StringId).Should().Be("Qowaiv-ID");
}
}
}
#if NET8_0_OR_GREATER
#else
public class Supports_binary_serialization
{
[Test]
[Obsolete("Usage of the binary formatter is considered harmful.")]
public void using_BinaryFormatter()
{
var round_tripped = SerializeDeserialize.Binary(Svo.StringId);
round_tripped.Should().Be(Svo.StringId);
}
[Test]
public void storing_value_in_SerializationInfo()
{
var info = Serialize.GetInfo(Svo.StringId);
info.GetString("Value").Should().Be("Qowaiv-ID");
}
}
#endif
public class Is_Open_API_data_type
{
[Test]
public void with_info()
=> OpenApiDataType.FromType(typeof(ForString))
.Should().Be(new OpenApiDataType(
dataType: typeof(StringId),
description: "String based identifier",
example: "Order-UK-2022-215",
type: "string",
format: "identifier",
nullable: true));
}