forked from MoonStorm/FastCrud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleCrudSteps.cs
80 lines (68 loc) · 3.35 KB
/
SimpleCrudSteps.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
namespace Dapper.FastCrud.Benchmarks
{
using System.Linq;
using Dapper.FastCrud.Tests;
using Dapper.FastCrud.Tests.Models;
using NUnit.Framework;
using TechTalk.SpecFlow;
using SimpleCrud = global::Dapper.SimpleCRUD;
[Binding]
public class SimpleCrudSteps:EntityGenerationSteps
{
private DatabaseTestContext _testContext;
public SimpleCrudSteps(DatabaseTestContext testContext)
{
_testContext = testContext;
}
[When(@"I insert (.*) benchmark entities using Simple Crud")]
public void WhenIInsertSingleIntKeyEntitiesUsingSimpleCrud(int entitiesCount)
{
var dbConnection = _testContext.DatabaseConnection;
for (var entityIndex = 1; entityIndex <= entitiesCount; entityIndex++)
{
var generatedEntity = this.GenerateSimpleBenchmarkEntity(entityIndex);
generatedEntity.Id = SimpleCrud.Insert(dbConnection, generatedEntity).Value;
Assert.Greater(generatedEntity.Id, 1); // the seed starts from 2 in the db to avoid confusion with the number of rows modified
_testContext.LocalInsertedEntities.Add(generatedEntity);
}
}
[When(@"I select all the benchmark entities using Simple Crud")]
public void WhenISelectAllTheSingleIntKeyEntitiesUsingSimpleCrud()
{
var dbConnection = _testContext.DatabaseConnection;
_testContext.QueriedEntities.AddRange(SimpleCrud.GetList<SimpleBenchmarkEntity>(dbConnection));
}
[When(@"I select all the benchmark entities that I previously inserted using Simple Crud")]
public void WhenISelectAllTheSingleIntKeyEntitiesThatIPreviouslyInsertedUsingSimpleCrud()
{
var dbConnection = _testContext.DatabaseConnection;
foreach (var entity in _testContext.LocalInsertedEntities.OfType<SimpleBenchmarkEntity>())
{
_testContext.QueriedEntities.Add(SimpleCrud.Get<SimpleBenchmarkEntity>(dbConnection, entity.Id));
}
}
[When(@"I update all the benchmark entities that I previously inserted using Simple Crud")]
public void WhenIUpdateAllTheSingleIntKeyEntitiesThatIPreviouslyInsertedUsingSimpleCrud()
{
var dbConnection = _testContext.DatabaseConnection;
var entityCount = _testContext.LocalInsertedEntities.Count;
for (var entityIndex = 0; entityIndex < _testContext.LocalInsertedEntities.Count; entityIndex++)
{
var oldEntity = _testContext.LocalInsertedEntities[entityIndex] as SimpleBenchmarkEntity;
var newEntity = this.GenerateSimpleBenchmarkEntity(entityCount++);
newEntity.Id = oldEntity.Id;
SimpleCrud.Update(dbConnection, newEntity);
_testContext.LocalInsertedEntities[entityIndex] = newEntity;
}
}
[When(@"I delete all the inserted benchmark entities using Simple Crud")]
public void WhenIDeleteAllTheInsertedSingleIntKeyEntitiesUsingSimpleCrud()
{
var dbConnection = _testContext.DatabaseConnection;
foreach (var entity in _testContext.LocalInsertedEntities.OfType<SimpleBenchmarkEntity>())
{
SimpleCrud.Delete(dbConnection, entity);
}
}
}
}