Exemplo n.º 1
0
 public BloggingContext(CosmosTestStore testStore)
 {
     _connectionUri = testStore.ConnectionUri;
     _authToken     = testStore.AuthToken;
     _name          = testStore.Name;
 }
        public async Task Can_add_update_delete_detached_entity_end_to_end_async()
        {
            using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName))
            {
                var options = Fixture.CreateOptions(testDatabase);

                var customer = new Customer {
                    Id = 42, Name = "Theon"
                };

                string storeId = null;
                using (var context = new CustomerContext(options))
                {
                    await context.Database.EnsureCreatedAsync();

                    var entry = context.Add(customer);

                    await context.SaveChangesAsync();

                    context.Add(customer);

                    storeId = entry.Property <string>("id").CurrentValue;
                }

                Assert.NotNull(storeId);

                using (var context = new CustomerContext(options))
                {
                    var customerFromStore = context.Set <Customer>().Single();

                    Assert.Equal(42, customerFromStore.Id);
                    Assert.Equal("Theon", customerFromStore.Name);
                }

                using (var context = new CustomerContext(options))
                {
                    customer.Name = "Theon Greyjoy";

                    var entry = context.Entry(customer);
                    entry.Property <string>("id").CurrentValue = storeId;

                    entry.State = EntityState.Modified;

                    await context.SaveChangesAsync();
                }

                using (var context = new CustomerContext(options))
                {
                    var customerFromStore = context.Set <Customer>().Single();

                    Assert.Equal(42, customerFromStore.Id);
                    Assert.Equal("Theon Greyjoy", customerFromStore.Name);
                }

                using (var context = new CustomerContext(options))
                {
                    var entry = context.Entry(customer);
                    entry.Property <string>("id").CurrentValue = storeId;
                    entry.State = EntityState.Deleted;

                    await context.SaveChangesAsync();
                }

                using (var context = new CustomerContext(options))
                {
                    Assert.Equal(0, context.Set <Customer>().Count());
                }
            }
        }
 public CosmosFixture()
 {
     TestStore = CosmosTestStore.Create(DatabaseName);
 }
Exemplo n.º 4
0
 public IdentifierShadowValuePresenceTestContext(CosmosTestStore testStore)
 {
     _connectionUri = testStore.ConnectionUri;
     _authToken     = testStore.AuthToken;
     _name          = testStore.Name;
 }
Exemplo n.º 5
0
 public TestStoreContext(CosmosTestStore testStore)
 {
     _testStore = testStore;
 }
Exemplo n.º 6
0
 public ReloadTestContext(CosmosTestStore testStore)
 {
     _connectionUri = testStore.ConnectionUri;
     _authToken     = testStore.AuthToken;
     _name          = testStore.Name;
 }
Exemplo n.º 7
0
 private DbContextOptions CreateOptions(CosmosTestStore testDatabase)
 => Fixture.AddOptions(testDatabase.AddProviderOptions(new DbContextOptionsBuilder()))
 .EnableDetailedErrors()
 .Options;
Exemplo n.º 8
0
 public BloggingContext(CosmosTestStore testStore)
 {
     _connectionString = testStore.ConnectionString;
     _name             = testStore.Name;
 }
 public override TestStore GetOrCreate(string storeName)
     => CosmosTestStore.GetOrCreate(Name, "Northwind.json");
Exemplo n.º 10
0
 public ValueTask <bool> IsMetAsync()
 => CosmosTestStore.IsConnectionAvailableAsync();