-
Notifications
You must be signed in to change notification settings - Fork 882
Expand file tree
/
Copy pathConformanceTests.cs
More file actions
106 lines (85 loc) · 4.07 KB
/
ConformanceTests.cs
File metadata and controls
106 lines (85 loc) · 4.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.TestUtilities;
using Aspire.Components.ConformanceTests;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;
namespace Aspire.Microsoft.EntityFrameworkCore.Cosmos.Tests;
public class ConformanceTests : ConformanceTests<TestDbContext, EntityFrameworkCoreCosmosSettings>
{
protected override ServiceLifetime ServiceLifetime => ServiceLifetime.Singleton;
protected override string ActivitySourceName => "Azure.Cosmos.Operation";
protected override string[] RequiredLogCategories => new string[]
{
"Microsoft.EntityFrameworkCore.ChangeTracking",
"Microsoft.EntityFrameworkCore.Database.Command",
"Microsoft.EntityFrameworkCore.Infrastructure",
"Microsoft.EntityFrameworkCore.Query",
};
protected override void PopulateConfiguration(ConfigurationManager configuration, string? key = null)
=> configuration.AddInMemoryCollection(new KeyValuePair<string, string?>[]
{
new KeyValuePair<string, string?>("Aspire:Microsoft:EntityFrameworkCore:Cosmos:ConnectionString",
AspireAzureEfCoreCosmosDBExtensionsTests.ConnectionString),
});
protected override void RegisterComponent(HostApplicationBuilder builder, Action<EntityFrameworkCoreCosmosSettings>? configure = null, string? key = null)
=> builder.AddCosmosDbContext<TestDbContext>(key ?? "cosmosdb", "TestDatabase", configure);
protected override void SetHealthCheck(EntityFrameworkCoreCosmosSettings options, bool enabled)
=> throw new NotImplementedException();
protected override void SetTracing(EntityFrameworkCoreCosmosSettings options, bool enabled)
=> options.DisableTracing = !enabled;
protected override void SetMetrics(EntityFrameworkCoreCosmosSettings options, bool enabled)
=> throw new NotImplementedException();
protected override string ValidJsonConfig => """
{
"Aspire": {
"Microsoft": {
"EntityFrameworkCore": {
"Cosmos": {
"ConnectionString": "YOUR_CONNECTION_STRING",
"DisableTracing": false
}
}
}
}
}
""";
protected override (string json, string error)[] InvalidJsonToErrorMessage => new[]
{
("""{"Aspire": { "Microsoft":{ "EntityFrameworkCore": { "Cosmos": { "AccountEndpoint": 3 }}}}}""", "Value is \"integer\" but should be \"string\""),
("""{"Aspire": { "Microsoft":{ "EntityFrameworkCore": { "Cosmos": { "AccountEndpoint": "hello" }}}}}""", "Value does not match format \"uri\""),
("""{"Aspire": { "Microsoft":{ "EntityFrameworkCore": { "Cosmos": { "Region": 3 }}}}}""", "Value is \"integer\" but should be \"string\""),
};
protected override void TriggerActivity(TestDbContext service)
{
if (service.Database.CanConnect())
{
service.Database.EnsureCreated();
}
}
[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Required to verify pooling without touching DB")]
public void DbContextPoolingRegistersIDbContextPool()
{
using IHost host = CreateHostWithComponent();
IDbContextPool<TestDbContext>? pool = host.Services.GetService<IDbContextPool<TestDbContext>>();
Assert.NotNull(pool);
}
[Fact]
public void DbContextCanBeAlwaysResolved()
{
using IHost host = CreateHostWithComponent();
TestDbContext? dbContext = host.Services.GetService<TestDbContext>();
Assert.NotNull(dbContext);
}
[Fact]
public void TracingEnablesTheRightActivitySource()
{
SkipIfCanNotConnectToServer();
RemoteExecutor.Invoke(() => ActivitySourceTest(key: null)).Dispose();
}
}