Esempio n. 1
0
        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")]);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private static bool ParseDomainId(ReadOnlySpan <char> value, out DomainId result)
        {
            result = DomainId.Create(new string(value));

            return(true);
        }
Esempio n. 5
0
        public void Should_initialize_default_from_string()
        {
            var domainId = DomainId.Create(Guid.Empty.ToString());

            Assert.Equal(DomainId.Empty, domainId);
        }
Esempio n. 6
0
        public void Should_compare_with_non_shared_nullable()
        {
            DomainId?value = DomainId.Create("0");

            Assert.True(value == DomainId.Create("0"));
        }
Esempio n. 7
0
        public void Should_compare_with_nullable2()
        {
            DomainId?value = DomainId.Create(Guid.Empty.ToString());

            Assert.True(value == DomainId.Empty);
        }