Skip to content

Commit

Permalink
Unit Tests for stored procedures fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sheryever committed Aug 15, 2022
1 parent 229e339 commit e249fe0
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 130 deletions.
220 changes: 113 additions & 107 deletions Source/SimpleAccess.SqlServer.Test/DbScript.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1196,33 +1196,63 @@ GO
SET QUOTED_IDENTIFIER ON
GO





-------------------------
--- Start of People_Delete
--- Start of People_GetAll
-------------------------
CREATE PROCEDURE [dbo].[People_Delete]
@id INT
CREATE PROCEDURE People_GetAll
AS
BEGIN
SELECT [Id]
, [FullName]
, [Gender]
, [DOB]
, [Phone]
, [Address]
, [BasicSalary]
, [Transport]
, [Alive]

FROM dbo.[People]
END
-------------------------
--END of People_GetAll
-------------------------

DELETE FROM dbo.[People]
WHERE
[Id] = @Id
Go

-------------------------
--- Start of People_GetById
-------------------------
CREATE PROCEDURE People_GetById
@id INT
AS
BEGIN
SELECT [Id]
, [FullName]
, [Gender]
, [DOB]
, [Phone]
, [Address]
, [BasicSalary]
, [Transport]
, [Alive]
FROM dbo.People
WHERE [Id] = @Id
END
-------------------------
--END of People_Delete
--END of People_GetById
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_Find] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
GO

-------------------------
--- Start of People_Find
-------------------------
CREATE PROCEDURE [dbo].[People_Find]
CREATE PROCEDURE People_Find
@whereClause NVARCHAR(4000)
WITH EXEC AS CALLER
AS
Expand All @@ -1231,7 +1261,13 @@ BEGIN
SET @sql =
'SELECT ' + ' [Id] ' +
' , [FullName] ' +
' , [Gender] ' +
' , [DOB] ' +
' , [Phone] ' +
' , [Address] ' +
' , [BasicSalary] ' +
' , [Transport] ' +
' , [Alive] ' +
'FROM dbo.People ' +
ISNULL(@whereClause, '');

Expand All @@ -1256,67 +1292,12 @@ END
--END of People_Find
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_GetAll] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-------------------------
--- Start of People_GetAll
-------------------------
CREATE PROCEDURE [dbo].[People_GetAll]
AS
BEGIN
SELECT [Id]
, [FullName]
, [Phone]

FROM dbo.[People]
END
-------------------------
--END of People_GetAll
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_GetById] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-------------------------
--- Start of People_GetById
-------------------------
CREATE PROCEDURE [dbo].[People_GetById]
@id INT
AS
BEGIN
SELECT [Id]
, [FullName]
, [Phone]
FROM dbo.People
WHERE [Id] = @Id
END
-------------------------
--END of People_GetById
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_GetPagedList] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Go

-------------------------
--- Start of People_GetPagedList
-------------------------
CREATE PROCEDURE [dbo].[People_GetPagedList]
CREATE PROCEDURE People_GetPagedList
@startIndex INT
, @pageSize INT
, @sortExpression VARCHAR(255)
Expand All @@ -1336,7 +1317,13 @@ BEGIN
SET @sql =
'SELECT ' + ' [Id] ' +
' , [FullName] ' +
' , [Gender] ' +
' , [DOB] ' +
' , [Phone] ' +
' , [Address] ' +
' , [BasicSalary] ' +
' , [Transport] ' +
' , [Alive] ' +
' FROM ( ' +
' SELECT * ' +
' , ROW_NUMBER() OVER ( ORDER BY ' + @sortExpression + ' ) AS [RowNumber] ' +
Expand Down Expand Up @@ -1370,24 +1357,39 @@ END
--END of People_GetPagedList
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_Insert] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Go

-------------------------
--- Start of People_Delete
-------------------------
CREATE PROCEDURE People_Delete
@id INT
AS
BEGIN

DELETE FROM dbo.[People]
WHERE
[Id] = @Id
END
-------------------------
--END of People_Delete
-------------------------


GO
-------------------------
--- Start of People_Insert
-------------------------
CREATE PROCEDURE [dbo].[People_Insert]
@fullName NVARCHAR(200)
, @gender smallint
CREATE PROCEDURE People_Insert

