示例#1
0
        public async Task Entities_can_be_tracked_with_normal_use_of_DbContext_methods_and_have_correct_resultant_state_and_id_shadow_value()
        {
            await using var testDatabase = CosmosTestStore.Create("IdentifierShadowValuePresenceTest");
            using var context            = new IdentifierShadowValuePresenceTestContext(testDatabase);

            var item = new Item {
                Id = 1337
            };
            var entry = context.Attach(item);

            Assert.Equal($"Item|{item.Id}", entry.Property("__id").CurrentValue);
            Assert.Equal(EntityState.Unchanged, entry.State);

            entry.State = EntityState.Detached;
            entry       = context.Update(item = new Item {
                Id = 71
            });

            Assert.Equal($"Item|{item.Id}", entry.Property("__id").CurrentValue);
            Assert.Equal(EntityState.Modified, entry.State);

            entry.State = EntityState.Detached;
            entry       = context.Remove(item = new Item {
                Id = 33
            });

            Assert.Equal($"Item|{item.Id}", entry.Property("__id").CurrentValue);
            Assert.Equal(EntityState.Deleted, entry.State);
        }
示例#2
0
        public async Task Entities_with_null_PK_can_be_added_with_normal_use_of_DbContext_methods_and_have_id_shadow_value_and_PK_created()
        {
            await using var testDatabase = CosmosTestStore.Create("IdentifierShadowValuePresenceTest");
            using var context            = new IdentifierShadowValuePresenceTestContext(testDatabase);

            var item = new GItem {
            };

            Assert.Null(item.Id);

            var entry = context.Add(item);

            var id = entry.Property("__id").CurrentValue;

            Assert.NotNull(item.Id);
            Assert.NotNull(id);

            Assert.Equal($"GItem|{item.Id}", id);
            Assert.Equal(EntityState.Added, entry.State);
        }