Skip to content

Commit 26e9c39

Browse files
committed
code review feedback
1 parent b765d31 commit 26e9c39

12 files changed

Lines changed: 1054 additions & 1008 deletions

File tree

.gitignore

Lines changed: 439 additions & 437 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
# SmoSamples
2-
3-
This unit test project is meant to demonstrate features of the Sql Management Objects framework and to help developers optimize performance of their SMO-based applications.
4-
5-
6-
### Contents
7-
8-
[About this sample](#about-this-sample)<br/>
9-
[Before you begin](#before-you-begin)<br/>
10-
[Run this sample](#run-this-sample)<br/>
11-
[Sample details](#sample-details)<br/>
12-
[Disclaimers](#disclaimers)<br/>
13-
[Related links](#related-links)<br/>
14-
15-
16-
<a name=about-this-sample></a>
17-
18-
## About this sample
19-
20-
<!-- Delete the ones that don't apply -->
21-
- **Applies to:** SQL Server 2016 (or higher), Azure SQL Database, Azure SQL Data Warehouse
22-
- **Key features:**
23-
- Unit tests and a docker file that demonstrate proper use of SMO features against a working SQL Server instance.
24-
- **Programming Language:**
25-
- C#
26-
27-
<a name=before-you-begin></a>
28-
29-
## Before you begin
30-
31-
To run this sample, you need the following prerequisites.
32-
33-
**Software prerequisites:**
34-
35-
1. SQL Server 2016 (or higher) or an Azure SQL Database with the full WideWorldImporters sample database, or
36-
2. Docker
37-
3. At minimum the dotnet 2.2 SDK, or Visual Studio 2017
38-
39-
<a name=run-this-sample></a>
40-
41-
## Run this sample
42-
43-
44-
<a name=sample-details></a>
45-
46-
## Sample details
47-
48-
Each unit test demonstrates a specific aspect of SMO-based application development, either in isolation or in conjunction with other SMO components. <br/>
49-
Feature areas tested include:
50-
1. Efficient use of collections
51-
2. Sql query capture
52-
3. Events
53-
4. URNs
54-
5. Script generation
55-
56-
57-
<a name=related-links></a>
58-
59-
## Related Links
60-
The SMO NuGet package is at https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects/ <br/>
61-
Documentation for the APIs is at https://docs.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/overview-smo<br/>
1+
# SmoSamples
2+
3+
This unit test project is meant to demonstrate features of the Sql Management Objects framework and to help developers optimize performance of their SMO-based applications.
4+
5+
6+
### Contents
7+
8+
[About this sample](#about-this-sample)<br/>
9+
[Before you begin](#before-you-begin)<br/>
10+
[Run this sample](#run-this-sample)<br/>
11+
[Sample details](#sample-details)<br/>
12+
[Disclaimers](#disclaimers)<br/>
13+
[Related links](#related-links)<br/>
14+
15+
16+
<a name=about-this-sample></a>
17+
18+
## About this sample
19+
20+
<!-- Delete the ones that don't apply -->
21+
- **Applies to:** SQL Server 2016 (or higher), Azure SQL Database, Azure SQL Data Warehouse
22+
- **Key features:**
23+
- Unit tests and a docker file that demonstrate proper use of SMO features against a working SQL Server instance.
24+
- **Programming Language:**
25+
- C#
26+
27+
<a name=before-you-begin></a>
28+
29+
## Before you begin
30+
31+
To run this sample, you need the following prerequisites.
32+
33+
**Software prerequisites:**
34+
35+
1. SQL Server 2016 (or higher) or an Azure SQL Database with the full WideWorldImporters sample database, or
36+
2. Docker
37+
3. At minimum the dotnet 2.2 SDK, or Visual Studio 2017
38+
39+
<a name=run-this-sample></a>
40+
41+
## Run this sample
42+
If using Docker, use runtests.sh or runtests.cmd as appropriate. If using a separate instance of SQL Server or Azure SQL Database, create a .runsettings file and run the unit tests using Visual Studio or "dotnet vstest".
43+
44+
<a name=sample-details></a>
45+
46+
## Sample details
47+
48+
Each unit test demonstrates a specific aspect of SMO-based application development, either in isolation or in conjunction with other SMO components. <br/>
49+
Feature areas tested include:
50+
1. Efficient use of collections
51+
2. Sql query capture
52+
3. Events
53+
4. URNs
54+
5. Script generation
55+
56+
57+
<a name=related-links></a>
58+
59+
## Related Links
60+
The SMO NuGet package is at https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects/ <br/>
61+
Documentation for the APIs is at https://docs.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo<br/>
6262
The WideWorldImporters sample database can be found at https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak <br/>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM mcr.microsoft.com/mssql/server:2017-latest
2-
WORKDIR /tmp/backup
3-
RUN wget -q https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak
4-
COPY restore.sql .
5-
COPY restore.sh .
6-
COPY entrypoint.sh .
7-
CMD ["/bin/bash", "/tmp/backup/entrypoint.sh"]
8-
1+
FROM mcr.microsoft.com/mssql/server:2017-latest
2+
WORKDIR /tmp/backup
3+
RUN wget -q https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak
4+
COPY restore.sql .
5+
COPY restore.sh .
6+
COPY entrypoint.sh .
7+
CMD ["/bin/bash", "/tmp/backup/entrypoint.sh"]
8+

samples/features/sql-management-objects/prep/restore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Wait for SQL Server to start and be ready to accept connections
12
sleep 35s
23
echo sa_password is $SA_PASSWORD
34
/opt/mssql-tools/bin/sqlcmd -S . -U sa -P $SA_PASSWORD -i /tmp/backup/restore.sql
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
RESTORE DATABASE WideWorldImporters FROM DISK = "/tmp/backup/WideWorldImporters-Full.bak"
2-
WITH MOVE "WWI_Primary" TO "/var/opt/mssql/data/WideWorldImporters.mdf",
3-
MOVE "WWI_Userdata" TO "/var/opt/mssql/data/WideWorldImporters_UserData.ndf",
4-
MOVE "WWI_Log" TO "/var/opt/mssql/data/WideWorldImporters.ldf", MOVE "WWI_InMemory_Data_1"
1+
RESTORE DATABASE WideWorldImporters FROM DISK = "/tmp/backup/WideWorldImporters-Full.bak"
2+
WITH MOVE "WWI_Primary" TO "/var/opt/mssql/data/WideWorldImporters.mdf",
3+
MOVE "WWI_Userdata" TO "/var/opt/mssql/data/WideWorldImporters_UserData.ndf",
4+
MOVE "WWI_Log" TO "/var/opt/mssql/data/WideWorldImporters.ldf", MOVE "WWI_InMemory_Data_1"
55
TO "/var/opt/mssql/data/WideWorldImporters_InMemory_Data_1"

samples/features/sql-management-objects/src/CollectionSamples.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-

2-
using System.Diagnostics;
3-
using Microsoft.SqlServer.Management.Smo;
4-
5-
namespace Microsoft.SqlServer.SmoSamples
1+
namespace Microsoft.SqlServer.SmoSamples
62
{
73
using System;
84
using System.Collections.Generic;
5+
using System.Diagnostics;
96
using System.Text;
7+
using Microsoft.SqlServer.Management.Smo;
108
using Microsoft.VisualStudio.TestTools.UnitTesting;
119
using NUnit.Framework;
1210
using Assert = NUnit.Framework.Assert;
@@ -16,6 +14,12 @@ public class CollectionSamples
1614
{
1715
public VisualStudio.TestTools.UnitTesting.TestContext TestContext { get; set; }
1816

17+
/// <summary>
18+
/// SetDefaultInitFields tells the Server object which properties to include in the initial query
19+
/// to populate of a given object type when initialized a collection of that type.
20+
/// The test demonstrates the effect of using this call to enumerate Tables when accessing the FileGroup
21+
/// property of each Table object
22+
/// </summary>
1923
[TestMethod]
2024
public void Collection_iteration_is_faster_with_SetDefaultInitFields()
2125
{
@@ -26,11 +30,14 @@ public void Collection_iteration_is_faster_with_SetDefaultInitFields()
2630
connectionMetrics.Reset();
2731
foreach (Table table in database.Tables)
2832
{
33+
// Accessing FileGroup triggers a query to fetch it
2934
Trace.TraceInformation(
3035
$"Unoptimized table Name: {table.Name}\tSchema:{table.Schema}\tFileGroup:{table.FileGroup}");
3136
}
3237

33-
var unoptimizedMetrics = (connectionMetrics.QueryCount, connectionMetrics.BytesSent, connectionMetrics.BytesRead, connectionMetrics.ConnectionCount);
38+
var unoptimizedMetrics = (QueryCount: connectionMetrics.QueryCount,
39+
BytesSent: connectionMetrics.BytesSent, BytesRead: connectionMetrics.BytesRead,
40+
ConnectionCount: connectionMetrics.ConnectionCount);
3441
Trace.TraceInformation(string.Join($"{Environment.NewLine}\t", new[]
3542
{
3643
"Unoptimized metrics:",
@@ -43,11 +50,14 @@ public void Collection_iteration_is_faster_with_SetDefaultInitFields()
4350
database.Tables.Refresh();
4451
foreach (Table table in database.Tables)
4552
{
53+
// The FileGroup property is already populated, so no extra query is needed
4654
Trace.TraceInformation(
4755
$"Optimized table Name: {table.Name}\tSchema:{table.Schema}\tFileGroup:{table.FileGroup}");
4856
}
4957

50-
var optimizedMetrics = (connectionMetrics.QueryCount, connectionMetrics.BytesSent, connectionMetrics.BytesRead, connectionMetrics.ConnectionCount);
58+
var optimizedMetrics = (QueryCount: connectionMetrics.QueryCount,
59+
BytesSent: connectionMetrics.BytesSent, BytesRead: connectionMetrics.BytesRead,
60+
ConnectionCount: connectionMetrics.ConnectionCount);
5161
Trace.TraceInformation(string.Join($"{Environment.NewLine}\t", new[]
5262
{
5363
"Optimized Metrics:",

0 commit comments

Comments
 (0)