コード例 #1
0
ファイル: PatchTests.cs プロジェクト: khoavn/Detached
        public void create_proxy_patch()
        {
            Type   proxyType = _proxyFactory.Create <Entity>();
            Entity entity    = (Entity)Activator.CreateInstance(proxyType);

            entity.Name = "newName";

            IPatch entityChanges = (IPatch)entity;

            Assert.True(entityChanges.IsSet("Name"));
            Assert.False(entityChanges.IsSet("Date"));

            entityChanges.Reset();

            Assert.False(entityChanges.IsSet("Name"));
            Assert.False(entityChanges.IsSet("Date"));
        }
コード例 #2
0
ファイル: JsonPatchTests.cs プロジェクト: khoavn/Detached
        public void deserialize_as_patch()
        {
            JsonSerializerOptions jsonOptions = new JsonSerializerOptions();

            jsonOptions.Converters.Add(new PatchJsonConverterFactory(Options.Create(new ModelOptions())));
            jsonOptions.IgnoreReadOnlyProperties = true;

            string json = @"
                {
                    'Id': 1,
                    'Name': 'test name'
                }";

            Entity entity = JsonSerializer.Deserialize <Entity>(json.Replace("'", "\""), jsonOptions);

            IPatch changeTracking = (IPatch)entity;

            Assert.True(changeTracking.IsSet("Name"));
            Assert.True(changeTracking.IsSet("Id"));
            Assert.False(changeTracking.IsSet("Date"));
        }