public async Task TestCosmosDbAzureCosmosDbOk() { //SETUP var config = new ConfigurationBuilder() .AddUserSecrets <Startup>() .Build(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["CosmosUrl"], config["CosmosKey"], GetType().Name); using (var context = new NoSqlDbContext(builder.Options)) { await context.Database.EnsureCreatedAsync(); //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); await context.SaveChangesAsync(); //VERIFY context.Books.Find(book.BookId).ShouldNotBeNull(); } }
public async Task TestCosmosDbAzureCosmosDbOk() { //SETUP var config = new ConfigurationBuilder() .AddUserSecrets <Startup>() .Build(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["CosmosUrl"], config["CosmosKey"], nameof(TestNoSqlDbContext)); using (var context = new NoSqlDbContext(builder.Options)) { await context.Database.EnsureCreatedAsync(); //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); await context.SaveChangesAsync(); //VERIFY (await context.Books.CountAsync(p => p.BookId == book.BookId)).ShouldEqual(1); } }
public async Task TestCosmosDbCatchFailedRequestOk() { //SETUP var config = AppSettings.GetConfiguration(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["endpoint"], config["authKey"], "UNKNOWNDATABASE"); using (var context = new NoSqlDbContext(builder.Options)) { //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); var ex = await Assert.ThrowsAsync <CosmosException>(async() => await context.SaveChangesAsync()); //VERIFY ex.Message.ShouldStartWith("Response status code does not indicate success: 404 Substatus:"); } }
public async Task TestCosmosDbCatchFailedRequestOk() { //SETUP var config = AppSettings.GetConfiguration(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["endpoint"], config["authKey"], "UNKNOWNDATABASE"); using (var context = new NoSqlDbContext(builder.Options)) { //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); var ex = await Assert.ThrowsAsync <HttpException>(async() => await context.SaveChangesAsync()); //VERIFY ex.Message.ShouldEqual("NotFound"); } }
public async Task TestCosmosDbLocalDbEmulatorCreateDatabaseOk() { //SETUP var config = AppSettings.GetConfiguration(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["endpoint"], config["authKey"], GetType().Name); using (var context = new NoSqlDbContext(builder.Options)) { await context.Database.EnsureCreatedAsync(); //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); await context.SaveChangesAsync(); //VERIFY context.Books.Find(book.BookId).ShouldNotBeNull(); } }
public async Task TestCosmosDbLocalDbEmulatorCreateDatabaseOk() { //SETUP var config = AppSettings.GetConfiguration(); var builder = new DbContextOptionsBuilder <NoSqlDbContext>() .UseCosmos( config["endpoint"], config["authKey"], nameof(TestNoSqlDbContext)); using (var context = new NoSqlDbContext(builder.Options)) { await context.Database.EnsureCreatedAsync(); //ATTEMPT var book = NoSqlTestData.CreateDummyNoSqlBook(); context.Add(book); await context.SaveChangesAsync(); //VERIFY (await context.Books.CountAsync(p => p.BookId == book.BookId)).ShouldEqual(1); } }