Beispiel #1
0
        /// <summary>
        /// Deletes the specified <see cref="ISqlLocalDbInstance"/> instance.
        /// </summary>
        /// <param name="instance">The LocalDB instance to delete.</param>
        /// <param name="throwIfNotFound">
        /// Whether to throw an exception if the SQL LocalDB instance
        /// associated with <paramref name="instance"/> cannot be found.
        /// </param>
        /// <param name="deleteFiles">
        /// Whether to delete the file(s) associated with the SQL LocalDB instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="instance"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="SqlLocalDbException">
        /// The SQL Server LocalDB instance specified by <paramref name="instance"/> could not be deleted.
        /// </exception>
        internal static void Delete(ISqlLocalDbInstance instance, bool throwIfNotFound, bool deleteFiles)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            try
            {
                SqlLocalDbApi.DeleteInstanceInternal(instance.Name, throwIfNotFound, deleteFiles);
            }
            catch (SqlLocalDbException ex)
            {
                string message = SRHelper.Format(
                    SR.SqlLocalDbInstance_DeleteFailedFormat,
                    instance.Name);

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

                throw new SqlLocalDbException(
                          message,
                          ex.ErrorCode,
                          ex.InstanceName,
                          ex);
            }
        }
        public void DeleteInstanceInternal_Returns_False_If_ThrownIfNotFound_Is_False_And_Instance_Does_Not_Exist()
        {
            // Arrange
            using var actual = new SqlLocalDbApi(_loggerFactory);

            // Act and Assert
            actual.DeleteInstanceInternal("NotARealInstance", throwIfNotFound: false).ShouldBeFalse();
        }
Beispiel #3
0
        public void DeleteInstanceInternal_Returns_False_If_ThrownIfNotFound_Is_False_And_Instance_Does_Not_Exist()
        {
            // Arrange
            TimeSpan timeout = TimeSpan.Zero.Add(TimeSpan.FromTicks(-1));

            using (var actual = new SqlLocalDbApi(_loggerFactory))
            {
                // Act and Assert
                actual.DeleteInstanceInternal("NotARealInstance", throwIfNotFound: false).ShouldBeFalse();
            }
        }
        public void Manager_Shares_And_Unshares_Instance()
        {
            // Act
            string instanceName = Guid.NewGuid().ToString();
            string sharedName   = Guid.NewGuid().ToString();

            using (var api = new SqlLocalDbApi(_loggerFactory))
            {
                api.CreateInstance(instanceName);

                try
                {
                    api.StartInstance(instanceName);

                    try
                    {
                        var instance = api.GetInstanceInfo(instanceName);

                        var manager = new SqlLocalDbInstanceManager(instance, api);

                        // Act
                        manager.Share(sharedName);

                        // Assert
                        instance.IsShared.ShouldBeTrue();

                        // Act
                        manager.Unshare();

                        // Assert
                        instance.IsShared.ShouldBeFalse();
                    }
                    catch (Exception)
                    {
                        api.StopInstance(instanceName);
                        throw;
                    }
                }
                catch (Exception)
                {
                    api.DeleteInstanceInternal(instanceName, throwIfNotFound: false, deleteFiles: true);
                    throw;
                }
            }
        }