@fullName NVARCHAR(200)
, @gender SMALLINT
, @dOB SMALLDATETIME
, @phone NVARCHAR(40)
, @address nvarchar(600)
, @basicSalary decimal(10, 2)
, @transport int
, @alive bit
, @address NVARCHAR(600)
, @basicSalary DECIMAL
, @transport INT
, @alive BIT
,@Id INT OUTPUT

AS
Expand All @@ -1401,17 +1403,19 @@ BEGIN
(
[Id]
, [FullName]
, Gender
, [Gender]
, [DOB]
, [Phone]
, Address
, BasicSalary
, Transport
, Alive
, [Address]
, [BasicSalary]
, [Transport]
, [Alive]

) VALUES (
@id
, @fullName
, @gender
, @dOB
, @phone
, @address
, @basicSalary
Expand All @@ -1426,26 +1430,22 @@ END
--END of People_Insert
-------------------------

GO
/****** Object: StoredProcedure [dbo].[People_Update] Script Date: 8/13/2022 8:49:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Go

-------------------------
--- Start of People_Update
-------------------------

CREATE PROCEDURE [dbo].[People_Update]
CREATE PROCEDURE People_Update
@id INT
, @fullName NVARCHAR(200)
, @gender smallint
, @gender SMALLINT
, @dOB SMALLDATETIME
, @phone NVARCHAR(40)
, @address nvarchar(600)
, @basicSalary decimal(10, 2)
, @transport int
, @alive bit
, @address NVARCHAR(600)
, @basicSalary DECIMAL
, @transport INT
, @alive BIT

AS
BEGIN
Expand All @@ -1454,13 +1454,13 @@ CREATE PROCEDURE [dbo].[People_Update]

UPDATE dbo.[People] SET
[FullName] = @fullName
, Gender = @gender
, [Gender] = @gender
, [DOB] = @dOB
, [Phone] = @phone
, Address = @address
, BasicSalary = @basicSalary
, Transport = @transport
, Alive = @alive

, [Address] = @address
, [BasicSalary] = @basicSalary
, [Transport] = @transport
, [Alive] = @alive
WHERE [Id] = @id


Expand All @@ -1469,5 +1469,11 @@ END
--END of People_Update
-------------------------

GO





ALTER DATABASE [SimpleAccessTest] SET READ_WRITE
GO
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="DbScript.sql" />
</ItemGroup>

<ItemGroup>
<Compile Include="DbScript.sql" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
16 changes: 11 additions & 5 deletions Source/SimpleAccess.SqlServer.Test/SqlSpRepositoryAsyncTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SimpleAccess.SqlServer;
using SimpleAccess.SqlServer.TestNetCore2.Entities;
using Xunit;
using System;

namespace SimpleAccess.SqlServer.Test
{
Expand All @@ -33,7 +34,8 @@ public void InsertAsyncTest()
var person = new Person
{
FullName = "Muhammad Abdul Rehman Khan",
Phone = "1112182123"
Phone = "1112182123",
DOB = DateTime.Now.AddYears(-20)
};
var rowAffected = SqlRepository.InsertAsync<Person>(person).Result;
//var rowAffected = SqlRepository.Insert<Person>(person);
Expand All @@ -50,22 +52,26 @@ public void InsertAllAsyncWithTransactionContextTest()
new Person
{
FullName = "Muhammad Abdul Rehman Khan",
Phone = "1112182123"
Phone = "1112182123",
DOB = DateTime.Now.AddYears(-20)
},
new Person
{
FullName = "Muhammad Sharjeel",
Phone = "0599065644"
Phone = "0599065644",
DOB = DateTime.Now.AddYears(-20)
},
new Person
{
FullName = "Muhammad Affan",
Phone = "1112182123"
Phone = "1112182123",
DOB = DateTime.Now.AddYears(-20)
},
new Person
{
FullName = "Muhammad Usman",
Phone = "1112182123"
Phone = "1112182123",
DOB = DateTime.Now.AddYears(-20)
},
};
var rowAffected = SqlRepository.InsertAllAsync<Person>(transContext, people).Result;
Expand Down
Loading

0 comments on commit e249fe0

Please sign in to comment.