forked from answerdigital/AnswerKing-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update JSON deserialisation and fake DB tests
- Loading branch information
1 parent
6eb57e1
commit 86a69a1
Showing
13 changed files
with
288 additions
and
167 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
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,96 @@ | ||
namespace Answer.King.IntegrationTests.Tests; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using FluentAssertions.Extensions; | ||
using Npgsql; | ||
|
||
//The tests in here are mocked data to practice how I could do DB testing and assertions with a working SQL DB | ||
|
||
[TestFixture] | ||
public class BeeKeeperDBTests | ||
{ | ||
[Test] | ||
public async Task OrderAssertionsProductId() | ||
{ | ||
|
||
var connectionString = "Server=localhost;Port=5432;User Id=postgres;Password=penguin;Database=postgres;"; | ||
await using var dataSource = NpgsqlDataSource.Create(connectionString); | ||
await using var command = dataSource.CreateCommand("SELECT product_id from public.orders WHERE order_id = 4"); | ||
await using var reader = await command.ExecuteReaderAsync(); | ||
|
||
List<Int32> resultList = new List<Int32>(); | ||
|
||
while (await reader.ReadAsync()) | ||
{ | ||
var result = reader.GetInt32(0); | ||
resultList.Add(result); | ||
} | ||
|
||
string resultString = string.Join(", ", resultList); | ||
|
||
//Assertions that can be done on a int list | ||
resultList.Count().Should().Be(3); | ||
|
||
//Assertions that can't be done on a list | ||
resultString.Should().ContainAll("1", "2", "5"); | ||
Console.WriteLine(resultString); | ||
} | ||
|
||
[Test] | ||
public async Task OrderAssertionsProductName() | ||
{ | ||
|
||
var connectionString = "Server=localhost;Port=5432;User Id=postgres;Password=penguin;Database=postgres;"; | ||
await using var dataSource = NpgsqlDataSource.Create(connectionString); | ||
await using var command = dataSource.CreateCommand("SELECT pro_name from public.orders WHERE order_id = 4"); | ||
await using var reader = await command.ExecuteReaderAsync(); | ||
|
||
List<string> resultList = new List<string>(); | ||
|
||
while (await reader.ReadAsync()) | ||
{ | ||
var result = reader.GetString(0); | ||
resultList.Add(result); | ||
} | ||
|
||
string resultString = string.Join(", ", resultList); | ||
|
||
//Assertions that can be done on a list | ||
resultList.Should().Contain("Fish", "Chips", "Cheese Burger"); | ||
resultList.Should().NotContain("Gravy"); | ||
|
||
//Assertions that can't be done on a list | ||
Console.WriteLine(resultString); | ||
} | ||
|
||
[Test] | ||
public async Task OrderAssertionsProductQuantity() | ||
{ | ||
|
||
var connectionString = "Server=localhost;Port=5432;User Id=postgres;Password=penguin;Database=postgres;"; | ||
await using var dataSource = NpgsqlDataSource.Create(connectionString); | ||
await using var command = dataSource.CreateCommand("SELECT quantity from public.orders WHERE order_id = 4"); | ||
await using var reader = await command.ExecuteReaderAsync(); | ||
|
||
List<int> resultList = new List<int>(); | ||
|
||
while (await reader.ReadAsync()) | ||
{ | ||
var result = reader.GetInt32(0); | ||
resultList.Add(result); | ||
result.Should().Be(1); | ||
} | ||
|
||
string resultString = string.Join(", ", resultList); | ||
|
||
//Assertions that can be done on a list | ||
resultList.Count().Should().Be(3); | ||
|
||
//Assertions that can't be done on a list | ||
resultString.Should().Contain("1", Exactly.Thrice()); | ||
Console.WriteLine(resultString); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
...Tests/__snapshots__/AnswerKingPostOrder.ProductOrder_Success_Multiple_Products_Order.snap
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...__snapshots__/AnswerKingPostOrder.ProductOrder_Success_Multiple_Products_Order_18.97.snap
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 @@ | ||
{ | ||
"id": 4, | ||
"createdOn": "2023-12-13T14:41:20.0664133Z", | ||
"lastUpdated": "2023-12-13T14:41:20.0665808Z", | ||
"orderStatus": "Created", | ||
"orderTotal": 18.97, | ||
"lineItems": [ | ||
{ | ||
"product": { | ||
"id": 1, | ||
"name": "Fish", | ||
"description": "Delicious and satisfying.", | ||
"price": 5.99 | ||
}, | ||
"quantity": 1, | ||
"subTotal": 5.99 | ||
}, | ||
{ | ||
"product": { | ||
"id": 2, | ||
"name": "Chips", | ||
"description": "Nothing more to say.", | ||
"price": 2.99 | ||
}, | ||
"quantity": 1, | ||
"subTotal": 2.99 | ||
}, | ||
{ | ||
"product": { | ||
"id": 5, | ||
"name": "Cheese Burger", | ||
"description": "Plain burger with cheese", | ||
"price": 9.99 | ||
}, | ||
"quantity": 1, | ||
"subTotal": 9.99 | ||
} | ||
] | ||
} |
19 changes: 0 additions & 19 deletions
19
.../AnswerKingPostOrder.ProductOrder_Success_Multiple_Same_Product_Multiple_Lines_Order.snap
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...erKingPostOrder.ProductOrder_Success_Multiple_Same_Product_Multiple_Lines_Order_8.97.snap
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,19 @@ | ||
{ | ||
"id": 4, | ||
"createdOn": "2023-12-13T14:41:20.1602293Z", | ||
"lastUpdated": "2023-12-13T14:41:20.1602512Z", | ||
"orderStatus": "Created", | ||
"orderTotal": 8.97, | ||
"lineItems": [ | ||
{ | ||
"product": { | ||
"id": 2, | ||
"name": "Chips", | ||
"description": "Nothing more to say.", | ||
"price": 2.99 | ||
}, | ||
"quantity": 3, | ||
"subTotal": 8.97 | ||
} | ||
] | ||
} |
19 changes: 0 additions & 19 deletions
19
...ots__/AnswerKingPostOrder.ProductOrder_Success_Multiple_Same_Product_Same_Line_Order.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.