-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
StoreInitializationTests.cs
83 lines (67 loc) · 2.47 KB
/
StoreInitializationTests.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using FluentAssertions;
using Marten.Integration.Tests.TestsInfrastructure;
using Weasel.Core;
using Xunit;
namespace Marten.Integration.Tests.General;
public class StoreInitializationTests(MartenFixture fixture): MartenTest(fixture.PostgreSqlContainer, false, false)
{
[Fact]
public void GivenWrongConnectionString_WhenDocumentSessionIsInitialized_ThenConnectionIsCreated()
{
var ex = Record.Exception(() =>
{
var store = DocumentStore.For("WrongConnectionString");
ConnectionShouldBeEstablished(store);
});
ex.Should().NotBeNull();
}
[Fact]
public void GivenProperConnectionString_WhenDocumentSessionIsInitialized_ThenConnectionIsCreated()
{
var ex = Record.Exception(() =>
{
var store = DocumentStore.For(ConnectionString);
ConnectionShouldBeEstablished(store);
});
ex.Should().BeNull();
}
[Fact]
public void GivenProperConnectionString_WhenDocumentSessionIsInitializedWithDifferentShema_ThenConnectionIsCreated()
{
var ex = Record.Exception(() =>
{
var store = DocumentStore.For(options =>
{
options.Connection(ConnectionString);
options.AutoCreateSchemaObjects = AutoCreate.All;
options.Events.DatabaseSchemaName = SchemaName;
});
ConnectionShouldBeEstablished(store);
});
ex.Should().BeNull();
}
[Fact(Skip = "To investigate in Npgsql")]
public void GivenProperConnectionString_WhenDocumentSessionIsCreatedAndTransactionIsCreated_ThenConnectionIsCreatedAndItsPossibleToMakeRollback()
{
var ex = Record.Exception(() =>
{
var store = DocumentStore.For(options =>
{
options.Connection(ConnectionString);
options.AutoCreateSchemaObjects = AutoCreate.All;
options.Events.DatabaseSchemaName = SchemaName;
});
using var session = store.LightweightSession();
using var transaction = session.Connection.BeginTransaction();
ConnectionShouldBeEstablished(store);
transaction.Rollback();
});
ex.Should().BeNull();
}
private static void ConnectionShouldBeEstablished(IDocumentStore store)
{
using var session = store.LightweightSession();
var result = session.Query<int>("SELECT 1");
result.Should().NotBeNull();
}
}