Exemple #1
0
        public static void SqlLocalDbException_Constructor_For_Serialization_Can_Be_Serialized()
        {
            // Arrange
            InvalidOperationException innerException = new InvalidOperationException();
            const int ErrorCode    = 337519;
            string    instanceName = Guid.NewGuid().ToString();
            string    message      = Guid.NewGuid().ToString();

            // Act
            var target    = new SqlLocalDbException(message, ErrorCode, instanceName, innerException);
            var formatter = new BinaryFormatter();

            SqlLocalDbException?deserialized;

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, target);
                stream.Seek(0L, SeekOrigin.Begin);
                deserialized = formatter.Deserialize(stream) as SqlLocalDbException;
            }

            // Assert
            deserialized.ShouldNotBeNull();
            deserialized !.ErrorCode.ShouldBe(target.ErrorCode);
            deserialized.InstanceName.ShouldBe(target.InstanceName);
            deserialized.Message.ShouldBe(target.Message);
        }
        public static void Share_Throws_If_SqlLocalDbEception_Is_Thrown()
        {
            // Act
            var innerException = new SqlLocalDbException(
                "It broke",
                123,
                "Name");

            var mock = new Mock <ISqlLocalDbApi>();

            mock.Setup((p) => p.ShareInstance(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Throws(innerException);

            ISqlLocalDbInstanceInfo instance = CreateInstance();
            ISqlLocalDbApi          api      = mock.Object;

            var target = new SqlLocalDbInstanceManager(instance, api);

            var exception = Assert.Throws <SqlLocalDbException>(() => target.Share("SharedName"));

            exception.ErrorCode.ShouldBe(123);
            exception.InstanceName.ShouldBe("Name");
            exception.Message.ShouldBe("Failed to share SQL LocalDB instance 'Name'.");
            exception.InnerException.ShouldBeSameAs(innerException);
        }
Exemple #3
0
        public static void SqlLocalDbException_Constructor_Default_Sets_Properties()
        {
            // Act
            var target = new SqlLocalDbException();

            // Assert
            target.ErrorCode.ShouldBe(-2147467259);
            target.InstanceName.ShouldBeNull();
            target.Message.ShouldBe("An error occurred with a SQL Server LocalDB instance.");
        }
Exemple #4
0
        public static void SqlLocalDbException_GetObjectData_Throws_If_Info_Is_Null()
        {
            // Arrange
            var target = new SqlLocalDbException();

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

            // Act and Assert
            Assert.Throws <ArgumentNullException>("info", () => target.GetObjectData(info !, context));
        }
Exemple #5
0
        public static void SqlLocalDbException_Constructor_With_Message_Sets_Properties()
        {
            // Arrange
            string message = Guid.NewGuid().ToString();

            // Act
            var target = new SqlLocalDbException(message);

            // Assert
            target.ErrorCode.ShouldBe(-2147467259);
            target.InstanceName.ShouldBeNull();
            target.Message.ShouldBe(message);
        }
Exemple #6
0
        public static void SqlLocalDbException_Constructor_With_Message_ErrorCode_And_InstanceName_Sets_Properties()
        {
            // Arrange
            const int ErrorCode    = 337519;
            string    instanceName = Guid.NewGuid().ToString();
            string    message      = Guid.NewGuid().ToString();

            // Act
            var target = new SqlLocalDbException(message, ErrorCode, instanceName);

            // Assert
            target.ErrorCode.ShouldBe(ErrorCode);
            target.InstanceName.ShouldBe(instanceName);
            target.Message.ShouldBe(message);
        }
Exemple #7
0
        public static void SqlLocalDbException_Constructor_With_Message_And_InnerException_Sets_Properties()
        {
            // Arrange
            var    innerException = new InvalidOperationException();
            string message        = Guid.NewGuid().ToString();

            // Act
            var target = new SqlLocalDbException(message, innerException);

            // Assert
            target.ErrorCode.ShouldBe(-2147467259);
            target.InnerException.ShouldBeSameAs(innerException);
            target.InstanceName.ShouldBeNull();
            target.Message.ShouldBe(message);
        }