-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for SendNotificationTask and ResolveIncidentTask functions.
Fixed bugs and refactored DDB persistance to IncidentRepository
- Loading branch information
Showing
18 changed files
with
333 additions
and
163 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
13 changes: 4 additions & 9 deletions
13
AWSStepFunctionsPlagiarismDemo/AdminActionTask/AdminActionTask.csproj
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 |
---|---|---|
@@ -1,26 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" /> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.10.3" /> | ||
<PackageReference Include="AWSXRayRecorder.Core" Version="2.2.1-beta" /> | ||
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.2.1-beta" /> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14" /> | ||
<PackageReference Include="AWSXRayRecorder.Core" Version="2.3.0-beta" /> | ||
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.3.0-beta" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\IncidentPersistence\IncidentPersistence.csproj" /> | ||
<ProjectReference Include="..\IncidentState\IncidentState.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
</Project> |
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
39 changes: 0 additions & 39 deletions
39
AWSStepFunctionsPlagiarismDemo/IncidentPersistence/IncidentDocument.cs
This file was deleted.
Oops, something went wrong.
10 changes: 3 additions & 7 deletions
10
AWSStepFunctionsPlagiarismDemo/IncidentPersistence/IncidentPersistence.csproj
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.10.3" /> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\IncidentState\IncidentState.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
</Project> |
87 changes: 87 additions & 0 deletions
87
AWSStepFunctionsPlagiarismDemo/IncidentPersistence/IncidentRepository.cs
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,87 @@ | ||
using System; | ||
using Amazon.DynamoDBv2; | ||
using Amazon.DynamoDBv2.DocumentModel; | ||
using Amazon.Runtime; | ||
using IncidentState; | ||
|
||
namespace IncidentPersistence | ||
{ | ||
|
||
public interface IIncidentRepository | ||
{ | ||
void SaveIncident(State state); | ||
} | ||
|
||
public class IncidentRepository : IIncidentRepository | ||
{ | ||
private readonly IAmazonDynamoDB _dynamoDb; | ||
private readonly string _tableName; | ||
|
||
public IncidentRepository(string tableName) | ||
{ | ||
_dynamoDb = new AmazonDynamoDBClient(); | ||
_tableName = tableName; | ||
} | ||
|
||
public void SaveIncident(State state) | ||
{ | ||
var incidentDocument = new IncidentDocument().CreateDocumentFromState(state); | ||
|
||
try | ||
{ | ||
Console.WriteLine("Saving incident:{0} to {1}", state.IncidentId.ToString("N"), _tableName); | ||
var table = Table.LoadTable(_dynamoDb, _tableName); | ||
table.PutItemAsync(incidentDocument); | ||
} | ||
catch (AmazonDynamoDBException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
throw; | ||
} | ||
catch (AmazonServiceException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
throw; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
throw; | ||
} | ||
} | ||
} | ||
|
||
internal class IncidentDocument | ||
{ | ||
internal Document CreateDocumentFromState(State state) | ||
{ | ||
var examsList = new DynamoDBList(); | ||
|
||
foreach (var exam in state.Exams) | ||
{ | ||
var examMap = new Document | ||
{ | ||
{"ExamId", exam.ExamId}, | ||
{"ExamDate", exam.ExamDate}, | ||
{"Score", exam.Score} | ||
}; | ||
|
||
examsList.Add(examMap); | ||
} | ||
|
||
var incidentDocument = new Document | ||
{ | ||
["IncidentId"] = state.IncidentId, | ||
["StudentId"] = state.StudentId, | ||
["IncidentDate"] = state.IncidentDate, | ||
["AdminActionRequired"] = new DynamoDBBool(state.AdminActionRequired), | ||
["IncidentResolved"] = new DynamoDBBool(state.IncidentResolved), | ||
["ResolutionDate"] = state.ResolutionDate, | ||
["Exams"] = examsList | ||
}; | ||
|
||
return incidentDocument; | ||
} | ||
|
||
} | ||
} |
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
11 changes: 3 additions & 8 deletions
11
AWSStepFunctionsPlagiarismDemo/RegisterIncidentTask/RegisterIncidentTask.csproj
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 |
---|---|---|
@@ -1,24 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" /> | ||
<PackageReference Include="AWSXRayRecorder.Core" Version="2.2.1-beta" /> | ||
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.2.1-beta" /> | ||
<PackageReference Include="AWSXRayRecorder.Core" Version="2.3.0-beta" /> | ||
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.3.0-beta" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\IncidentState\IncidentState.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
</Project> |
47 changes: 47 additions & 0 deletions
47
AWSStepFunctionsPlagiarismDemo/ResolveIncidentTask.Tests/FunctionTests.cs
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,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
using Amazon.Lambda.TestUtilities; | ||
using IncidentPersistence; | ||
using IncidentState; | ||
using NSubstitute; | ||
|
||
namespace ResolveIncidentTask.Tests | ||
{ | ||
public class FunctionTests | ||
{ | ||
public FunctionTests() | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void ResolveIncidentFunctionTest() | ||
{ | ||
var incidentRepository | ||
= Substitute.For<IIncidentRepository>(); | ||
|
||
|
||
var function = new Function(incidentRepository); | ||
var context = new TestLambdaContext(); | ||
|
||
var state = new State | ||
{ | ||
IncidentId = Guid.NewGuid(), | ||
StudentId = "123", | ||
IncidentDate = new DateTime(2018, 02, 03), | ||
Exams = new List<Exam>() | ||
{ | ||
new Exam(Guid.NewGuid(), new DateTime(2018, 02, 10), 10), | ||
new Exam(Guid.NewGuid(), new DateTime(2018, 02, 17), 65) | ||
}, | ||
ResolutionDate = null | ||
}; | ||
|
||
|
||
incidentRepository.SaveIncident(state); | ||
incidentRepository.ReceivedCalls(); | ||
|
||
function.FunctionHandler(state, context); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
AWSStepFunctionsPlagiarismDemo/ResolveIncidentTask.Tests/ResolveIncidentTask.Tests.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" /> | ||
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="1.0.0" /> | ||
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="1.1.3" /> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | ||
<PackageReference Include="NSubstitute" Version="3.1.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ResolveIncidentTask\ResolveIncidentTask.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.