public void Can_read_with_find_with_resource_id() { var options = Fixture.CreateOptions(); const int pk1 = 1; const int pk2 = 2; var customer = new Customer_WithResourceId { id = "42", Name = "Theon", PartitionKey = pk1 }; using (var context = new PartitionKeyContext_WithResourceId(options)) { context.Database.EnsureCreated(); context.Add(customer); context.Add( new Customer_WithResourceId { id = "42", Name = "Theon Twin", PartitionKey = pk2 }); context.SaveChanges(); } using (var context = new PartitionKeyContext_WithResourceId(options)) { var customerFromStore = context.Set <Customer_WithResourceId>() .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 PartitionKeyContext_WithResourceId(options)) { var customerFromStore = context.Set <Customer_WithResourceId>() .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 PartitionKeyContext_WithResourceId(options)) { context.Database.EnsureCreated(); Assert.Equal(CosmosStrings.InvalidResourceId, Assert.Throws <InvalidOperationException>(() => context.Set <Customer_WithResourceId>().Find(1, "")).Message); } }