-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding test db project and corbertura summary
- Loading branch information
Showing
187 changed files
with
4,636 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/SQLCover/test/DatabaseWithTests/Accelerator/Functions/GetParticlesInRectangle.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
CREATE FUNCTION Accelerator.GetParticlesInRectangle( | ||
@X1 DECIMAL(10,2), | ||
@Y1 DECIMAL(10,2), | ||
@X2 DECIMAL(10,2), | ||
@Y2 DECIMAL(10,2) | ||
) | ||
RETURNS TABLE | ||
AS RETURN ( | ||
SELECT Id, X, Y, Value | ||
FROM Accelerator.Particle | ||
WHERE X > @X1 AND X < @X2 | ||
AND | ||
Y > @Y1 AND Y < @Y2 | ||
); |
9 changes: 9 additions & 0 deletions
9
src/SQLCover/test/DatabaseWithTests/Accelerator/Functions/GetStatusMessage.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
CREATE FUNCTION Accelerator.GetStatusMessage() | ||
RETURNS NVARCHAR(MAX) | ||
AS | ||
BEGIN | ||
DECLARE @NumParticles INT; | ||
SELECT @NumParticles = COUNT(1) FROM Accelerator.Particle; | ||
RETURN 'The Accelerator is prepared with ' + CAST(@NumParticles AS NVARCHAR(MAX)) + ' particles.'; | ||
END; |
14 changes: 14 additions & 0 deletions
14
src/SQLCover/test/DatabaseWithTests/Accelerator/Functions/IsExperimentReady.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
CREATE FUNCTION Accelerator.IsExperimentReady() | ||
RETURNS BIT | ||
AS | ||
BEGIN | ||
DECLARE @NumParticles INT; | ||
|
||
SELECT @NumParticles = COUNT(1) FROM Accelerator.Particle; | ||
|
||
IF @NumParticles > 2 | ||
RETURN 1; | ||
|
||
RETURN 0; | ||
END; |
10 changes: 10 additions & 0 deletions
10
...SQLCover/test/DatabaseWithTests/Accelerator/Stored Procedures/AlertParticleDiscovered.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
CREATE PROCEDURE Accelerator.AlertParticleDiscovered | ||
@ParticleDiscovered NVARCHAR(MAX) | ||
AS | ||
BEGIN | ||
IF @ParticleDiscovered = 'Higgs Boson' | ||
BEGIN | ||
EXEC Accelerator.SendHiggsBosonDiscoveryEmail '[email protected]'; | ||
END; | ||
END; |
7 changes: 7 additions & 0 deletions
7
...ver/test/DatabaseWithTests/Accelerator/Stored Procedures/SendHiggsBosonDiscoveryEmail.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
CREATE PROCEDURE Accelerator.SendHiggsBosonDiscoveryEmail | ||
@EmailAddress NVARCHAR(MAX) | ||
AS | ||
BEGIN | ||
RAISERROR('Not Implemented - yet',16,10); | ||
END; |
6 changes: 6 additions & 0 deletions
6
src/SQLCover/test/DatabaseWithTests/Accelerator/Tables/Color.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE [Accelerator].[Color] ( | ||
[Id] INT IDENTITY (1, 1) NOT NULL, | ||
[ColorName] NVARCHAR (MAX) NOT NULL, | ||
CONSTRAINT [PK_Color_Id] PRIMARY KEY CLUSTERED ([Id] ASC) | ||
); | ||
|
10 changes: 10 additions & 0 deletions
10
src/SQLCover/test/DatabaseWithTests/Accelerator/Tables/Particle.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE [Accelerator].[Particle] ( | ||
[Id] INT IDENTITY (1, 1) NOT NULL, | ||
[X] DECIMAL (10, 2) NOT NULL, | ||
[Y] DECIMAL (10, 2) NOT NULL, | ||
[Value] NVARCHAR (MAX) NOT NULL, | ||
[ColorId] INT NOT NULL, | ||
CONSTRAINT [PK_Point_Id] PRIMARY KEY CLUSTERED ([Id] ASC), | ||
CONSTRAINT [FK_ParticleColor] FOREIGN KEY ([ColorId]) REFERENCES [Accelerator].[Color] ([Id]) | ||
); | ||
|
39 changes: 39 additions & 0 deletions
39
...es/test a particle is included only if it fits inside the boundaries of the rectangle.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test a particle is included only if it fits inside the boundaries of the rectangle] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle table to make sure it is empty and that constraints will not be a problem | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
-- Populate the Particle table with rows that hug the rectangle boundaries | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 1, -0.01, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 2, 0.00, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 3, 0.01, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 4, 0.99, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 5, 1.00, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 6, 1.01, 0.50); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 7, 0.50, -0.01); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 8, 0.50, 0.00); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES ( 9, 0.50, 0.01); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES (10, 0.50, 0.99); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES (11, 0.50, 1.00); | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES (12, 0.50, 1.01); | ||
|
||
--Act: Call the GetParticlesInRectangle Table-Valued Function and capture the relevant columns into the #Actual temp table | ||
SELECT Id, X, Y | ||
INTO #Actual | ||
FROM Accelerator.GetParticlesInRectangle(0.0, 0.0, 1.0, 1.0); | ||
|
||
--Assert: Create an empty #Expected temp table that has the same structure as the #Actual table | ||
SELECT TOP(0) * | ||
INTO #Expected | ||
FROM #Actual; | ||
|
||
-- The expected data is inserted into the #Expected table | ||
INSERT INTO #Expected (Id, X, Y) VALUES (3, 0.01, 0.50); | ||
INSERT INTO #Expected (Id, X, Y) VALUES (4, 0.99, 0.50); | ||
INSERT INTO #Expected (Id, X, Y) VALUES (9, 0.50, 0.01); | ||
INSERT INTO #Expected (Id, X, Y) VALUES (10, 0.50, 0.99); | ||
|
||
-- Compare the data in the #Expected and #Actual tables | ||
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'; | ||
END; |
25 changes: 25 additions & 0 deletions
25
...test a particle within the rectangle is returned with an Id, Point Location and Value.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test a particle within the rectangle is returned with an Id, Point Location and Value] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle table to make sure it is empty and that constraints will not be a problem | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
-- Put a test particle into the table | ||
INSERT INTO Accelerator.Particle (Id, X, Y, Value) VALUES (1, 0.5, 0.5, 'MyValue'); | ||
|
||
--Act: Call the GetParticlesInRectangle Table-Valued Function and capture the relevant columns into the #Actual temp table | ||
SELECT Id, X, Y, Value | ||
INTO #Actual | ||
FROM Accelerator.GetParticlesInRectangle(0.0, 0.0, 1.0, 1.0); | ||
|
||
--Assert: Create an empty #Expected temp table that has the same structure as the #Actual table | ||
SELECT TOP(0) * | ||
INTO #Expected | ||
FROM #Actual; | ||
|
||
-- A single row with the expected data is inserted into the #Expected table | ||
INSERT INTO #Expected (Id, X, Y, Value) VALUES (1, 0.5, 0.5, 'MyValue'); | ||
|
||
-- Compare the data in the #Expected and #Actual tables | ||
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'; | ||
END; |
25 changes: 25 additions & 0 deletions
25
...s/AcceleratorTests/Stored Procedures/test a particle within the rectangle is returned.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test a particle within the rectangle is returned] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle table to make sure it is empty and that constraints will not be a problem | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
-- Put a test particle into the table | ||
INSERT INTO Accelerator.Particle (Id, X, Y) VALUES (1, 0.5, 0.5); | ||
|
||
--Act: Call the GetParticlesInRectangle Table-Valued Function and capture the Id column into the #Actual temp table | ||
SELECT Id | ||
INTO #Actual | ||
FROM Accelerator.GetParticlesInRectangle(0.0, 0.0, 1.0, 1.0); | ||
|
||
--Assert: Create an empty #Expected temp table that has the same structure as the #Actual table | ||
SELECT TOP(0) * | ||
INTO #Expected | ||
FROM #Actual; | ||
|
||
-- A single row with an Id value of 1 is expected | ||
INSERT INTO #Expected (Id) VALUES (1); | ||
|
||
-- Compare the data in the #Expected and #Actual tables | ||
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'; | ||
END; |
26 changes: 26 additions & 0 deletions
26
...red Procedures/test email is not sent if we detected something other than higgs-boson.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
CREATE PROCEDURE AcceleratorTests.[test email is not sent if we detected something other than higgs-boson] | ||
AS | ||
BEGIN | ||
--Assemble: Replace the SendHiggsBosonDiscoveryEmail with a spy. | ||
EXEC tSQLt.SpyProcedure 'Accelerator.SendHiggsBosonDiscoveryEmail'; | ||
|
||
--Act: Call the AlertParticleDiscovered procedure - this is the procedure being tested. | ||
EXEC Accelerator.AlertParticleDiscovered 'Proton'; | ||
|
||
--Assert: A spy records the parameters passed to the procedure in a *_SpyProcedureLog table. | ||
-- Copy the EmailAddress parameter values that the spy recorded into the #Actual temp table. | ||
SELECT EmailAddress | ||
INTO #Actual | ||
FROM Accelerator.SendHiggsBosonDiscoveryEmail_SpyProcedureLog; | ||
|
||
-- Create an empty #Expected temp table that has the same structure as the #Actual table | ||
SELECT TOP(0) * INTO #Expected FROM #Actual; | ||
|
||
-- The SendHiggsBosonDiscoveryEmail should not have been called. So the #Expected table is empty. | ||
|
||
-- Compare the data in the #Expected and #Actual tables | ||
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'; | ||
|
||
END; |
28 changes: 28 additions & 0 deletions
28
...ts/AcceleratorTests/Stored Procedures/test email is sent if we detected a higgs-boson.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test email is sent if we detected a higgs-boson] | ||
AS | ||
BEGIN | ||
--Assemble: Replace the SendHiggsBosonDiscoveryEmail with a spy. | ||
EXEC tSQLt.SpyProcedure 'Accelerator.SendHiggsBosonDiscoveryEmail'; | ||
|
||
--Act: Call the AlertParticleDiscovered procedure - this is the procedure being tested. | ||
EXEC Accelerator.AlertParticleDiscovered 'Higgs Boson'; | ||
|
||
--Assert: A spy records the parameters passed to the procedure in a *_SpyProcedureLog table. | ||
-- Copy the EmailAddress parameter values that the spy recorded into the #Actual temp table. | ||
SELECT EmailAddress | ||
INTO #Actual | ||
FROM Accelerator.SendHiggsBosonDiscoveryEmail_SpyProcedureLog; | ||
|
||
-- Create an empty #Expected temp table that has the same structure as the #Actual table | ||
SELECT TOP(0) * INTO #Expected FROM #Actual; | ||
|
||
-- Add a row to the #Expected table with the expected email address. | ||
INSERT INTO #Expected | ||
(EmailAddress) | ||
VALUES | ||
('[email protected]'); | ||
|
||
-- Compare the data in the #Expected and #Actual tables | ||
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'; | ||
END; |
23 changes: 23 additions & 0 deletions
23
...tored Procedures/test foreign key is not violated if Particle color is in Color table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
CREATE PROC AcceleratorTests.[test foreign key is not violated if Particle color is in Color table] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle and the Color tables to make sure they are empty and other | ||
-- constraints will not be a problem | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
EXEC tSQLt.FakeTable 'Accelerator.Color'; | ||
-- Put the FK_ParticleColor foreign key constraint back onto the Particle table | ||
-- so we can test it. | ||
EXEC tSQLt.ApplyConstraint 'Accelerator.Particle', 'FK_ParticleColor'; | ||
|
||
-- Insert a record into the Color table. We'll reference this Id again in the Act | ||
-- step. | ||
INSERT INTO Accelerator.Color (Id) VALUES (7); | ||
|
||
--Act: Attempt to insert a record into the Particle table. | ||
INSERT INTO Accelerator.Particle (ColorId) VALUES (7); | ||
|
||
--Assert: If any exception was thrown, the test will automatically fail. Therefore, the test | ||
-- passes as long as there was no exception. This is one of the VERY rare cases when | ||
-- at test case does not have an Assert step. | ||
END |
29 changes: 29 additions & 0 deletions
29
...s/Stored Procedures/test foreign key violated if Particle color is not in Color table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test foreign key violated if Particle color is not in Color table] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle and the Color tables to make sure they are empty and other | ||
-- constraints will not be a problem | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
EXEC tSQLt.FakeTable 'Accelerator.Color'; | ||
-- Put the FK_ParticleColor foreign key constraint back onto the Particle table | ||
-- so we can test it. | ||
EXEC tSQLt.ApplyConstraint 'Accelerator.Particle', 'FK_ParticleColor'; | ||
|
||
--Act: Attempt to insert a record into the Particle table without any records in Color table. | ||
-- We expect an exception to happen, so we capture the ERROR_MESSAGE() | ||
DECLARE @err NVARCHAR(MAX); SET @err = '<No Exception Thrown!>'; | ||
BEGIN TRY | ||
INSERT INTO Accelerator.Particle (ColorId) VALUES (7); | ||
END TRY | ||
BEGIN CATCH | ||
SET @err = ERROR_MESSAGE(); | ||
END CATCH | ||
|
||
--Assert: Check that trying to insert the record resulted in the FK_ParticleColor foreign key being violated. | ||
-- If no exception happened the value of @err is still '<No Exception Thrown>'. | ||
IF (@err NOT LIKE '%FK_ParticleColor%') | ||
BEGIN | ||
EXEC tSQLt.Fail 'Expected exception (FK_ParticleColor exception) not thrown. Instead:',@err; | ||
END; | ||
END; |
16 changes: 16 additions & 0 deletions
16
...cedures/test no particles are in a rectangle when there are no particles in the table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
CREATE PROCEDURE AcceleratorTests.[test no particles are in a rectangle when there are no particles in the table] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle table to make sure it is empty | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
|
||
DECLARE @ParticlesInRectangle INT; | ||
|
||
--Act: Call the GetParticlesInRectangle Table-Valued Function and capture the number of rows it returns. | ||
SELECT @ParticlesInRectangle = COUNT(1) | ||
FROM Accelerator.GetParticlesInRectangle(0.0, 0.0, 1.0, 1.0); | ||
|
||
--Assert: Check that 0 rows were returned | ||
EXEC tSQLt.AssertEquals 0, @ParticlesInRectangle; | ||
END; |
20 changes: 20 additions & 0 deletions
20
...ests/AcceleratorTests/Stored Procedures/test ready for experimentation if 2 particles.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
CREATE PROCEDURE | ||
AcceleratorTests.[test ready for experimentation if 2 particles] | ||
AS | ||
BEGIN | ||
--Assemble: Fake the Particle table to make sure | ||
-- it is empty and has no constraints | ||
EXEC tSQLt.FakeTable 'Accelerator.Particle'; | ||
INSERT INTO Accelerator.Particle (Id) VALUES (1); | ||
INSERT INTO Accelerator.Particle (Id) VALUES (2); | ||
|
||
DECLARE @Ready BIT; | ||
|
||
--Act: Call the IsExperimentReady function | ||
SELECT @Ready = Accelerator.IsExperimentReady(); | ||
|
||
--Assert: Check that 1 is returned from IsExperimentReady | ||
EXEC tSQLt.AssertEquals 1, @Ready; | ||
|
||
END; |
Oops, something went wrong.