public void Should_serialize_and_deserialize_as_dictionary() { var dictionary = new Dictionary <DomainId, int> { [DomainId.Create("123")] = 321 }; var serialized = dictionary.SerializeAndDeserialize(); Assert.Equal(321, serialized[DomainId.Create("123")]); }
public override object ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value) { if (value is string text) { return(DomainId.Create(text)); } if (value is Guid guid) { return(DomainId.Create(guid)); } return(DomainId.Empty); }
public void Should_make_correct_equal_comparisons() { var domainId_1_a = DomainId.Create("1"); var domainId_1_b = DomainId.Create("1"); var domainId2_a = DomainId.Create("2"); Assert.Equal(domainId_1_a, domainId_1_b); Assert.Equal(domainId_1_a.GetHashCode(), domainId_1_b.GetHashCode()); Assert.True(domainId_1_a.Equals((object)domainId_1_b)); Assert.NotEqual(domainId_1_a, domainId2_a); Assert.NotEqual(domainId_1_a.GetHashCode(), domainId2_a.GetHashCode()); Assert.False(domainId_1_a.Equals((object)domainId2_a)); Assert.True(domainId_1_a == domainId_1_b); Assert.True(domainId_1_a != domainId2_a); Assert.False(domainId_1_a != domainId_1_b); Assert.False(domainId_1_a == domainId2_a); }
private static bool ParseDomainId(ReadOnlySpan <char> value, out DomainId result) { result = DomainId.Create(new string(value)); return(true); }
public void Should_initialize_default_from_string() { var domainId = DomainId.Create(Guid.Empty.ToString()); Assert.Equal(DomainId.Empty, domainId); }
public void Should_compare_with_non_shared_nullable() { DomainId?value = DomainId.Create("0"); Assert.True(value == DomainId.Create("0")); }
public void Should_compare_with_nullable2() { DomainId?value = DomainId.Create(Guid.Empty.ToString()); Assert.True(value == DomainId.Empty); }