mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Enabling database properties general tab with real time values from SMO (#2093)
* initial commit with all required db handler and props, also getting the data from ADS * database properties view updated * Delete Microsoft.SqlTools.ServiceLayer.sln This file should be ignored * Removed unwanted file * Using DatabaseHandler for properties as one handler per object * removed unused and unnecessary changes * minimal updates * moving type conversion to UI side, properties with original types. * conversion number fixed * Adding Localized strings * using existing objectUrn logic to get the smo object * Adding Integration tests for database properties verification * refactoring * updating test
This commit is contained in:
committed by
GitHub
parent
532f7b0912
commit
5c7dae40e6
@@ -260,6 +260,50 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
/// This test validates the newly created database properties and verifies with some default values
|
||||
public async Task VerifyDatabasePropertiesTest()
|
||||
{
|
||||
// setup, drop database if exists.
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", serverType: TestServerType.OnPrem);
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connectionResult.ConnectionInfo))
|
||||
{
|
||||
var server = new Server(new ServerConnection(sqlConn));
|
||||
|
||||
var testDatabase = ObjectManagementTestUtils.GetTestDatabaseInfo();
|
||||
var objUrn = ObjectManagementTestUtils.GetDatabaseURN(testDatabase.Name);
|
||||
await ObjectManagementTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, objUrn);
|
||||
|
||||
try
|
||||
{
|
||||
// create database
|
||||
var parametersForCreation = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, "master", true, SqlObjectType.Database, "", "");
|
||||
await ObjectManagementTestUtils.SaveObject(parametersForCreation, testDatabase);
|
||||
Assert.That(DatabaseExists(testDatabase.Name!, server), $"Expected database '{testDatabase.Name}' was not created succesfully");
|
||||
|
||||
// Get database properties and verify
|
||||
var parametersForUpdate = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, testDatabase.Name, false, SqlObjectType.Database, "", objUrn);
|
||||
DatabaseViewInfo databaseViewInfo = await ObjectManagementTestUtils.GetDatabaseObject(parametersForUpdate, testDatabase);
|
||||
Assert.That(databaseViewInfo.ObjectInfo, Is.Not.Null, $"Expected result should not be empty");
|
||||
Assert.That(databaseViewInfo.ObjectInfo.Name, Is.EqualTo(testDatabase.Name), $"database name should be matched");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).DateCreated, Is.Not.Null, $"database name should be matched");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).NumberOfUsers, Is.GreaterThan(0), $"Default database users count should not be zero");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).LastDatabaseBackup, Is.EqualTo(testDatabase.LastDatabaseBackup), $"Should have no database last backup date");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).LastDatabaseLogBackup, Is.EqualTo(testDatabase.LastDatabaseLogBackup), $"Should have no database backup log date");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).SizeInMb, Is.GreaterThan(0), $"Should have default database size when created");
|
||||
|
||||
// cleanup
|
||||
await ObjectManagementTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, objUrn, throwIfNotExist: true);
|
||||
Assert.That(DatabaseExists(testDatabase.Name!, server), Is.False, $"Database '{testDatabase.Name}' was not dropped succesfully");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup using SMO if Drop didn't work
|
||||
DropDatabase(server, testDatabase.Name!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool DatabaseExists(string dbName, Server server)
|
||||
{
|
||||
server.Databases.Refresh();
|
||||
|
||||
@@ -70,7 +70,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
CollationName = "SQL_Latin1_General_CP1_CI_AS",
|
||||
CompatibilityLevel = "SQL Server 2022 (160)",
|
||||
ContainmentType = "None",
|
||||
RecoveryModel = "Full"
|
||||
RecoveryModel = "Full",
|
||||
LastDatabaseBackup = "None",
|
||||
LastDatabaseLogBackup = "None"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -152,6 +154,26 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
await Service.HandleDisposeViewRequest(new DisposeViewRequestParams { ContextId = parameters.ContextId }, disposeViewRequestContext.Object);
|
||||
}
|
||||
|
||||
internal static async Task<DatabaseViewInfo> GetDatabaseObject(InitializeViewRequestParams parameters, SqlObject obj)
|
||||
{
|
||||
// Initialize the view
|
||||
DatabaseViewInfo databaseViewInfo = new DatabaseViewInfo();
|
||||
var initViewRequestContext = new Mock<RequestContext<SqlObjectViewInfo>>();
|
||||
initViewRequestContext
|
||||
.Setup(x => x.SendResult(It.IsAny<SqlObjectViewInfo>()))
|
||||
.Returns(Task.FromResult<SqlObjectViewInfo>(null))
|
||||
.Callback<DatabaseViewInfo>(r => databaseViewInfo = r);
|
||||
await Service.HandleInitializeViewRequest(parameters, initViewRequestContext.Object);
|
||||
|
||||
// Dispose the view
|
||||
var disposeViewRequestContext = new Mock<RequestContext<DisposeViewRequestResponse>>();
|
||||
disposeViewRequestContext.Setup(x => x.SendResult(It.IsAny<DisposeViewRequestResponse>()))
|
||||
.Returns(Task.FromResult<DisposeViewRequestResponse>(new DisposeViewRequestResponse()));
|
||||
await Service.HandleDisposeViewRequest(new DisposeViewRequestParams { ContextId = parameters.ContextId }, disposeViewRequestContext.Object);
|
||||
|
||||
return databaseViewInfo;
|
||||
}
|
||||
|
||||
internal static async Task<string> ScriptObject(InitializeViewRequestParams parameters, SqlObject obj)
|
||||
{
|
||||
// Initialize the view
|
||||
|
||||
Reference in New Issue
Block a user