Skip to content

Commit b62ccab

Browse files
Changes to allow mocking of the lower-level native API by introducing the ISqlLocalDbApi interface.
1 parent 200bba0 commit b62ccab

9 files changed

Lines changed: 2300 additions & 1660 deletions

File tree

src/SqlLocalDb.UnitTests/SqlLocalDbProviderTests.cs

Lines changed: 325 additions & 246 deletions
Large diffs are not rendered by default.

src/SqlLocalDb/ISqlLocalDbApi.cs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ISqlLocalDbApi.cs" company="http://sqllocaldb.codeplex.com">
3+
// Martin Costello (c) 2012-2013
4+
// </copyright>
5+
// <license>
6+
// See license.txt in the project root for license information.
7+
// </license>
8+
// <summary>
9+
// ISqlLocalDbApi.cs
10+
// </summary>
11+
// --------------------------------------------------------------------------------------------------------------------
12+
13+
using System.Collections.Generic;
14+
15+
namespace System.Data.SqlLocalDb
16+
{
17+
/// <summary>
18+
/// Defines the interface to the SQL LocalDB API.
19+
/// </summary>
20+
public interface ISqlLocalDbApi
21+
{
22+
#region Properties
23+
24+
/// <summary>
25+
/// Gets the version string for the latest installed version of SQL Server LocalDB.
26+
/// </summary>
27+
string LatestVersion
28+
{
29+
get;
30+
}
31+
32+
/// <summary>
33+
/// Gets an <see cref="Array"/> of <see cref="String"/>
34+
/// containing the available versions of SQL LocalDB.
35+
/// </summary>
36+
IList<string> Versions
37+
{
38+
get;
39+
}
40+
41+
#endregion
42+
43+
#region Methods
44+
45+
/// <summary>
46+
/// Creates a new instance of SQL Server LocalDB.
47+
/// </summary>
48+
/// <param name="instanceName">The name of the LocalDB instance.</param>
49+
/// <param name="version">The version of SQL Server LocalDB to use.</param>
50+
void CreateInstance(string instanceName, string version);
51+
52+
/// <summary>
53+
/// Deletes the specified SQL Server LocalDB instance.
54+
/// </summary>
55+
/// <param name="instanceName">
56+
/// The name of the LocalDB instance to delete.
57+
/// </param>
58+
void DeleteInstance(string instanceName);
59+
60+
/// <summary>
61+
/// Returns information about the specified LocalDB instance.
62+
/// </summary>
63+
/// <param name="instanceName">The name of the LocalDB instance to get the information for.</param>
64+
/// <returns>
65+
/// An instance of <see cref="ISqlLocalDbInstanceInfo"/> containing information
66+
/// about the LocalDB instance specified by <paramref name="instanceName"/>.
67+
/// </returns>
68+
ISqlLocalDbInstanceInfo GetInstanceInfo(string instanceName);
69+
70+
/// <summary>
71+
/// Returns the names of all the SQL Server LocalDB instances for the current user.
72+
/// </summary>
73+
/// <returns>
74+
/// The names of the the SQL Server LocalDB instances for the current user.
75+
/// </returns>
76+
[Diagnostics.CodeAnalysis.SuppressMessage(
77+
"Microsoft.Design",
78+
"CA1024:UsePropertiesWhereAppropriate",
79+
Justification = "Requires enumerating the API which is non-trivial.")]
80+
IList<string> GetInstanceNames();
81+
82+
/// <summary>
83+
/// Returns information about the specified LocalDB version.
84+
/// </summary>
85+
/// <param name="version">The name of the LocalDB version to get the information for.</param>
86+
/// <returns>
87+
/// An instance of <see cref="ISqlLocalDbVersionInfo"/> containing information
88+
/// about the LocalDB version specified by <paramref name="version"/>.
89+
/// </returns>
90+
ISqlLocalDbVersionInfo GetVersionInfo(string version);
91+
92+
/// <summary>
93+
/// Returns whether SQL LocalDB is installed on the current machine.
94+
/// </summary>
95+
/// <returns>
96+
/// <see langword="true"/> if SQL Server LocalDB is installed on the
97+
/// current machine; otherwise <see langword="false"/>.
98+
/// </returns>
99+
bool IsLocalDBInstalled();
100+
101+
/// <summary>
102+
/// Shares the specified SQL Server LocalDB instance with other
103+
/// users of the computer, using the specified shared name.
104+
/// </summary>
105+
/// <param name="ownerSid">The SID of the instance owner.</param>
106+
/// <param name="instanceName">The private name for the LocalDB instance to share.</param>
107+
/// <param name="sharedInstanceName">The shared name for the LocalDB instance to share.</param>
108+
void ShareInstance(string ownerSid, string instanceName, string sharedInstanceName);
109+
110+
/// <summary>
111+
/// Starts the specified instance of SQL Server LocalDB.
112+
/// </summary>
113+
/// <param name="instanceName">The name of the LocalDB instance to start.</param>
114+
/// <returns>
115+
/// The named pipe to use to connect to the LocalDB instance.
116+
/// </returns>
117+
string StartInstance(string instanceName);
118+
119+
/// <summary>
120+
/// Enables tracing of native API calls for all the SQL Server
121+
/// LocalDB instances owned by the current Windows user.
122+
/// </summary>
123+
void StartTracing();
124+
125+
/// <summary>
126+
/// Stops the specified instance of SQL Server LocalDB.
127+
/// </summary>
128+
/// <param name="instanceName">
129+
/// The name of the LocalDB instance to stop.
130+
/// </param>
131+
/// <param name="timeout">
132+
/// The amount of time to give the LocalDB instance to stop.
133+
/// If the value is <see cref="TimeSpan.Zero"/>, the method will
134+
/// return immediately and not wait for the instance to stop.
135+
/// </param>
136+
void StopInstance(string instanceName, TimeSpan timeout);
137+
138+
/// <summary>
139+
/// Disables tracing of native API calls for all the SQL Server
140+
/// LocalDB instances owned by the current Windows user.
141+
/// </summary>
142+
/// <exception cref="SqlLocalDbException">
143+
/// Tracing could not be disabled.
144+
/// </exception>
145+
void StopTracing();
146+
147+
/// <summary>
148+
/// Stops the sharing of the specified SQL Server LocalDB instance.
149+
/// </summary>
150+
/// <param name="instanceName">
151+
/// The private name for the LocalDB instance to share.
152+
/// </param>
153+
[Diagnostics.CodeAnalysis.SuppressMessage(
154+
"Microsoft.Naming",
155+
"CA1704:IdentifiersShouldBeSpelledCorrectly",
156+
MessageId = "Unshare",
157+
Justification = "Matches the name of the native LocalDB API function.")]
158+
void UnshareInstance(string instanceName);
159+
160+
#endregion
161+
}
162+
}

0 commit comments

Comments
 (0)