コード例 #1
0
        bool Test <T>(T e) where T : EntityBase
        {
            var v = _converter.ToTableEntity(e);
            var r = _converter.ToRecord <T>(v);

            return(EqualityComparison.AreEqual(e, r));
        }
コード例 #2
0
        public void TestConvertToTableEntity()
        {
            var uriString = new Uri("https://localhost:9090");
            var converter = new EntityConverter();
            var entity1   = new Entity1(
                Guid.NewGuid(),
                "test",
                DateTimeOffset.UtcNow,
                123,
                12.44,
                TestEnum.TheTwo, TestFlagEnum.FlagOne | TestFlagEnum.FlagTwo,
                "renamed",
                new TestObject {
                TheName      = "testobject",
                TheEnum      = TestEnum.TheTwo,
                TheFlag      = TestFlagEnum.FlagOne | TestFlagEnum.FlagTwo,
                TheEnumValue = TestEnumValue.One
            },
                null,
                uriString,
                null
                );
            var tableEntity = converter.ToTableEntity(entity1);

            Assert.NotNull(tableEntity);
            Assert.Equal(entity1.Id.ToString(), tableEntity.PartitionKey);
            Assert.Equal(entity1.TheName.ToString(), tableEntity.RowKey);
            Assert.Equal(entity1.TheDate, tableEntity.GetDateTimeOffset("the_date"));
            Assert.Equal(entity1.TheNumber, tableEntity.GetInt32("the_number"));
            Assert.Equal(entity1.TheFloat, tableEntity.GetDouble("the_float"));
            Assert.Equal("the_two", tableEntity.GetString("the_enum"));
            Assert.Equal("flag_one,flag_two", tableEntity.GetString("the_flag"));
            Assert.Equal("renamed", tableEntity.GetString("a__special__name"));

            Assert.Equal(uriString, new Uri(tableEntity.GetString("test_uri")));


            var json = JsonNode.Parse(tableEntity.GetString("the_object"))?.AsObject() ?? throw new InvalidOperationException("Could not parse objec");

            json.TryGetPropertyValue("the_name", out var theName);
            json.TryGetPropertyValue("the_enum", out var theEnum);
            json.TryGetPropertyValue("the_flag", out var theFlag);
            json.TryGetPropertyValue("the_enum_value", out var theEnumValue);

            Assert.Equal(entity1.TheObject.TheName, theName?.GetValue <string>());
            Assert.Equal("the_two", theEnum?.GetValue <string>());
            Assert.Equal("flag_one,flag_two", theFlag?.GetValue <string>());
            Assert.Equal((int)TestEnumValue.One, theEnumValue?.GetValue <int>());
        }
コード例 #3
0
        public void TestBothDirections()
        {
            var uriString = new Uri("https://localhost:9090");
            var converter = new EntityConverter();
            var entity1   = new Entity1(
                Guid.NewGuid(),
                "test",
                DateTimeOffset.UtcNow,
                123,
                12.44,
                TestEnum.TheTwo, TestFlagEnum.FlagOne | TestFlagEnum.FlagTwo,
                "renamed",
                new TestObject {
                TheName      = "testobject",
                TheEnum      = TestEnum.TheTwo,
                TheFlag      = TestFlagEnum.FlagOne | TestFlagEnum.FlagTwo,
                TheEnumValue = TestEnumValue.Two
            },
                null,
                uriString,
                null
                );


            var tableEntity     = converter.ToTableEntity(entity1);
            var fromTableEntity = converter.ToRecord <Entity1>(tableEntity);
            var eq = fromTableEntity == entity1;

            Assert.Equal(fromTableEntity.TimeStamp, entity1.TimeStamp);
            Assert.Equal(fromTableEntity.Id, entity1.Id);
            Assert.Equal(fromTableEntity.Renamed, entity1.Renamed);
            Assert.Equal(fromTableEntity.TestNull, entity1.TestNull);
            Assert.Equal(fromTableEntity.TestUri, entity1.TestUri);
            Assert.Equal(fromTableEntity.TestUriNull, entity1.TestUriNull);
            Assert.Equal(fromTableEntity.TheDate, entity1.TheDate);
            Assert.Equal(fromTableEntity.TheEnum, entity1.TheEnum);

            Assert.Equal(fromTableEntity.TheFlag, entity1.TheFlag);
            Assert.Equal(fromTableEntity.TheFloat, entity1.TheFloat);
            Assert.Equal(fromTableEntity.TheName, entity1.TheName);
            Assert.Equal(fromTableEntity.TheNumber, entity1.TheNumber);
            Assert.Equal(fromTableEntity.TimeStamp, entity1.TimeStamp);

            Assert.Equal(fromTableEntity.TheObject.TheEnum, entity1.TheObject.TheEnum);
            Assert.Equal(fromTableEntity.TheObject.TheFlag, entity1.TheObject.TheFlag);
            Assert.Equal(fromTableEntity.TheObject.TheName, entity1.TheObject.TheName);
            Assert.Equal(fromTableEntity.TheObject.TheEnumValue, entity1.TheObject.TheEnumValue);
        }