Esempio n. 1
0
        public void SqlLocalDbInstance_Stop_Throws_If_An_Error_Occurs()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

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

            SqlLocalDbApi.CreateInstance(instanceName);

            SqlLocalDbInstance target;

            try
            {
                target = new SqlLocalDbInstance(instanceName);
            }
            finally
            {
                SqlLocalDbApi.DeleteInstance(instanceName);
            }

            // Act
            SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>(
                () => target.Stop());

            // Assert
            Assert.AreEqual(SqlLocalDbErrors.UnknownInstance, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect.");
            Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect.");

            throw error;
        }
Esempio n. 2
0
        public void SqlLocalDbInstance_Share_Throws_If_SharedName_Is_Null()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

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

            SqlLocalDbApi.CreateInstance(instanceName);

            try
            {
                SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName);

                string sharedName = null;

                // Act and Assert
                throw ErrorAssert.Throws <ArgumentNullException>(
                          () => target.Share(sharedName),
                          "sharedName");
            }
            finally
            {
                SqlLocalDbApi.DeleteInstance(instanceName);
            }
        }
Esempio n. 3
0
        public void SqlLocalDbInstance_Share_Throws_If_SharedName_Is_Invalid()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

            string instanceName = Guid.NewGuid().ToString();
            string sharedName   = "\\\\";

            SqlLocalDbApi.CreateInstance(instanceName);

            try
            {
                SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName);

                // Act
                SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>(
                    () => target.Share(sharedName));

                // Assert
                Assert.AreEqual(SqlLocalDbErrors.InvalidInstanceName, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect.");
                Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect.");

                throw error;
            }
            finally
            {
                SqlLocalDbApi.DeleteInstance(instanceName);
            }
        }
Esempio n. 4
0
        public void SqlLocalDbInstance_Constructor_Throws_If_InstanceName_Does_Not_Exist()
        {
            // Arrange
            string instanceName = Guid.NewGuid().ToString();

            // Act and Assert
            throw ErrorAssert.Throws <InvalidOperationException>(
                      () => new SqlLocalDbInstance(instanceName));
        }
Esempio n. 5
0
        public void SqlLocalDbInstance_Constructor_Throws_If_LocalDb_Returns_Null()
        {
            // Arrange
            string         instanceName = Guid.NewGuid().ToString();
            ISqlLocalDbApi localDB      = Mock.Of <ISqlLocalDbApi>();

            // Act and Assert
            throw ErrorAssert.Throws <InvalidOperationException>(
                      () => new SqlLocalDbInstance(instanceName, localDB));
        }
Esempio n. 6
0
        public void SqlLocalDbInstance_Constructor_Throws_If_InstanceName_Is_Null()
        {
            // Arrange
            string instanceName = null;

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => new SqlLocalDbInstance(instanceName),
                      "instanceName");
        }
Esempio n. 7
0
        public void SqlLocalDbInstance_Delete_Throws_If_Instance_Is_Null()
        {
            // Arrange
            ISqlLocalDbInstance instance = null;

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => SqlLocalDbInstance.Delete(instance),
                      "instance");
        }
Esempio n. 8
0
        public void SqlLocalDbProvider_Constructor_Throws_If_LocalDB_Is_Null()
        {
            // Arrange
            ISqlLocalDbApi localDB = null;

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => new SqlLocalDbProvider(localDB),
                      "localDB");
        }
Esempio n. 9
0
        public void SRHelper_Format_Throws_If_Args_Is_Null()
        {
            // Arrange
            string format = string.Empty;

            object[] args = null;

            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => SRHelper.Format(format, args),
                      "args");
        }
Esempio n. 10
0
        public void SRHelper_Format_Throws_If_Format_Is_Null()
        {
            // Arrange
            string format = null;

            object[] args = new object[0];

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => SRHelper.Format(format, args),
                      "format");
        }
Esempio n. 11
0
        public void SqlLocalDbProvider_CreateInstance_Throws_If_No_Instance_Info_From_Api()
        {
            // Arrange
            ISqlLocalDbApi localDB = Mock.Of <ISqlLocalDbApi>();

            SqlLocalDbProvider target       = new SqlLocalDbProvider(localDB);
            string             instanceName = Guid.NewGuid().ToString();

            // Act and Assert
            throw ErrorAssert.Throws <InvalidOperationException>(
                      () => target.CreateInstance(instanceName));
        }
