-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
ConnectionSpecificationTest.cs
60 lines (47 loc) · 2.02 KB
/
ConnectionSpecificationTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
namespace Microsoft.EntityFrameworkCore;
public class ConnectionSpecificationTest
{
[ConditionalFact]
public async Task Can_specify_connection_string_in_OnConfiguring()
{
await using var testDatabase = CosmosTestStore.Create("NonExisting");
using var context = new BloggingContext(testDatabase);
var creator = context.GetService<IDatabaseCreator>();
Assert.False(await creator.EnsureDeletedAsync());
}
public class BloggingContext : DbContext
{
private readonly string _connectionString;
private readonly string _name;
public BloggingContext(CosmosTestStore testStore)
{
_connectionString = testStore.ConnectionString;
_name = testStore.Name;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseCosmos(_connectionString, _name, b => b.ApplyConfiguration())
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning));
public DbSet<Blog> Blogs { get; set; }
}
[ConditionalFact]
public async Task Throws_for_missing_connection_info()
{
using var context = new NoConnectionContext();
var creator = context.GetService<IDatabaseCreator>();
Assert.Equal(CosmosStrings.ConnectionInfoMissing,
(await Assert.ThrowsAsync<InvalidOperationException>(() => creator.EnsureDeletedAsync())).Message);
}
public class NoConnectionContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseCosmos(b => b.ApplyConfiguration())
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning));
}
public class Blog
{
public int Id { get; set; }
}
}