Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
PetaPoco
提交
ba752fb4
P
PetaPoco
项目概览
jobily
/
PetaPoco
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PetaPoco
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ba752fb4
编写于
4月 17, 2019
作者:
W
Wade Baglin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add save documentation
上级
0aaa8855
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
119 addition
and
33 deletion
+119
-33
PetaPoco.Tests.Integration/Documentation/Delete.cs
PetaPoco.Tests.Integration/Documentation/Delete.cs
+26
-27
PetaPoco.Tests.Integration/Documentation/Pocos/Note.cs
PetaPoco.Tests.Integration/Documentation/Pocos/Note.cs
+15
-0
PetaPoco.Tests.Integration/Documentation/Save.cs
PetaPoco.Tests.Integration/Documentation/Save.cs
+68
-0
PetaPoco.Tests.Integration/PetaPoco.Tests.Integration.csproj
PetaPoco.Tests.Integration/PetaPoco.Tests.Integration.csproj
+4
-0
PetaPoco.Tests.Integration/Scripts/MSSQLBuildDatabase.sql
PetaPoco.Tests.Integration/Scripts/MSSQLBuildDatabase.sql
+6
-6
未找到文件。
PetaPoco.Tests.Integration/Documentation/Delete.cs
浏览文件 @
ba752fb4
using
System
;
using
System.Linq
;
using
PetaPoco.Core
;
using
PetaPoco.Tests.Integration.Databases
;
using
PetaPoco.Tests.Integration.Databases.MSSQL
;
...
...
@@ -26,17 +25,17 @@ namespace PetaPoco.Tests.Integration.Documentation
// Tell PetaPoco to insert it
DB
.
Insert
(
person
);
// Obviously, we find only 1 matching person in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [People] WHERE [Id] = @Id"
,
new
{
person
.
Id
});
count
.
ShouldBe
(
1
);
// Tell PetaPoco to delete it
DB
.
Delete
(
person
);
// Obviously, we should now have none in the db
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [People] WHERE [Id] = @0"
,
person
.
Id
);
count
.
ShouldBe
(
0
);
count
.
ShouldBe
(
0
);
}
[
Fact
]
...
...
@@ -44,78 +43,78 @@ namespace PetaPoco.Tests.Integration.Documentation
{
// Clear out any notes and reset the ID sequence counter
DB
.
Execute
(
"TRUNCATE TABLE [Note]"
);
// Add a note
var
note
=
new
Note
{
Text
=
"This is my note"
,
CreatedOn
=
DateTime
.
UtcNow
};
DB
.
Insert
(
note
);
// As note.id is auto increment, we should have an id of 1
note
.
Id
.
ShouldBe
(
1
);
// Obviously, we should find only one matching note in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @Id"
,
new
{
note
.
Id
});
count
.
ShouldBe
(
1
);
// Now, tell PetaPoco to delete a note with the id of 1
DB
.
Delete
<
Note
>(
note
.
Id
);
// Obviously, we should now have none in the db
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @0"
,
note
.
Id
);
count
.
ShouldBe
(
0
);
}
[
Fact
]
public
void
DeleteCustomWhere
()
{
// Clear out any notes and reset the ID sequence counter
DB
.
Execute
(
"TRUNCATE TABLE [Note]"
);
// Add a note
var
note
=
new
Note
{
Text
=
"This is my note"
,
CreatedOn
=
DateTime
.
UtcNow
};
DB
.
Insert
(
note
);
// As note.id is auto increment, we should have an id of 1
note
.
Id
.
ShouldBe
(
1
);
// Obviously, we should find only one matching note in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @Id"
,
new
{
note
.
Id
});
count
.
ShouldBe
(
1
);
// Now, we'll tell PetaPoco how to delete the note
DB
.
Delete
<
Note
>(
"WHERE [Id] = @Id"
,
new
{
note
.
Id
});
// Obviously, we should now have none in the db
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @0"
,
note
.
Id
);
count
.
ShouldBe
(
0
);
}
[
Fact
]
public
void
DeleteCustomSqlWhere
()
{
// Clear out any notes and reset the ID sequence counter
DB
.
Execute
(
"TRUNCATE TABLE [Note]"
);
// Add a note
var
note
=
new
Note
{
Text
=
"This is my note"
,
CreatedOn
=
DateTime
.
UtcNow
};
DB
.
Insert
(
note
);
// As note.id is auto increment, we should have an id of 1
note
.
Id
.
ShouldBe
(
1
);
// Obviously, we should find only one matching note in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @Id"
,
new
{
note
.
Id
});
count
.
ShouldBe
(
1
);
// Now, we'll tell PetaPoco how to delete the note
var
sql
=
new
Sql
();
sql
.
Where
(
"[Id] = @Id"
,
new
{
note
.
Id
});
DB
.
Delete
<
Note
>(
sql
);
// Obviously, we should now have none in the db
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @0"
,
note
.
Id
);
count
.
ShouldBe
(
0
);
}
[
Fact
]
public
void
DeleteAdvanced
()
{
...
...
@@ -124,17 +123,17 @@ namespace PetaPoco.Tests.Integration.Documentation
// Tell PetaPoco to insert it, but to the table SpecificPeople and not People
DB
.
Insert
(
"SpecificPeople"
,
person
);
// Obviously, we find only 1 matching person in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [SpecificPeople] WHERE [Id] = @Id"
,
new
{
person
.
Id
});
count
.
ShouldBe
(
1
);
// Tell PetaPoco to delete it, but in the table SpecificPeople and not People
DB
.
Delete
(
"SpecificPeople"
,
"Id"
,
person
);
// Obviously, we should now have none in the db
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [SpecificPeople] WHERE [Id] = @0"
,
person
.
Id
);
count
.
ShouldBe
(
0
);
count
.
ShouldBe
(
0
);
}
}
}
\ No newline at end of file
PetaPoco.Tests.Integration/Documentation/Pocos/Note.cs
浏览文件 @
ba752fb4
using
System
;
using
System.Data
;
using
System.Data.SqlClient
;
namespace
PetaPoco.Tests.Integration.Documentation.Pocos
{
...
...
@@ -6,8 +8,21 @@ namespace PetaPoco.Tests.Integration.Documentation.Pocos
{
public
int
Id
{
get
;
set
;
}
[
DateTime2ConverterAttribute
]
public
DateTime
CreatedOn
{
get
;
set
;
}
public
string
Text
{
get
;
set
;
}
}
public
class
DateTime2ConverterAttribute
:
ValueConverterAttribute
{
public
override
object
ConvertToDb
(
object
value
)
=>
new
SqlParameter
{
DbType
=
DbType
.
DateTime2
,
Value
=
value
};
public
override
object
ConvertFromDb
(
object
value
)
=>
value
;
}
}
\ No newline at end of file
PetaPoco.Tests.Integration/Documentation/Save.cs
0 → 100644
浏览文件 @
ba752fb4
using
System
;
using
PetaPoco.Core
;
using
PetaPoco.Tests.Integration.Databases
;
using
PetaPoco.Tests.Integration.Databases.MSSQL
;
using
PetaPoco.Tests.Integration.Documentation.Pocos
;
using
Shouldly
;
using
Xunit
;
namespace
PetaPoco.Tests.Integration.Documentation
{
[
Collection
(
"MssqlTests"
)]
public
class
Save
:
BaseDatabase
{
public
Save
()
:
base
(
new
MssqlDBTestProvider
())
{
PocoData
.
FlushCaches
();
}
[
Fact
]
public
void
Save_Insert
()
{
// Clear out any notes and reset the ID sequence counter
DB
.
Execute
(
"TRUNCATE TABLE [Note]"
);
// Add a note
var
note
=
new
Note
{
Text
=
"This is my note"
,
CreatedOn
=
DateTime
.
UtcNow
};
DB
.
Save
(
note
);
// As note.id is auto increment, we should have an id of 1
note
.
Id
.
ShouldBe
(
1
);
// Obviously, we should find only one matching note in the db
var
count
=
DB
.
ExecuteScalar
<
int
>(
"SELECT COUNT([Id]) FROM [Note] WHERE [Id] = @Id"
,
new
{
note
.
Id
});
count
.
ShouldBe
(
1
);
// Fetch a new copy of note
var
noteFromDb
=
DB
.
Single
<
Note
>(
note
.
Id
);
// They are the same
note
.
Id
.
ShouldBe
(
noteFromDb
.
Id
);
note
.
Text
.
ShouldBe
(
noteFromDb
.
Text
);
note
.
CreatedOn
.
Ticks
.
ShouldBe
(
noteFromDb
.
CreatedOn
.
Ticks
);
}
[
Fact
]
public
void
Save_Update
()
{
// Clear out any notes and reset the ID sequence counter
DB
.
Execute
(
"TRUNCATE TABLE [Note]"
);
// Add a note
var
note
=
new
Note
{
Text
=
"This is my note"
,
CreatedOn
=
DateTime
.
UtcNow
};
DB
.
Save
(
note
);
// Update the note
note
.
Text
+=
" and this is my update"
;
DB
.
Save
(
note
);
// Fetch a new copy of note
var
noteFromDb
=
DB
.
Single
<
Note
>(
note
.
Id
);
// The note text is the same
note
.
Text
.
ShouldBe
(
noteFromDb
.
Text
);
note
.
Text
.
ShouldContain
(
" and this is my update"
);
}
}
}
\ No newline at end of file
PetaPoco.Tests.Integration/PetaPoco.Tests.Integration.csproj
浏览文件 @
ba752fb4
...
...
@@ -9,6 +9,10 @@
<Copyright>Collaborating Platypus</Copyright>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<Compile Remove="Databases\MSAccess\**" />
...
...
PetaPoco.Tests.Integration/Scripts/MSSQLBuildDatabase.sql
浏览文件 @
ba752fb4
...
...
@@ -20,7 +20,7 @@ CREATE TABLE dbo.[People] (
[
FullName
]
NVARCHAR
(
255
),
[
Age
]
BIGINT
NOT
NULL
,
[
Height
]
INT
NOT
NULL
,
[
Dob
]
DATETIME
NULL
[
Dob
]
DATETIME
2
NULL
)
CREATE
TABLE
dbo
.[
Orders
]
(
...
...
@@ -28,7 +28,7 @@ CREATE TABLE dbo.[Orders] (
[
PersonId
]
UNIQUEIDENTIFIER
FOREIGN
KEY
REFERENCES
dbo
.[
People
](
Id
),
[
PoNumber
]
NVARCHAR
(
15
)
NOT
NULL
,
[
OrderStatus
]
INT
NOT
NULL
,
[
CreatedOn
]
DATETIME
NOT
NULL
,
[
CreatedOn
]
DATETIME
2
NOT
NULL
,
[
CreatedBy
]
NVARCHAR
(
255
)
NOT
NULL
)
...
...
@@ -45,7 +45,7 @@ CREATE TABLE dbo.[SpecificPeople] (
[
FullName
]
NVARCHAR
(
255
),
[
Age
]
BIGINT
NOT
NULL
,
[
Height
]
INT
NOT
NULL
,
[
Dob
]
DATETIME
NULL
[
Dob
]
DATETIME
2
NULL
)
CREATE
TABLE
dbo
.[
SpecificOrders
]
(
...
...
@@ -53,7 +53,7 @@ CREATE TABLE dbo.[SpecificOrders] (
[
PersonId
]
UNIQUEIDENTIFIER
FOREIGN
KEY
REFERENCES
dbo
.[
SpecificPeople
](
Id
),
[
PoNumber
]
NVARCHAR
(
15
)
NOT
NULL
,
[
OrderStatus
]
INT
NOT
NULL
,
[
CreatedOn
]
DATETIME
NOT
NULL
,
[
CreatedOn
]
DATETIME
2
NOT
NULL
,
[
CreatedBy
]
NVARCHAR
(
255
)
NOT
NULL
)
...
...
@@ -67,13 +67,13 @@ CREATE TABLE dbo.[SpecificOrderLines] (
CREATE
TABLE
dbo
.[
TransactionLogs
]
(
[
Description
]
NTEXT
,
[
CreatedOn
]
DATETIME
NOT
NULL
[
CreatedOn
]
DATETIME
2
NOT
NULL
)
CREATE
TABLE
dbo
.[
Note
]
(
[
Id
]
INT
IDENTITY
(
1
,
1
)
PRIMARY
KEY
,
[
Text
]
NTEXT
NOT
NULL
,
[
CreatedOn
]
DATETIME
NOT
NULL
[
CreatedOn
]
DATETIME
2
NOT
NULL
)
IF
NOT
EXISTS
(
SELECT
*
FROM
sys
.
schemas
WHERE
name
=
'store'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录