public async Task Can_read_with_find_with_resource_id_async()
        {
            var       options = Fixture.CreateOptions();
            const int pk1     = 1;
            const int pk2     = 2;

            var customer = new CustomerWithResourceId
            {
                id           = "42",
                Name         = "Theon",
                PartitionKey = pk1
            };

            await using (var context = new PartitionKeyContextWithResourceId(options))
            {
                await context.Database.EnsureCreatedAsync();

                Assert.Null(
                    context.Model.FindEntityType(typeof(CustomerWithResourceId))
                    .FindProperty(StoreKeyConvention.DefaultIdPropertyName));

                context.Add(customer);
                context.Add(
                    new CustomerWithResourceId
                {
                    id           = "42",
                    Name         = "Theon Twin",
                    PartitionKey = pk2
                });

                await context.SaveChangesAsync();
            }

            await using (var context = new PartitionKeyContextWithResourceId(options))
            {
                var customerFromStore = await context.Set <CustomerWithResourceId>()
                                        .FindAsync(pk1, "42");

                Assert.Equal("42", customerFromStore.id);
                Assert.Equal("Theon", customerFromStore.Name);
                Assert.Equal(pk1, customerFromStore.PartitionKey);
                AssertSql(context, @"ReadItem(1, 42)");

                customerFromStore.Name = "Theon Greyjoy";

                await context.SaveChangesAsync();
            }

            await using (var context = new PartitionKeyContextWithResourceId(options))
            {
                var customerFromStore = await context.Set <CustomerWithResourceId>()
                                        .WithPartitionKey(partitionKey: pk1.ToString())
                                        .FirstAsync();

                Assert.Equal("42", customerFromStore.id);
                Assert.Equal("Theon Greyjoy", customerFromStore.Name);
                Assert.Equal(pk1, customerFromStore.PartitionKey);
            }
        }
        public void Can_read_with_find_with_resource_id()
        {
            var       options = Fixture.CreateOptions();
            const int pk1     = 1;
            const int pk2     = 2;

            var customer = new CustomerWithResourceId
            {
                id           = "42",
                Name         = "Theon",
                PartitionKey = pk1
            };

            using (var context = new PartitionKeyContextWithResourceId(options))
            {
                context.Database.EnsureCreated();

                context.Add(customer);
                context.Add(
                    new CustomerWithResourceId
                {
                    id           = "42",
                    Name         = "Theon Twin",
                    PartitionKey = pk2
                });

                context.SaveChanges();
            }

            using (var context = new PartitionKeyContextWithResourceId(options))
            {
                var customerFromStore = context.Set <CustomerWithResourceId>()
                                        .Find(pk1, "42");

                Assert.Equal("42", customerFromStore.id);
                Assert.Equal("Theon", customerFromStore.Name);
                Assert.Equal(pk1, customerFromStore.PartitionKey);
                AssertSql(context, @"ReadItem(1, 42)");

                customerFromStore.Name = "Theon Greyjoy";

                context.SaveChanges();
            }

            using (var context = new PartitionKeyContextWithResourceId(options))
            {
                var customerFromStore = context.Set <CustomerWithResourceId>()
                                        .WithPartitionKey(partitionKey: pk1.ToString())
                                        .First();

                Assert.Equal("42", customerFromStore.id);
                Assert.Equal("Theon Greyjoy", customerFromStore.Name);
                Assert.Equal(pk1, customerFromStore.PartitionKey);
            }
        }
        public void Find_with_empty_resource_id_throws()
        {
            var options = Fixture.CreateOptions();

            using (var context = new PartitionKeyContextWithResourceId(options))
            {
                context.Database.EnsureCreated();

                Assert.Equal(CosmosStrings.InvalidResourceId,
                             Assert.Throws <InvalidOperationException>(() => context.Set <CustomerWithResourceId>().Find(1, "")).Message);
            }
        }