Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using Cqrs.Azure.DocumentDb.Events;
10 : using cdmdotnet.Logging;
11 : using cdmdotnet.StateManagement;
12 : using cdmdotnet.StateManagement.Threaded;
13 : using Cqrs.Configuration;
14 : using Cqrs.DataStores;
15 : using Cqrs.Events;
16 : using Microsoft.Azure.Documents.Client;
17 :
18 : namespace Cqrs.Ninject.Azure.DocumentDb.Events
19 : {
20 : /// <summary>
21 : /// A <see cref="AzureDocumentDbEventStoreConnectionStringFactory"/>
22 : /// that enables you to set a database name with <see cref="DatabaseName"/>. This means you can randomly generate your own database name per test.
23 : /// </summary>
24 : public class TestAzureDocumentDbEventStoreConnectionStringFactory
25 : : AzureDocumentDbEventStoreConnectionStringFactory
26 : , IAzureDocumentDbSnapshotStoreConnectionStringFactory
27 1 : {
28 : private const string CallContextDatabaseNameKey = "AzureDocumentDbEventStoreConnectionStringFactory¿DatabaseName";
29 :
30 : private static IContextItemCollection Query { get; set; }
31 :
32 : static TestAzureDocumentDbEventStoreConnectionStringFactory()
33 : {
34 : Query = new ThreadedContextItemCollection();
35 : }
36 :
37 : /// <summary>
38 : /// The name of the database currently being used.
39 : /// </summary>
40 : public static string DatabaseName
41 : {
42 : get
43 : {
44 : return Query.GetData<string>(CallContextDatabaseNameKey);
45 : }
46 : set
47 : {
48 : Query.SetData(CallContextDatabaseNameKey, value);
49 : }
50 : }
51 :
52 : /// <summary>
53 : /// Instantiates a new instance of <see cref="TestAzureDocumentDbEventStoreConnectionStringFactory"/> defaulting to using <see cref="ConfigurationManager"/>
54 : /// </summary>
55 1 : public TestAzureDocumentDbEventStoreConnectionStringFactory(ILogger logger)
56 : : base(logger, new ConfigurationManager())
57 : {
58 : }
59 :
60 : #region Implementation of IAzureDocumentDbDataStoreConnectionStringFactory
61 :
62 : /// <summary>
63 : /// Gets the value of <see cref="DatabaseName"/>.
64 : /// </summary>
65 1 : public override string GetEventStoreConnectionDatabaseName()
66 : {
67 : return DatabaseName;
68 : }
69 :
70 : #endregion
71 :
72 : #region Implementation of IAzureDocumentDbSnapshotStoreConnectionStringFactory
73 :
74 : /// <summary>
75 : /// Gets the current <see cref="DocumentClient"/>.
76 : /// </summary>
77 1 : public DocumentClient GetSnapshotStoreConnectionClient()
78 : {
79 : return GetEventStoreConnectionClient();
80 : }
81 :
82 : /// <summary>
83 : /// Gets the current database name.
84 : /// </summary>
85 1 : public string GetSnapshotStoreConnectionDatabaseName()
86 : {
87 : return GetEventStoreConnectionDatabaseName();
88 : }
89 :
90 : /// <summary>
91 : /// Gets the current collection name.
92 : /// </summary>
93 1 : public string GetSnapshotStoreConnectionCollectionName()
94 : {
95 : return GetEventStoreConnectionCollectionName();
96 : }
97 :
98 : #endregion
99 : }
100 : }
|