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.Factories;
10 : using cdmdotnet.Logging;
11 : using cdmdotnet.StateManagement;
12 : using cdmdotnet.StateManagement.Threaded;
13 : using Cqrs.Configuration;
14 : using Cqrs.DataStores;
15 : using Cqrs.Entities;
16 :
17 : namespace Cqrs.Ninject.Azure.DocumentDb.Factories
18 : {
19 : /// <summary>
20 : /// A <see cref="AzureDocumentDbDataStoreConnectionStringFactory"/>
21 : /// that enables you to set a database name with <see cref="DatabaseName"/>. This means you can randomly generate your own database name per test.
22 : /// </summary>
23 : public class TestAzureDocumentDbDataStoreConnectionStringFactory : AzureDocumentDbDataStoreConnectionStringFactory
24 1 : {
25 : private const string CallContextDatabaseNameKey = "AzureDocumentDbDataStoreConnectionStringFactory¿DatabaseName";
26 :
27 : private static IContextItemCollection Query { get; set; }
28 :
29 : static TestAzureDocumentDbDataStoreConnectionStringFactory()
30 : {
31 : Query = new ThreadedContextItemCollection();
32 : }
33 :
34 : /// <summary>
35 : /// The name of the database currently being used.
36 : /// </summary>
37 : public static string DatabaseName
38 : {
39 : get
40 : {
41 : return Query.GetData<string>(CallContextDatabaseNameKey);
42 : }
43 : set
44 : {
45 : Query.SetData(CallContextDatabaseNameKey, value);
46 : }
47 : }
48 :
49 : /// <summary>
50 : /// Instantiates a new instance of <see cref="TestAzureDocumentDbDataStoreConnectionStringFactory"/> defaulting to using <see cref="ConfigurationManager"/>
51 : /// </summary>
52 1 : public TestAzureDocumentDbDataStoreConnectionStringFactory(ILogger logger)
53 : : base(logger, new ConfigurationManager())
54 : {
55 : }
56 :
57 : #region Implementation of IAzureDocumentDbDataStoreConnectionStringFactory
58 :
59 : /// <summary>
60 : /// Gets the value of <see cref="DatabaseName"/>.
61 : /// </summary>
62 1 : public override string GetAzureDocumentDbDatabaseName()
63 : {
64 : return DatabaseName;
65 : }
66 :
67 : #endregion
68 :
69 : #region Overrides of AzureDocumentDbDataStoreConnectionStringFactory
70 :
71 : /// <summary>
72 : /// Indicates if a different collection should be used per <see cref="IEntity"/>/<see cref="IDataStore{TData}"/> or a single collection used for all instances of <see cref="IDataStore{TData}"/> and <see cref="IDataStore{TData}"/>.
73 : /// Setting this to true can become expensive as each <see cref="IEntity"/> will have it's own collection. Check the relevant SDK/pricing models.
74 : /// </summary>
75 : /// <returns>Always returns true.</returns>
76 1 : public override bool UseSingleCollectionForAllDataStores()
77 : {
78 : return true;
79 : }
80 :
81 : #endregion
82 : }
83 : }
|