Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTTL 1117 #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: 2.1

orbs:
nuget-cache: guitarrapc/[email protected]
aws-ecr: circleci/[email protected]

executors:
docker-dotnet:
docker:
- image: mcr.microsoft.com/dotnet/core/sdk:3.1
docker-python:
docker:
- image: circleci/python:3.7

references:
workspace_root: &workspace_root "~"
attach_workspace: &attach_workspace
attach_workspace:
at: *workspace_root

jobs:
check-code-formatting:
executor: docker-dotnet
steps:
- checkout
- run:
name: Install dotnet format
command: dotnet tool install dotnet-format --tool-path ./dotnet-format-local/
- run:
name: Run formatter check
command: ./dotnet-format-local/dotnet-format --check
build-and-test:
executor: docker-python
steps:
- checkout
- setup_remote_docker
- run:
name: build
command: docker-compose build hackney-shared-contact-details-test
- run:
name: Run tests
command: docker-compose run hackney-shared-contact-details-test
publish-package:
executor: docker-dotnet
steps:
- checkout
- *attach_workspace
- run:
name: Release the Package
command: |
cd ./Hackney.Shared.ContactDetails
dotnet pack --configuration Release
- run:
name: Publish to GitHub
command: |
cd /root/project/Hackney.Shared.ContactDetails/bin/Release
dotnet nuget push Hackney.Shared.ContactDetails.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${NUGET_KEY} Hackney.Shared.ContactDetails.*/*.nupkg
workflows:
nuget-package:
jobs:
- check-code-formatting
- build-and-test
- publish-package:
requires:
- build-and-test
filters:
branches:
only: main

68 changes: 68 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#Junk Files
*.DS_Store
[Tt]humbs.db

#Visual Studio Files
[Oo]bj
[Bb]in
[Dd]ebug
[Bb]uild/
*.user
*.suo
*.exe
*.pdb
*.aps
*_i.c
*_p.c
*.ncb
*.tlb
*.tlh
*.[Cc]ache
*.bak
*.ncb
*.ilk
*.log
*.lib
*.sbr
*.sdf
ipch/
*.dbmdl
*.csproj.user
*.cache
*.swp
*.vspscc
*.vssscc
*.bak.*
*.bak

#Tools
_ReSharper.*
_ReSharper*/
*.resharper
*.resharper.user
[Nn][Dd]epend[Oo]ut*/
Ankh.NoLoad

#Other
.svn

# Include DLLs if they're in the NuGet packages directory
!/packages/*/lib/*.dll
!/packages/*/lib/*/*.dll

# Ignore master key for decrypting credentials and more.
/config/master.key

obj/
out/
bin/
.idea/
tmp/
.vs/
/Hackney.Shared.ContactDetails.Tests/Properties/launchSettings.json

.fake
.ionide

*.nupkg
testresults/
Binary file not shown.
Binary file added .vs/Hackney.Shared.ContactDetails/v16/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
8 changes: 8 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# doc for this file https://help.github.com/articles/about-code-owners/

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.

* @LBHMGeorgieva @LBHMKeyworth @LBHSPreston @LBHRShetty @mtfh-manage-my-home
21 changes: 21 additions & 0 deletions Hackney.Shared.ContactDetails.Tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

# disable microsoft telematry
ENV DOTNET_CLI_TELEMETRY_OPTOUT='true'

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY ./Hackney.Shared.ContactDetails.sln ./
COPY ./Hackney.Shared.ContactDetails/Hackney.Shared.ContactDetails.csproj ./Hackney.Shared.ContactDetails/
COPY ./Hackney.Shared.ContactDetails.Tests/Hackney.Shared.ContactDetails.Tests.csproj ./Hackney.Shared.ContactDetails.Tests/

RUN dotnet restore ./Hackney.Shared.ContactDetails/Hackney.Shared.ContactDetails.csproj
RUN dotnet restore ./Hackney.Shared.ContactDetails.Tests/Hackney.Shared.ContactDetails.Tests.csproj

# Copy everything else and build
COPY . .

RUN dotnet build -c debug -o out Hackney.Shared.ContactDetails.Tests/Hackney.Shared.ContactDetails.Tests.csproj

CMD dotnet test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
<NoWarn>CA1303;CA1305;CA1001;CA1062;CA1307</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Remove="TestResults\**" />
<EmbeddedResource Remove="TestResults\**" />
<None Remove="TestResults\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.17.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Hackney.Shared.ContactDetails\Hackney.Shared.ContactDetails.csproj" />
</ItemGroup>

</Project>
88 changes: 88 additions & 0 deletions Hackney.Shared.ContactDetails.Tests/SNS/SnsGatewayTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
using AutoFixture;
using FluentAssertions;
using Hackney.Shared.ContactDetails.Sns;
using Moq;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Xunit;

namespace Hackney.Shared.ContactDetails.Tests.Sns
{
public class SnsGatewayTests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can stay in LBH-Core

{
private readonly Fixture _fixture = new Fixture();
private readonly Mock<IAmazonSimpleNotificationService> _mockAwsSns;
private readonly SnsGateway _sut;
private readonly SnsTestMessage _message;
private readonly JsonSerializerOptions _jsonOptions;

private readonly string _topic = "some-topic";
private readonly string _group = "some-group";

public SnsGatewayTests()
{
_mockAwsSns = new Mock<IAmazonSimpleNotificationService>();
_sut = new SnsGateway(_mockAwsSns.Object);
_message = _fixture.Create<SnsTestMessage>();
_jsonOptions = CreateJsonOptions();
}

private static JsonSerializerOptions CreateJsonOptions()
{
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
};
options.Converters.Add(new JsonStringEnumConverter());
return options;
}

private static bool VerifyPublishRequest(PublishRequest actual, string expectedMsgJson, string expectedTopic, string expectedGroup)
{
actual.Message.Should().Be(expectedMsgJson);
actual.TopicArn.Should().Be(expectedTopic);
actual.MessageGroupId.Should().Be(expectedGroup);
return true;
}

[Fact]
public void PublishTestNullSnsObjectThrows()
{
Func<Task> func = async () => await _sut.Publish<SnsTestMessage>(null, _topic, _group).ConfigureAwait(false);
func.Should().Throw<ArgumentNullException>();
}

[Theory]
[InlineData(null)]
[InlineData("")]
public void PublishTestNullTopicArnThrows(string topic)
{
Func<Task> func = async () => await _sut.Publish<SnsTestMessage>(_message, topic, _group).ConfigureAwait(false);
func.Should().Throw<ArgumentNullException>();
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("a_group")]
public async Task PublishTestPublishesMessageToTopic(string group)
{
var msgJson = JsonSerializer.Serialize(_message, _jsonOptions);
await _sut.Publish<SnsTestMessage>(_message, _topic, group).ConfigureAwait(false);

_mockAwsSns.Verify(x => x.PublishAsync(It.Is<PublishRequest>(y => VerifyPublishRequest(y, msgJson, _topic, group)), default), Times.Once);
}
}

public class SnsTestMessage
{
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading