Ejemplo n.º 1
0
 public void Throws_PlatformNotSupportedException()
 {
     // Arrange
     using (var actual = new SqlLocalDbApi(_loggerFactory))
     {
         // Act and Assert
         Assert.Throws <PlatformNotSupportedException>(() => actual.CreateInstance("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.DeleteInstance("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.DeleteUserInstances());
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetDefaultInstance());
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetInstanceInfo("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetInstanceNames());
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetInstances());
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetOrCreateInstance("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.GetVersionInfo("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.InstanceExists("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.LatestVersion);
         Assert.Throws <PlatformNotSupportedException>(() => actual.ShareInstance("name", "sharedName"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.ShareInstance("sid", "name", "sharedName"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.StartInstance("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.StartTracing());
         Assert.Throws <PlatformNotSupportedException>(() => actual.StopInstance("name"));
         Assert.Throws <PlatformNotSupportedException>(() => actual.StopTracing());
         Assert.Throws <PlatformNotSupportedException>(() => actual.UnshareInstance("name"));
     }
 }
Ejemplo n.º 2
0
        public void Throws_InvalidOperationException_If_SQL_LocalDB_Not_Installed()
        {
            // Arrange
            var options  = new SqlLocalDbOptions();
            var registry = Mock.Of <Interop.IRegistry>();

            using (var actual = new SqlLocalDbApi(options, registry, _loggerFactory))
            {
                // Act and Assert
                Assert.Throws <InvalidOperationException>(() => actual.CreateInstance("name"));
                Assert.Throws <InvalidOperationException>(() => actual.DeleteInstance("name"));
                Assert.Throws <InvalidOperationException>(() => actual.DeleteUserInstances());
                Assert.Throws <InvalidOperationException>(() => actual.GetDefaultInstance());
                Assert.Throws <InvalidOperationException>(() => actual.GetInstanceInfo("name"));
                Assert.Throws <InvalidOperationException>(() => actual.GetInstanceNames());
                Assert.Throws <InvalidOperationException>(() => actual.GetInstances());
                Assert.Throws <InvalidOperationException>(() => actual.GetOrCreateInstance("name"));
                Assert.Throws <InvalidOperationException>(() => actual.GetVersionInfo("name"));
                Assert.Throws <InvalidOperationException>(() => actual.InstanceExists("name"));
                Assert.Throws <InvalidOperationException>(() => actual.LatestVersion);
                Assert.Throws <InvalidOperationException>(() => actual.ShareInstance("name", "sharedName"));
                Assert.Throws <InvalidOperationException>(() => actual.StartInstance("name"));
                Assert.Throws <InvalidOperationException>(() => actual.StartTracing());
                Assert.Throws <InvalidOperationException>(() => actual.StopInstance("name"));
                Assert.Throws <InvalidOperationException>(() => actual.StopTracing());
                Assert.Throws <InvalidOperationException>(() => actual.UnshareInstance("name"));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Shares the LocalDB instance using the specified name.
        /// </summary>
        /// <param name="sharedName">The name to use to share the instance.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="sharedName"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="SqlLocalDbException">
        /// The LocalDB instance could not be shared.
        /// </exception>
        public virtual void Share(string sharedName)
        {
            if (sharedName == null)
            {
                throw new ArgumentNullException(nameof(sharedName));
            }

            try
            {
                SqlLocalDbApi.ShareInstance(_instanceName, sharedName);
            }
            catch (SqlLocalDbException e)
            {
                string message = SRHelper.Format(
                    SR.SqlLocalDbInstance_ShareFailedFormat,
                    _instanceName);

                Logger.Error(Logger.TraceEvent.ShareInstance, message);

                throw new SqlLocalDbException(
                          message,
                          e.ErrorCode,
                          e.InstanceName,
                          e);
            }
        }
        public void Methods_Validate_Parameters()
        {
            // Arrange
            TimeSpan timeout = TimeSpan.Zero.Add(TimeSpan.FromTicks(-1));

            using var actual = new SqlLocalDbApi(_loggerFactory);

            // Act and Assert
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.CreateInstance(null !, "version"));
            Assert.Throws <ArgumentNullException>("version", () => actual.CreateInstance("instanceName", null !));
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.DeleteInstance(null !));
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.GetInstanceInfo(null !));
            Assert.Throws <ArgumentNullException>("version", () => actual.GetVersionInfo(null !));
            Assert.Throws <ArgumentNullException>("ownerSid", () => actual.ShareInstance(null !, "instanceName", "sharedInstanceName"));
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.ShareInstance("ownerSid", null !, "sharedInstanceName"));
            Assert.Throws <ArgumentNullException>("sharedInstanceName", () => actual.ShareInstance("ownerSid", "instanceName", null !));
            Assert.Throws <ArgumentException>("instanceName", () => actual.ShareInstance("sid", string.Empty, "sharedInstanceName"));
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.StartInstance(null !));
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.StopInstance(null !, TimeSpan.Zero));
            Assert.Throws <ArgumentOutOfRangeException>("timeout", () => actual.StopInstance("instanceName", timeout)).ActualValue.ShouldBe(timeout);
            Assert.Throws <ArgumentNullException>("instanceName", () => actual.UnshareInstance(null !));
        }
        public void ShareInstance_Shares_Instance_For_Current_User()
        {
            // Arrange
            using var api = new SqlLocalDbApi(_loggerFactory);
            using TemporarySqlLocalDbInstance target = api.CreateTemporaryInstance(deleteFiles: true);

            target.GetInstanceInfo().IsShared.ShouldBeFalse();

            // Act
            api.ShareInstance(target.Name, Guid.NewGuid().ToString());

            // Assert
            target.GetInstanceInfo().IsShared.ShouldBeTrue();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Shares the specified SQL Server LocalDB instance with other
 /// users of the computer, using the specified shared name.
 /// </summary>
 /// <param name="ownerSid">The SID of the instance owner.</param>
 /// <param name="instanceName">The private name for the LocalDB instance to share.</param>
 /// <param name="sharedInstanceName">The shared name for the LocalDB instance to share.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="ownerSid"/>, <paramref name="instanceName"/> or
 /// <paramref name="instanceName"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// SQL Server LocalDB is not installed on the local machine.
 /// </exception>
 /// <exception cref="SqlLocalDbException">
 /// The SQL Server LocalDB instance specified by <paramref name="instanceName"/> could not be shared.
 /// </exception>
 public virtual void ShareInstance(string ownerSid, string instanceName, string sharedInstanceName)
 {
     SqlLocalDbApi.ShareInstance(ownerSid, instanceName, sharedInstanceName);
 }