Esempio n. 12
0
        public void SqlLocalDbException_GetObjectData_Throws_If_Info_Is_Null()
        {
            // Arrange
            SqlLocalDbException target = new SqlLocalDbException();

            SerializationInfo info    = null;
            StreamingContext  context = new StreamingContext();

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () => target.GetObjectData(info, context),
                      "info");
        }
        public void TemporarySqlLocalDbInstance_Constructor_Throws_If_Provider_Is_Null()
        {
            // Arrange
            string instanceName          = Guid.NewGuid().ToString();
            ISqlLocalDbProvider provider = null;

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () =>
            {
                using (TemporarySqlLocalDbInstance target = new TemporarySqlLocalDbInstance(instanceName, provider))
                {
                }
            },
                      "provider");
        }
        public void TemporarySqlLocalDbInstance_Constructor_Throws_If_InstanceName_Is_Null()
        {
            // Arrange
            string instanceName          = null;
            ISqlLocalDbProvider provider = Mock.Of <ISqlLocalDbProvider>();

            // Act and Assert
            throw ErrorAssert.Throws <ArgumentNullException>(
                      () =>
            {
                using (TemporarySqlLocalDbInstance target = new TemporarySqlLocalDbInstance(instanceName, provider))
                {
                }
            },
                      "instanceName");
        }
        public void TemporarySqlLocalDbInstance_Constructor_Attempts_To_Delete_Instance_If_Instance_Cannot_Be_Started()
        {
            // Arrange
            string instanceName = "MyTempInstance" + Guid.NewGuid().ToString();

            var mock = new Mock <SqlLocalDbProvider>()
            {
                CallBase = true,
            };

            // Set up the CreateInstance() method to create an SQL LocalDB
            // instance but that then throws an exception when started.
            mock.Setup((p) => p.CreateInstance(instanceName))
            .Returns(
                () =>
            {
                SqlLocalDbApi.CreateInstance(instanceName);
                return(new SqlLocalDbInstanceThatCannotBeStarted(instanceName));
            })
            .Verifiable();

            ISqlLocalDbProvider provider = mock.Object;
            bool deleteFiles             = false;

            // Act
            InvalidOperationException error = ErrorAssert.Throws <InvalidOperationException>(
                () =>
            {
                using (TemporarySqlLocalDbInstance target = new TemporarySqlLocalDbInstance(instanceName, provider, deleteFiles))
                {
                }
            });

            mock.Verify();

            ISqlLocalDbInstanceInfo instanceInfo = SqlLocalDbApi.GetInstanceInfo(instanceName);

            Assert.IsFalse(instanceInfo.Exists, "The temporary instance was not deleted.");

            throw error;
        }
Esempio n. 16
0
        public void SqlLocalDbProvider_CreateInstance_Throws_If_Instance_Already_Exists()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

            SqlLocalDbProvider target       = new SqlLocalDbProvider();
            string             instanceName = Guid.NewGuid().ToString();

            SqlLocalDbApi.CreateInstance(instanceName);

            try
            {
                // Act and Assert
                throw ErrorAssert.Throws <InvalidOperationException>(
                          () => target.CreateInstance(instanceName));
            }
            finally
            {
                SqlLocalDbApi.DeleteInstance(instanceName);
            }
        }
Esempio n. 17
0
        public void SqlLocalDbInstance_CreateConnectionStringBuilder_Throws_If_Instance_Not_Started()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

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

            SqlLocalDbApi.CreateInstance(instanceName);

            try
            {
                SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName);

                // Act and Assert
                throw ErrorAssert.Throws <InvalidOperationException>(
                          () => target.CreateConnectionStringBuilder());
            }
            finally
            {
                SqlLocalDbApi.DeleteInstance(instanceName);
            }
        }
Esempio n. 18
0
        public void SqlLocalDbInstance_Delete_Throws_If_Instance_Is_Invalid()
        {
            // Arrange
            Helpers.EnsureLocalDBInstalled();

            const string InstanceName = "\\\\";

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

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

            ISqlLocalDbInstance instance = mock.Object;

            // Act
            SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>(
                () => SqlLocalDbInstance.Delete(instance));

            // Assert
            Assert.AreEqual(SqlLocalDbErrors.InvalidInstanceName, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect.");
            Assert.AreEqual(InstanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect.");

            throw error;
        }