mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* Remove xunit dependency from testdriver * swap expected/actual as needed * Convert Test.Common to nunit * port hosting unit tests to nunit * port batchparser integration tests to nunit * port testdriver.tests to nunit * fix target to copy dependency * port servicelayer unittests to nunit * more unit test fixes * port integration tests to nunit * fix test method type * try using latest windows build for PRs * reduce test memory use
71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
using System;
|
|
using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
|
|
using NUnit.Framework;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
|
|
{
|
|
/// <summary>
|
|
/// Tests to verify FirewallErrorParser
|
|
/// </summary>
|
|
public class FirewallErrorParserTest
|
|
{
|
|
private const int SqlAzureFirewallBlockedErrorNumber = 40615;
|
|
private const int SqlAzureLoginFailedErrorNumber = 18456;
|
|
private string _errorMessage = "error Message with 1.2.3.4 as IP address";
|
|
private FirewallErrorParser _firewallErrorParser = new FirewallErrorParser();
|
|
|
|
|
|
[Test]
|
|
public void ParseExceptionShouldThrowExceptionGivenNullErrorMessage()
|
|
{
|
|
string errorMessage = null;
|
|
int errorCode = SqlAzureFirewallBlockedErrorNumber;
|
|
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(errorMessage, errorCode);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenDifferentError()
|
|
{
|
|
int errorCode = 123;
|
|
|
|
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(_errorMessage, errorCode);
|
|
Assert.False(response.FirewallRuleErrorDetected);
|
|
}
|
|
|
|
[Test]
|
|
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenLoginFailedError()
|
|
{
|
|
int errorCode = SqlAzureLoginFailedErrorNumber;
|
|
|
|
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(_errorMessage, errorCode);
|
|
Assert.False(response.FirewallRuleErrorDetected);
|
|
}
|
|
|
|
[Test]
|
|
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenInvalidErrorMessage()
|
|
{
|
|
int errorCode = SqlAzureFirewallBlockedErrorNumber;
|
|
string errorMessage = "error Message with no IP address";
|
|
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(errorMessage, errorCode);
|
|
Assert.False(response.FirewallRuleErrorDetected);
|
|
}
|
|
|
|
[Test]
|
|
public void ParseExceptionShouldReturnFireWallRuleDetectedGivenValidErrorMessage()
|
|
{
|
|
int errorCode = SqlAzureFirewallBlockedErrorNumber;
|
|
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(_errorMessage, errorCode);
|
|
Assert.True(response.FirewallRuleErrorDetected);
|
|
Assert.AreEqual("1.2.3.4", response.BlockedIpAddress.ToString());
|
|
}
|
|
}
|
|
}
|