Convert most tools service tests to nunit (#1037)

* 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
This commit is contained in:
David Shiflet
2020-08-05 13:43:14 -04:00
committed by GitHub
parent bf4911795f
commit 839acf67cd
205 changed files with 4146 additions and 4329 deletions

View File

@@ -13,7 +13,7 @@ using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
using Microsoft.SqlTools.ResourceProvider.Core.Contracts;
using Microsoft.SqlTools.ResourceProvider.DefaultImpl;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
{
@@ -29,14 +29,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
serviceProvider.RegisterSingleService<IAzureResourceManager>(resourceManagerMock.Object);
}
[Fact]
[Test]
public async Task CurrentUserShouldBeNullWhenUserIsNotSignedIn()
{
IAzureAuthenticationManager accountManager = await CreateAccountManager(null, null);
Assert.Null(await accountManager.GetCurrentAccountAsync());
}
[Fact]
[Test]
public async Task GetSubscriptionShouldReturnEmptyWhenUserIsNotSignedIn()
{
IAzureAuthenticationManager accountManager = await CreateAccountManager(null, null);
@@ -45,24 +45,24 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
Assert.False(result.Any());
}
[Fact]
[Test]
public async Task GetSubscriptionShouldThrowWhenUserNeedsAuthentication()
{
var currentUserAccount = CreateAccount();
currentUserAccount.Account.IsStale = true;
IAzureAuthenticationManager accountManager = await CreateAccountManager(currentUserAccount, null);
await Assert.ThrowsAsync<ExpiredTokenException>(() => accountManager.GetSelectedSubscriptionsAsync());
Assert.ThrowsAsync<ExpiredTokenException>(() => accountManager.GetSelectedSubscriptionsAsync());
}
[Fact]
[Test]
public async Task GetSubscriptionShouldThrowIfFailed()
{
var currentUserAccount = CreateAccount();
IAzureAuthenticationManager accountManager = await CreateAccountManager(currentUserAccount, null, true);
await Assert.ThrowsAsync<ServiceFailedException>(() => accountManager.GetSelectedSubscriptionsAsync());
Assert.ThrowsAsync<ServiceFailedException>(() => accountManager.GetSelectedSubscriptionsAsync());
}
[Fact]
[Test]
public async Task GetSubscriptionShouldReturnTheListSuccessfully()
{
List<IAzureUserAccountSubscriptionContext> subscriptions = new List<IAzureUserAccountSubscriptionContext> {

View File

@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.ResourceProvider.Core;
using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
{
@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
/// </summary>
public class AzureDatabaseDiscoveryProviderTest
{
[Fact]
[Test]
public async Task GetShouldReturnDatabasesSuccessfully()
{
string databaseName1 = "server/db1";
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
Assert.True(list.Count() == 2);
}
[Fact]
[Test]
public async Task GetShouldReturnDatabasesEvenIfFailsForOneServer()
{
string databaseName1 = "server1/db1";
@@ -85,7 +85,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
Assert.True(response.Errors.Count() == 1);
}
[Fact]
[Test]
public async Task GetShouldReturnDatabasesFromCacheIfGetCalledTwice()
{
Dictionary<string, List<string>> subscriptionToDatabaseMap = CreateSubscriptonMap(2);
@@ -107,7 +107,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
ValidateResult(subscriptionToDatabaseMap, list);
}
[Fact]
[Test]
public async Task GetShouldReturnDatabasesFromServiceIfGetCalledTwiceButRefreshed()
{
Dictionary<string, List<string>> subscriptionToDatabaseMap = CreateSubscriptonMap(2);
@@ -187,7 +187,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
return subscriptionToDatabaseMapCopy;
}
[Fact]
[Test]
public async Task GetShouldReturnEmptyGivenNotSubscriptionFound()
{
Dictionary<string, List<string>> subscriptionToDatabaseMap = new Dictionary<string, List<string>>();

View File

@@ -5,13 +5,13 @@
using Microsoft.Azure.Management.Sql.Models;
using Microsoft.SqlTools.ResourceProvider.DefaultImpl;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
{
public class AzureResourceWrapperTest
{
[Fact]
[Test]
public void ShouldParseResourceGroupFromId()
{
// Given a resource with a known resource group
@@ -25,10 +25,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
string rgName = resource.ResourceGroupName;
// then I get it as expected
Assert.Equal("myresourcegroup", rgName);
Assert.AreEqual("myresourcegroup", rgName);
}
[Fact]
[Test]
public void ShouldHandleMissingResourceGroup()
{
// Given a resource without resource group in the ID
@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
string rgName = resource.ResourceGroupName;
// then I get string.Empty
Assert.Equal(string.Empty, rgName);
Assert.AreEqual(string.Empty, rgName);
}
private TrackedResource CreateMockResource(string id = null, string name = null, string type = null)

View File

@@ -8,7 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlTools.ResourceProvider.Core;
using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
{
@@ -17,7 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
/// </summary>
public class AzureSqlServerDiscoveryProviderTest
{
[Fact]
[Test]
public async Task GetShouldReturnServersSuccessfully()
{
string serverName = "server";
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
Assert.True(servers.Count() == 4);
}
[Fact]
[Test]
public async Task GetShouldReturnEmptyGivenNoSubscriptionFound()
{
Dictionary<string, List<string>> subscriptionToDatabaseMap = new Dictionary<string, List<string>>();

View File

@@ -4,7 +4,7 @@
using System;
using Microsoft.SqlTools.ResourceProvider.DefaultImpl;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
{
@@ -13,7 +13,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
/// </summary>
public class AzureSubscriptionContextTest
{
[Fact]
[Test]
public void SubscriptionNameShouldReturnNullGivenNullSubscription()
{
AzureSubscriptionContext subscriptionContext = new AzureSubscriptionContext(null);
@@ -21,7 +21,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
Assert.True(subscriptionContext.Subscription == null);
}
[Fact]
[Test]
public void SubscriptionNameShouldReturnCorrectValueGivenValidSubscription()
{
string name = Guid.NewGuid().ToString();

View File

@@ -12,7 +12,7 @@
//using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
//using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes;
//using Moq;
//using Xunit;
//using NUnit.Framework;
//namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
//{
@@ -48,7 +48,7 @@
// _dependencyManager = new DependencyManager(_serviceProperties);
// }
// [Fact]
// [Test]
// public void GetShouldReturnProvidersFromTheCatalog()
// {
// IEnumerable<ExportableDescriptor<IServerDiscoveryProvider>> providers =
@@ -56,19 +56,19 @@
// Assert.NotNull(providers);
// }
// [Fact]
// [Test]
// public void GetShouldReturnEmptyListGivenInvalidCategory()
// {
// Assert.False(_dependencyManager.GetServiceDescriptors<IServerDiscoveryProvider>(new ServerDefinition(null, "invalid category")).Any());
// }
// [Fact]
// [Test]
// public void GetShouldReturnEmptyListGivenInvalidServerType()
// {
// Assert.False(_dependencyManager.GetServiceDescriptors<IServerDiscoveryProvider>(new ServerDefinition("invalid server type", null)).Any());
// }
// [Fact]
// [Test]
// public void GetShouldReturnAllProvidersGivenNoParameter()
// {
// IEnumerable<ExportableDescriptor<IServerDiscoveryProvider>> providers =
@@ -77,7 +77,7 @@
// Assert.True(providers.Count() == _providers.Count());
// }
// [Fact]
// [Test]
// public void GetShouldReturnProvidersGivenServerType()
// {
// var serverType = "sqlServer";
@@ -88,7 +88,7 @@
// Assert.True(providers.Count() == _providers.Count(x => x.Metadata.ServerType.Equals(serverType, StringComparison.OrdinalIgnoreCase)));
// }
// [Fact]
// [Test]
// public void GetShouldReturnProvidersGivenCategory()
// {
// IEnumerable<ExportableDescriptor<IServerDiscoveryProvider>> providers =
@@ -97,7 +97,7 @@
// Assert.True(providers.Count() == 1);
// }
// [Fact]
// [Test]
// public void GetShouldReturnProviderForEmptyCategoryGivenEmptyCategory()
// {
// // Given choice of 2 providers, one with empty category and other with specified one
@@ -126,7 +126,7 @@
// Assert.True(foundProviders.Count() == 1);
// }
// [Fact]
// [Test]
// public void GetShouldReturnProviderGivenServerTypeAndLocationWithValidProvider()
// {
// IEnumerable<ExportableDescriptor<IServerDiscoveryProvider>> providers =
@@ -135,7 +135,7 @@
// Assert.True(providers.Count() == 1);
// }
// [Fact]
// [Test]
// public void GetShouldReturnTheServiceWithTheHighestPriorityIdMultipleFound()
// {
@@ -162,7 +162,7 @@
// Assert.True(descriptor.Exportable == expectedProvider);
// }
// [Fact]
// [Test]
// public void GetShouldReturnTheServiceEvenIfTheServerTypeNotSet()
// {
// IServerDiscoveryProvider expectedProvider = new Mock<IServerDiscoveryProvider>();
@@ -188,7 +188,7 @@
// Assert.True(descriptor.Exportable == expectedProvider);
// }
// [Fact]
// [Test]
// public void GetShouldReturnTheServiceThatMatchedExactlyIfServerTypeSpecified()
// {
// IServerDiscoveryProvider expectedProvider = new Mock<IServerDiscoveryProvider>();
@@ -214,7 +214,7 @@
// Assert.True(descriptor.Exportable == expectedProvider);
// }
// [Fact]
// [Test]
// public void GetShouldReturnTheServiceThatMatchedExactlyIfCategorySpecified()
// {
// IServerDiscoveryProvider expectedProvider = new Mock<IServerDiscoveryProvider>();
@@ -240,7 +240,7 @@
// Assert.True(descriptor.Exportable == expectedProvider);
// }
// [Fact]
// [Test]
// public void GetShouldReturnTheServiceEvenIfTheCategoryNotSet()
// {
@@ -267,7 +267,7 @@
// Assert.True(descriptor.Exportable == expectedProvider);
// }
// [Fact]
// [Test]
// public void GetShouldReturnProvidersGivenServerTypeAndMoreThanOneLocation()
// {
// var serverType = "sqlServer";
@@ -277,7 +277,7 @@
// Assert.True(providers.Count() == _providers.Count(x => x.Metadata.ServerType.Equals(serverType, StringComparison.OrdinalIgnoreCase)));
// }
// [Fact]
// [Test]
// public async Task ProviderCreatedByFactoryShouldReturnServersSuccessfully()
// {
// List<ServerInstanceInfo> expectedServers = _localSqlServers;
@@ -289,7 +289,7 @@
// ServiceResponse<ServerInstanceInfo> result = await provider.Exportable.GetServerInstancesAsync();
// var servers = result.Data;
// Assert.NotNull(servers);
// Assert.Equal(expectedServers, servers);
// Assert.AreEqual(expectedServers, servers);
// }
// }
//}

View File

@@ -6,7 +6,7 @@ using System;
using System.Data.Common;
using Microsoft.SqlTools.ResourceProvider.Core;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
{
@@ -15,34 +15,34 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
/// </summary>
public class ExceptionUtilTest
{
[Fact]
[Test]
public void IsSqlExceptionShouldReturnFalseGivenNullException()
{
Exception exception = null;
bool expected = false;
bool actual = exception.IsDbException();
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
[Fact]
[Test]
public void IsSqlExceptionShouldReturnFalseGivenNonSqlException()
{
Exception exception = new ApplicationException();
bool expected = false;
bool actual = exception.IsDbException();
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
[Fact]
[Test]
public void IsSqlExceptionShouldReturnFalseGivenNonSqlExceptionWithInternalException()
{
Exception exception = new ApplicationException("Exception message", new ServiceFailedException());
bool expected = false;
bool actual = exception.IsDbException();
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
[Fact]
[Test]
public void IsSqlExceptionShouldReturnTrueGivenSqlException()
{
Exception exception = CreateDbException();
@@ -50,10 +50,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
bool expected = true;
bool actual = exception.IsDbException();
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
[Fact]
[Test]
public void IsSqlExceptionShouldReturnTrueGivenExceptionWithInnerSqlException()
{
Exception exception = new ApplicationException("", CreateDbException());
@@ -61,7 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
bool expected = true;
bool actual = exception.IsDbException();
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
private Exception CreateDbException()

View File

@@ -4,7 +4,7 @@
using System;
using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
{
@@ -19,20 +19,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
private FirewallErrorParser _firewallErrorParser = new FirewallErrorParser();
[Fact]
[Test]
public void ParseExceptionShouldThrowExceptionGivenNullErrorMessage()
{
string errorMessage = null;
int errorCode = SqlAzureFirewallBlockedErrorNumber;
Assert.Throws<ArgumentNullException>("errorMessage", () =>
Assert.Throws<ArgumentNullException>(() =>
{
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(errorMessage, errorCode);
Assert.False(response.FirewallRuleErrorDetected);
});
}
[Fact]
[Test]
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenDifferentError()
{
int errorCode = 123;
@@ -41,7 +40,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.False(response.FirewallRuleErrorDetected);
}
[Fact]
[Test]
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenLoginFailedError()
{
int errorCode = SqlAzureLoginFailedErrorNumber;
@@ -50,7 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.False(response.FirewallRuleErrorDetected);
}
[Fact]
[Test]
public void ParseExceptionShouldReturnFireWallRuleNotDetectedGivenInvalidErrorMessage()
{
int errorCode = SqlAzureFirewallBlockedErrorNumber;
@@ -59,13 +58,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.False(response.FirewallRuleErrorDetected);
}
[Fact]
[Test]
public void ParseExceptionShouldReturnFireWallRuleDetectedGivenValidErrorMessage()
{
int errorCode = SqlAzureFirewallBlockedErrorNumber;
FirewallParserResponse response = _firewallErrorParser.ParseErrorMessage(_errorMessage, errorCode);
Assert.True(response.FirewallRuleErrorDetected);
Assert.Equal(response.BlockedIpAddress.ToString(), "1.2.3.4");
Assert.AreEqual("1.2.3.4", response.BlockedIpAddress.ToString());
}
}
}

View File

@@ -10,7 +10,7 @@ using Microsoft.SqlTools.ResourceProvider.Core;
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
{
@@ -19,55 +19,55 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
/// </summary>
public class FirewallRuleServiceTest
{
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenNullServerName()
{
string serverName = null;
ServiceTestContext testContext = new ServiceTestContext();
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenNullStartIp()
{
string serverName = "serverName";
ServiceTestContext testContext = new ServiceTestContext();
testContext.StartIpAddress = null;
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenInvalidEndIp()
{
string serverName = "serverName";
ServiceTestContext testContext = new ServiceTestContext();
testContext.EndIpAddress = "invalid ip";
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenInvalidStartIp()
{
string serverName = "serverName";
ServiceTestContext testContext = new ServiceTestContext();
testContext.StartIpAddress = "invalid ip";
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, serverName));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenNullEndIp()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext.EndIpAddress = null;
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionIfUserIsNotLoggedIn()
{
var applicationAuthenticationManagerMock = new Mock<IAzureAuthenticationManager>();
@@ -78,13 +78,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
testContext.ApplicationAuthenticationManagerMock = applicationAuthenticationManagerMock;
testContext.AzureResourceManagerMock = azureResourceManagerMock;
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
azureResourceManagerMock.Verify(x => x.CreateFirewallRuleAsync(
It.IsAny<IAzureResourceManagementSession>(), It.IsAny<IAzureSqlServerResource>(), It.IsAny<FirewallRuleRequest>()),
Times.Never);
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionIfUserDoesNotHaveSubscriptions()
{
var applicationAuthenticationManagerMock =
@@ -98,13 +98,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
testContext.ApplicationAuthenticationManagerMock = applicationAuthenticationManagerMock;
testContext.AzureResourceManagerMock = azureResourceManagerMock;
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
azureResourceManagerMock.Verify(x => x.CreateFirewallRuleAsync(
It.IsAny<IAzureResourceManagementSession>(), It.IsAny<IAzureSqlServerResource>(), It.IsAny<FirewallRuleRequest>()),
Times.Never);
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionIfAuthenticationManagerFailsToReturnSubscription()
{
var applicationAuthenticationManagerMock = new Mock<IAzureAuthenticationManager>();
@@ -115,23 +115,23 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
ServiceTestContext testContext = new ServiceTestContext();
testContext.ApplicationAuthenticationManagerMock = applicationAuthenticationManagerMock;
testContext.AzureResourceManagerMock = azureResourceManagerMock;
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, "invalid server"));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, "invalid server"));
azureResourceManagerMock.Verify(x => x.CreateFirewallRuleAsync(
It.IsAny<IAzureResourceManagementSession>(), It.IsAny<IAzureSqlServerResource>(), It.IsAny<FirewallRuleRequest>()),
Times.Never);
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionGivenNoSubscriptionFound()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext = CreateMocks(testContext);
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, "invalid server"));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, "invalid server"));
}
[Fact]
[Test]
public async Task CreateShouldCreateFirewallSuccessfullyGivenValidUserAccount()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -140,7 +140,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightSubscriptionGivenValidSubscriptionInFirstPlace()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -156,7 +156,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightSubscriptionGivenValidSubscriptionInSecondPlace()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -171,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightSubscriptionGivenValidSubscriptionInLastPlace()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -188,7 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightResourceGivenValidResourceInLastPlace()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -204,7 +204,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightResourceGivenValidResourceInFirstPlace()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -220,7 +220,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateShouldFindTheRightResourceGivenValidResourceInMiddle()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -237,7 +237,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
await VerifyCreateAsync(testContext, testContext.ServerName);
}
[Fact]
[Test]
public async Task CreateThrowExceptionIfResourceNotFound()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -250,10 +250,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
testContext = CreateMocks(testContext);
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName));
}
[Fact]
[Test]
public async Task CreateThrowExceptionIfResourcesIsEmpty()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -261,10 +261,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
testContext.SubscriptionToResourcesMap[testContext.ValidSubscription.Subscription.SubscriptionId] = new List<IAzureSqlServerResource>();
testContext = CreateMocks(testContext);
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionIfThereIsNoSubscriptionForUser()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -272,11 +272,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
testContext = CreateMocks(testContext);
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
}
[Fact]
[Test]
public async Task CreateShouldThrowExceptionIfSubscriptionIsInAnotherAccount()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -287,10 +287,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
};
testContext = CreateMocks(testContext);
await Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
Assert.ThrowsAsync<FirewallRuleException>(() => VerifyCreateAsync(testContext, testContext.ServerName, false));
}
[Fact]
[Test]
public async Task CreateShouldCreateFirewallForTheRightServerFullyQualifiedName()
{
ServiceTestContext testContext = new ServiceTestContext();

View File

@@ -17,7 +17,7 @@ using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
using Microsoft.SqlTools.ResourceProvider.DefaultImpl;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
@@ -47,7 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
protected ResourceProviderService ResourceProviderService { get; private set; }
[Fact]
[Test]
public async Task TestHandleFirewallRuleIgnoresNonMssqlProvider()
{
// Given a non-MSSQL provider
@@ -64,11 +64,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
Assert.NotNull(response);
Assert.False(response.Result);
Assert.Null(response.IpAddress);
Assert.Equal(Microsoft.SqlTools.ResourceProvider.Core.SR.FirewallRuleUnsupportedConnectionType, response.ErrorMessage);
Assert.AreEqual(Microsoft.SqlTools.ResourceProvider.Core.SR.FirewallRuleUnsupportedConnectionType, response.ErrorMessage);
});
}
[Fact]
[Test]
public async Task TestHandleFirewallRuleSupportsMssqlProvider()
{
// Given a firewall error for the MSSQL provider
@@ -84,12 +84,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
// Then I expect the response to be true and the IP address to be extracted
Assert.NotNull(response);
Assert.True(response.Result);
Assert.Equal("1.2.3.4", response.IpAddress);
Assert.AreEqual("1.2.3.4", response.IpAddress);
Assert.Null(response.ErrorMessage);
});
}
[Fact]
[Test]
public async Task TestHandleFirewallRuleIgnoresNonFirewallErrors()
{
// Given a login error for the MSSQL provider
@@ -105,12 +105,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
// Then I expect the response to be false and no IP address to be defined
Assert.NotNull(response);
Assert.False(response.Result);
Assert.Equal(string.Empty, response.IpAddress);
Assert.AreEqual(string.Empty, response.IpAddress);
Assert.Null(response.ErrorMessage);
});
}
[Fact]
[Test]
public async Task TestHandleFirewallRuleDoesntBreakWithoutIp()
{
// Given a firewall error with no IP address in the error message
@@ -126,12 +126,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
// Then I expect the response to be OK as we require the known IP address to function
Assert.NotNull(response);
Assert.False(response.Result);
Assert.Equal(string.Empty, response.IpAddress);
Assert.AreEqual(string.Empty, response.IpAddress);
Assert.Null(response.ErrorMessage);
});
}
[Fact]
[Test]
public async Task TestCreateFirewallRuleBasicRequest()
{
// Given a firewall request for a valid subscription
@@ -176,7 +176,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
});
}
[Fact]
[Test]
public async Task TestCreateFirewallRuleHandlesTokenExpiration()
{
// Given the token has expired
@@ -201,7 +201,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
// Then I expect the response to indicate that we failed due to token expiration
Assert.NotNull(response);
Assert.Equal(expectedErrorMsg, response.ErrorMessage);
Assert.AreEqual(expectedErrorMsg, response.ErrorMessage);
Assert.True(response.IsTokenExpiredFailure);
Assert.False(response.Result);
});

View File

@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure;
using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
{
@@ -40,7 +40,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
};
}
[Fact]
[Test]
public void GetServiceShouldReturnTheServiceThatHasGivenMetadataCorrectly()
{
//given
@@ -55,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.True(service.GetType() == typeof(FakeSecureServerDiscoveryProvider));
}
[Fact]
[Test]
public void GetServiceShouldReturnNullGivenInvalidMetadata()
{
//given
@@ -69,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.Null(service);
}
[Fact]
[Test]
public void GetServiceShouldReturnNullGivenUnSupportedMetadata()
{
//given
@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.Null(service);
}
[Fact]
[Test]
public void RequiresUserAccountShouldReturnFalseGivenNotSecuredService()
{
//given
@@ -97,7 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.NotNull(service);
}
[Fact]
[Test]
public void GetShouldReturnDefaultAzureServiceGivenDefaultCatalog()
{
// given
@@ -127,7 +127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Fact]
[Test]
public void GetShouldReturnImplementedAzureServiceIfFoundInCatalog()
{
//given
@@ -140,7 +140,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
Assert.True(serverDiscoveryProvider is FakeAzureServerDiscoveryProvider);
}
[Fact]
[Test]
public void GetGetServiceOfExportableShouldReturnNullGivenSameTypeAsExportable()
{
//given