Feature/more tests (#154)

* First batch of new tests for increasing code coverage

* Fix for merge

* Added comments to tests
This commit is contained in:
Mitchell Sternke
2016-11-22 09:55:15 -08:00
committed by GitHub
parent db1e4ae351
commit 2e3bd3ae27
2 changed files with 85 additions and 0 deletions

View File

@@ -891,5 +891,74 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
}
});
}
/// <summary>
/// Test that the connection complete notification type can be created.
/// </summary>
[Fact]
public void TestConnectionCompleteNotificationIsCreated()
{
Assert.NotNull(ConnectionCompleteNotification.Type);
}
/// <summary>
/// Test that the connection summary comparer creates a hash code correctly
/// <summary>
[Theory]
[InlineData(true, null, null ,null)]
[InlineData(false, null, null, null)]
[InlineData(false, null, null, "sa")]
[InlineData(false, null, "test", null)]
[InlineData(false, null, "test", "sa")]
[InlineData(false, "server", null, null)]
[InlineData(false, "server", null, "sa")]
[InlineData(false, "server", "test", null)]
[InlineData(false, "server", "test", "sa")]
public void TestConnectionSummaryComparerHashCode(bool objectNull, string serverName, string databaseName, string userName)
{
// Given a connection summary and comparer object
ConnectionSummary summary = null;
if (!objectNull)
{
summary = new ConnectionSummary()
{
ServerName = serverName,
DatabaseName = databaseName,
UserName = userName
};
}
ConnectionSummaryComparer comparer = new ConnectionSummaryComparer();
// If I compute a hash code
int hashCode = comparer.GetHashCode(summary);
if (summary == null || (serverName == null && databaseName == null && userName == null))
{
// Then I expect it to be 31 for a null summary
Assert.Equal(31, hashCode);
}
else
{
// And not 31 otherwise
Assert.NotEqual(31, hashCode);
}
}
[Fact]
public void ConnectParamsAreInvalidIfConnectionIsNull()
{
// Given connection parameters where the connection property is null
ConnectParams parameters = new ConnectParams();
parameters.OwnerUri = "my/sql/file.sql";
parameters.Connection = null;
string errorMessage;
// If I check if the parameters are valid
Assert.False(parameters.IsValid(out errorMessage));
// Then I expect an error message
Assert.NotNull(errorMessage);
Assert.NotEmpty(errorMessage);
}
}
}

View File

@@ -720,6 +720,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
Assert.True(SqlSchemaModelErrorCodes.IsInterpretationErrorCode(Interpretation.InterpretationBaseCode+ 1));
Assert.True(SqlSchemaModelErrorCodes.IsStatementFilterError(StatementFilter.StatementFilterBaseCode + 1));
}
[Fact]
public void RetryCallbackEventArgsTest()
{
var exception = new Exception();
var timespan = TimeSpan.FromMinutes(1);
// Given a RetryCallbackEventArgs object with certain parameters
var args = new RetryCallbackEventArgs(5, exception, timespan);
// If I check the properties on the object
// Then I expect the values to be the same as the values I passed into the constructor
Assert.Equal(5, args.RetryCount);
Assert.Equal(exception, args.Exception);
Assert.Equal(timespan, args.Delay);
}
}
}