コード例 #1
0
        public void ConvertSameModelBothWays_Complex()
        {
            var obj = new ModelTwo()
            {
                Type  = ModelType.Complex,
                Model = new ModelOne()
                {
                    Type  = ModelType.Complex,
                    Key   = 1,
                    Label = "Label 1",
                    Value = "TestValue",
                },
                Values = new List <string>()
                {
                    "Value1", "Value2", "Value3",
                },
            };

            var ser = JsonSerializer.Serialize(obj);

            Assert.AreEqual("{\"Type\":1,\"Model\":{\"Type\":1,\"Key\":1,\"Value\":\"TestValue\",\"Label\":\"Label 1\"},\"Values\":[\"Value1\",\"Value2\",\"Value3\"]}", ser);

            var bObj = JsonSerializer.Deserialize <ModelTwo>(ser);

            Assert.IsTrue(obj == bObj);
        }
コード例 #2
0
        public void When_having_members_Rev_EntityRev_It_extracts_EntityRev()
        {
            var model = new ModelTwo
            {
                Rev       = "ModelTwo:Rev:1",
                EntityRev = "ModelTwo:EntityRev:2"
            };

            SUT.GetValueFrom(model).Should().Be(model.EntityRev);
        }
コード例 #3
0
        public void When_having_members_Id_EntityId_It_extracts_EntityId()
        {
            var model = new ModelTwo
            {
                Id       = "ModelTwo:Id:1",
                EntityId = "ModelTwo:EntityId:2"
            };

            SUT.GetValueFrom(model).Should().Be(model.EntityId);
        }
コード例 #4
0
        public void When_serializing_entity_with_EntityId_It_will_translate_it_to__id()
        {
            var model = new ModelTwo {
                EntityId = "abc", Value = "def"
            };

            var json = SUT.Serialize(model);

            json.Should().Contain("\"_id\":\"abc\"");
            json.Should().NotContain("\"entityId\":\"abc\"");
        }