Skip to content

Commit ed47139

Browse files
committed
Updates to tests.
1 parent 2f452d3 commit ed47139

5 files changed

Lines changed: 61 additions & 161 deletions

File tree

dotnetv4/DynamoDB/Scenarios/DynamoDB_Basics/DynamoDbBasics.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ namespace Basics;
2020
// Query
2121
// Scan
2222
// DeleteItemAsync
23-
2423
public class DynamoDbBasics
2524
{
25+
public static bool IsInteractive = true;
26+
2627
// Separator for the console display.
2728
private static readonly string SepBar = new string('-', 80);
28-
public static bool isInteractive = true;
29-
29+
3030
public static async Task Main(string[] args)
3131
{
3232
// Set up dependency injection for Amazon DynamoDB.
3333
using var host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
3434
.ConfigureServices((_, services) =>
3535
services.AddAWSService<IAmazonDynamoDB>()
36-
.AddTransient<DynamoDbWrapper>()
37-
)
36+
.AddTransient<DynamoDbWrapper>())
3837
.Build();
3938

4039
// Now the wrapper is available for injection.
@@ -183,6 +182,11 @@ public static async Task Main(string[] args)
183182
/// </summary>
184183
private static void DisplayInstructions()
185184
{
185+
if (!IsInteractive)
186+
{
187+
return;
188+
}
189+
186190
Console.Clear();
187191
Console.WriteLine();
188192
Console.Write(new string(' ', 28));
@@ -208,7 +212,7 @@ private static void DisplayInstructions()
208212
/// </summary>
209213
private static void WaitForEnter()
210214
{
211-
if (isInteractive)
215+
if (IsInteractive)
212216
{
213217
Console.WriteLine("\nPress <Enter> to continue.");
214218
Console.WriteLine(SepBar);

dotnetv4/DynamoDB/Tests/DynamoDBTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
14+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
1415
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
16+
<PackageReference Include="Moq" Version="4.20.72" />
1517
<PackageReference Include="xunit" Version="2.9.3" />
16-
<PackageReference Include="Xunit.Extensions.Ordering" Version="1.4.5" />
1718
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
1819
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1920
<PrivateAssets>all</PrivateAssets>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using Basics;
5+
using Microsoft.Extensions.Logging;
6+
using Moq;
7+
using Xunit;
8+
9+
namespace DynamoDBTests;
10+
11+
/// <summary>
12+
/// Integration tests for the Amazon DynamoDB Basics scenario.
13+
/// </summary>
14+
public class DynamoDbBasicsTest
15+
{
16+
/// <summary>
17+
/// Verifies the scenario with an integration test. No errors should be logged.
18+
/// </summary>
19+
/// <returns>Async task.</returns>
20+
[Fact]
21+
[Trait("Category", "Integration")]
22+
public async Task TestScenario()
23+
{
24+
// Arrange.
25+
DynamoDbBasics.IsInteractive = false;
26+
var loggerMock = new Mock<ILogger<DynamoDbBasics>>();
27+
28+
loggerMock.Setup(logger => logger.Log(
29+
It.Is<LogLevel>(logLevel => logLevel == LogLevel.Error),
30+
It.IsAny<EventId>(),
31+
It.Is<It.IsAnyType>((@object, @type) => true),
32+
It.IsAny<Exception>(),
33+
It.IsAny<Func<It.IsAnyType, Exception?, string>>()
34+
));
35+
36+
// Act.
37+
await DynamoDbBasics.Main(new string[] { "" });
38+
39+
// Assert no exceptions or errors logged.
40+
loggerMock.Verify(
41+
logger => logger.Log(
42+
It.Is<LogLevel>(logLevel => logLevel == LogLevel.Error),
43+
It.IsAny<EventId>(),
44+
It.Is<It.IsAnyType>((@object, @type) => true),
45+
It.IsAny<Exception>(),
46+
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
47+
Times.Never);
48+
}
49+
}

dotnetv4/DynamoDB/Tests/DynamoDbMethodsTests.cs

Lines changed: 0 additions & 141 deletions
This file was deleted.

dotnetv4/DynamoDB/Tests/GlobalUsings.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)