mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* Make nullable warnings a per file opt-in * Remove unneeded compiler directives * Remove compiler directive for User Data
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Data.Common;
|
|
using Microsoft.SqlTools.ResourceProvider.Core;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
|
|
{
|
|
/// <summary>
|
|
/// Tests for ExceptionUtil to verify the helper and extension methods
|
|
/// </summary>
|
|
public class ExceptionUtilTest
|
|
{
|
|
[Test]
|
|
public void IsSqlExceptionShouldReturnFalseGivenNullException()
|
|
{
|
|
Exception exception = null;
|
|
bool expected = false;
|
|
bool actual = exception.IsDbException();
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
|
|
[Test]
|
|
public void IsSqlExceptionShouldReturnFalseGivenNonSqlException()
|
|
{
|
|
Exception exception = new ApplicationException();
|
|
bool expected = false;
|
|
bool actual = exception.IsDbException();
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
|
|
[Test]
|
|
public void IsSqlExceptionShouldReturnFalseGivenNonSqlExceptionWithInternalException()
|
|
{
|
|
Exception exception = new ApplicationException("Exception message", new ServiceFailedException());
|
|
bool expected = false;
|
|
bool actual = exception.IsDbException();
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
|
|
[Test]
|
|
public void IsSqlExceptionShouldReturnTrueGivenSqlException()
|
|
{
|
|
Exception exception = CreateDbException();
|
|
Assert.NotNull(exception);
|
|
|
|
bool expected = true;
|
|
bool actual = exception.IsDbException();
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
|
|
[Test]
|
|
public void IsSqlExceptionShouldReturnTrueGivenExceptionWithInnerSqlException()
|
|
{
|
|
Exception exception = new ApplicationException("", CreateDbException());
|
|
Assert.NotNull(exception);
|
|
|
|
bool expected = true;
|
|
bool actual = exception.IsDbException();
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
|
|
private Exception CreateDbException()
|
|
{
|
|
return new Mock<DbException>().Object;
|
|
}
|
|
}
|
|
}
|