Ejemplo n.º 1
0
        public void SqlLocalDbInstance_Delete_If_SqlLocalDbApi_AutomaticallyDeleteInstanceFiles_Is_True()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

            Helpers.InvokeInNewAppDomain(
                () =>
            {
                SqlLocalDbApi.AutomaticallyDeleteInstanceFiles = true;

                string instanceName = Guid.NewGuid().ToString();

                SqlLocalDbApi.CreateInstance(instanceName);

                Mock <ISqlLocalDbInstance> mock = new Mock <ISqlLocalDbInstance>();
                mock.Setup((p) => p.Name).Returns(instanceName);

                ISqlLocalDbInstanceInfo info = SqlLocalDbApi.GetInstanceInfo(instanceName);
                Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null.");
                Assert.IsTrue(info.Exists, "ISqlLocalDbInstanceInfo.Exists is incorrect.");

                ISqlLocalDbInstance instance = mock.Object;

                // Act
                SqlLocalDbInstance.Delete(instance);

                // Assert
                info = SqlLocalDbApi.GetInstanceInfo(instanceName);
                Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null.");
                Assert.IsFalse(info.Exists, "The SQL LocalDB instance was not deleted.");

                string path = Path.Combine(SqlLocalDbApi.GetInstancesFolderPath(), instanceName);
                Assert.IsFalse(Directory.Exists(path), "The instance folder was not deleted.");
            });
        }
Ejemplo n.º 2
0
        public void SqlLocalDbInstance_Delete_Deletes_Instance()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

            string instanceName = Guid.NewGuid().ToString();

            SqlLocalDbApi.CreateInstance(instanceName);

            Mock <ISqlLocalDbInstance> mock = new Mock <ISqlLocalDbInstance>();

            mock.Setup((p) => p.Name).Returns(instanceName);

            ISqlLocalDbInstanceInfo info = SqlLocalDbApi.GetInstanceInfo(instanceName);

            Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null.");
            Assert.IsTrue(info.Exists, "ISqlLocalDbInstanceInfo.Exists is incorrect.");

            ISqlLocalDbInstance instance = mock.Object;

            // Act
            SqlLocalDbInstance.Delete(instance);

            // Assert
            info = SqlLocalDbApi.GetInstanceInfo(instanceName);
            Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null.");
            Assert.IsFalse(info.Exists, "The SQL LocalDB instance was not deleted.");

            string path = Path.Combine(SqlLocalDbApi.GetInstancesFolderPath(), instanceName);

            Assert.IsTrue(Directory.Exists(path), "The instance folder was deleted.");
            Assert.AreNotEqual(0, Directory.GetFiles(path).Length, "The instance files were deleted.");
        }
Ejemplo n.º 3
0
        private TestDatabase(TemporarySqlLocalDbInstance instance, string pathToSeedDb)
        {
            _instance = instance;

            var pathToModel = Path.Combine(SqlLocalDbApi.GetInstancesFolderPath(), instance.Name, Path.GetFileName(pathToSeedDb));

            File.Copy(pathToSeedDb, pathToModel);

            _connectionString = GetConnectionString(instance, pathToModel);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the SQL LocalDB instance names using the instance folder names on the current machine.
        /// </summary>
        /// <returns>
        /// An <see cref="Array"/> containing the names of all the instance folder on the current machine.
        /// </returns>
        private static string[] GetInstanceNames()
        {
            string path = SqlLocalDbApi.GetInstancesFolderPath();

            if (Directory.Exists(path))
            {
                return(Directory.GetDirectories(path));
            }
            else
            {
                return(new string[0]);
            }
        }
        /// <summary>
        /// Assets that the specified SQL LocalDB instance's file(s) are in the specified state of existence.
        /// </summary>
        /// <param name="instanceName">The instance name to assert for.</param>
        /// <param name="shouldFilesExist">Whether the specified instance name's files are expected to exist.</param>
        private static void AssertFileExistence(string instanceName, bool shouldFilesExist)
        {
            string path = Path.Combine(SqlLocalDbApi.GetInstancesFolderPath(), instanceName);

            if (shouldFilesExist)
            {
                Assert.IsTrue(Directory.Exists(path), "The instance folder was deleted.");
                Assert.AreNotEqual(0, Directory.GetFiles(path).Length, "The instance file(s) were deleted.");
            }
            else
            {
                Assert.IsFalse(Directory.Exists(path), "The instance folder was not deleted.");
            }
        }
 /// <summary>
 /// Get the full path of the directory containing the SQL server LocalDB instance files for the current user.
 /// </summary>
 /// <param name="instanceName">instance name</param>
 /// <returns>full path of the directory containing the SQL server LocalDB instance</returns>
 public static string GetInstancePath(string instanceName)
 {
     return(System.IO.Path.Combine(SqlLocalDbApi.GetInstancesFolderPath(), instanceName));
 }