forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionSpecificationTest.cs
More file actions
56 lines (44 loc) · 2 KB
/
ConnectionSpecificationTest.cs
File metadata and controls
56 lines (44 loc) · 2 KB
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
// 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;
#nullable disable
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
public class ConnectionSpecificationTest
{
[ConditionalFact]
public async Task Can_specify_connection_string_in_OnConfiguring()
{
await using var testDatabase = CosmosTestStoreFactory.Instance.Create("NonExisting");
using var context = new BloggingContext(testDatabase);
var creator = context.GetService<IDatabaseCreator>();
Assert.False(await creator.EnsureDeletedAsync());
}
public class BloggingContext(CosmosTestStore testStore) : DbContext
{
private readonly string _connectionString = testStore.ConnectionString;
private readonly string _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();
Assert.Equal(
CosmosStrings.ConnectionInfoMissing,
(await Assert.ThrowsAsync<InvalidOperationException>(() => context.GetService<IDatabaseCreator>().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; }
}
}