Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace MHP.CodingChallenge.Backend.Dependency.Inquiry
{
public class Inquiry
{
public String Username { get; set; }
public String Recipient { get; set; }
public String Text { get; set; }

public override String ToString()
{
return "Inquiry{" +
"username='" + Username + '\'' +
", recipient='" + Recipient + '\'' +
", text='" + Text + '\'' +
'}';
}

public override bool Equals(Object o)
{
if (this == o) return true;
if (o == null || GetType() != o.GetType()) return false;
Inquiry inquiry = (Inquiry)o;
return Object.Equals(Username, inquiry.Username) &&
Object.Equals(Recipient, inquiry.Recipient) &&
Object.Equals(Text, inquiry.Text);
}

public override int GetHashCode()
{
return HashCode.Combine(Username, Recipient, Text);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace MHP.CodingChallenge.Backend.Dependency.Inquiry
{
public class InquiryService
{
public void Create(Inquiry inquiry)
{
Console.WriteLine(string.Format("User sent inquiry: {0}", inquiry.ToString()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using MHP.CodingChallenge.Backend.Dependency.Inquiry;
using Microsoft.Extensions.Logging;

namespace MHP.CodingChallenge.Backend.Dependency.Notifications
{
public class EmailHandler
{
public virtual void SendEmail(Inquiry.Inquiry inquiry)
{
Console.WriteLine(string.Format("sending email for: {0}", inquiry.ToString()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\MHP.CodingChallenge.Backend.Dependency.Inquiry\MHP.CodingChallenge.Backend.Dependency.Inquiry.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using MHP.CodingChallenge.Backend.Dependency.Inquiry;
using Microsoft.Extensions.Logging;

namespace MHP.CodingChallenge.Backend.Dependency.Notifications
{
public class PushNotificationHandler
{
public virtual void SendNotification(Inquiry.Inquiry inquiry)
{
Console.WriteLine(string.Format("sending notification inquiry: {0}", inquiry.ToString()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Xunit;
using MHP.CodingChallenge.Backend.Dependency.Inquiry;
using Microsoft.Extensions.DependencyInjection;
using MHP.CodingChallenge.Backend.Dependency.Notifications;
using Moq;

namespace MHP.CodingChallenge.Backend.Dependency.Test
{
public class InquiryTest
{
[Fact]
public void TestInquiryHandlers()
{
// given
Inquiry.Inquiry inquiry = new Inquiry.Inquiry();
inquiry.Username = "TestUser";
inquiry.Recipient = "service@example.com";
inquiry.Text = "Can I haz cheezburger?";

// room for potential additional test setup
var mockEmailHander = new Mock<EmailHandler>();
var mockPushNotificationHandler = new Mock<PushNotificationHandler>();

var services = new ServiceCollection()
.AddLogging()
.AddSingleton<InquiryService>()
.AddSingleton(mockEmailHander.Object)
.AddSingleton(mockPushNotificationHandler.Object);

var inquiryService = services
.BuildServiceProvider()
.GetRequiredService<InquiryService>();

// when
inquiryService.Create(inquiry);

// then
mockEmailHander.Verify(e => e.SendEmail(inquiry));
mockPushNotificationHandler.Verify(e => e.SendNotification(inquiry));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.DependencyInjection" Version="7.2.0" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.1.1" />
<PackageReference Include="Moq" Version="4.16.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MHP.CodingChallenge.Backend.Dependency\MHP.CodingChallenge.Backend.Dependency.csproj" />
<ProjectReference Include="..\MHP.CodingChallenge.Backend.Dependency.Inquiry\MHP.CodingChallenge.Backend.Dependency.Inquiry.csproj" />
<ProjectReference Include="..\MHP.CodingChallenge.Backend.Dependency.Notifications\MHP.CodingChallenge.Backend.Dependency.Notifications.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Microsoft.Extensions.Configuration;

namespace MHP.CodingChallenge.Backend.Dependency.Test
{
public class Startup
{
public Startup()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.808.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHP.CodingChallenge.Backend.Dependency", "MHP.CodingChallenge.Backend.Dependency\MHP.CodingChallenge.Backend.Dependency.csproj", "{3EB0148C-F094-4D4E-A62E-0F722D4EB4BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHP.CodingChallenge.Backend.Dependency.Inquiry", "MHP.CodingChallenge.Backend.Dependency.Inquiry\MHP.CodingChallenge.Backend.Dependency.Inquiry.csproj", "{D9294E3E-2D76-46E6-A73A-08B942B4A587}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHP.CodingChallenge.Backend.Dependency.Notifications", "MHP.CodingChallenge.Backend.Dependency.Notifications\MHP.CodingChallenge.Backend.Dependency.Notifications.csproj", "{17A527BA-8779-4094-8584-4DEDB8F01235}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHP.CodingChallenge.Backend.Dependency.Test", "MHP.CodingChallenge.Backend.Dependency.Test\MHP.CodingChallenge.Backend.Dependency.Test.csproj", "{97E9E997-33F1-4AAE-A0C8-2FA38E92BFFA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{18C9722F-605C-41BA-ADE0-9627F10E2866}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3EB0148C-F094-4D4E-A62E-0F722D4EB4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3EB0148C-F094-4D4E-A62E-0F722D4EB4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EB0148C-F094-4D4E-A62E-0F722D4EB4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EB0148C-F094-4D4E-A62E-0F722D4EB4BF}.Release|Any CPU.Build.0 = Release|Any CPU
{D9294E3E-2D76-46E6-A73A-08B942B4A587}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9294E3E-2D76-46E6-A73A-08B942B4A587}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9294E3E-2D76-46E6-A73A-08B942B4A587}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9294E3E-2D76-46E6-A73A-08B942B4A587}.Release|Any CPU.Build.0 = Release|Any CPU
{17A527BA-8779-4094-8584-4DEDB8F01235}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17A527BA-8779-4094-8584-4DEDB8F01235}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17A527BA-8779-4094-8584-4DEDB8F01235}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17A527BA-8779-4094-8584-4DEDB8F01235}.Release|Any CPU.Build.0 = Release|Any CPU
{97E9E997-33F1-4AAE-A0C8-2FA38E92BFFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97E9E997-33F1-4AAE-A0C8-2FA38E92BFFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97E9E997-33F1-4AAE-A0C8-2FA38E92BFFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97E9E997-33F1-4AAE-A0C8-2FA38E92BFFA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {64806438-BF57-44F0-B7D2-99E7B7A3EF2E}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(RunConfiguration)' == 'MHP.CodingChallenge.Backend.Dependency' " />
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MHP.CodingChallenge.Backend.Dependency.Inquiry\MHP.CodingChallenge.Backend.Dependency.Inquiry.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace MHP.CodingChallenge.Backend.Dependency
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:7401",
"sslPort": 44326
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MHP.CodingChallenge.Backend.Dependency": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MHP.CodingChallenge.Backend.Dependency.Inquiry;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;

namespace MHP.CodingChallenge.Backend.Dependency
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<InquiryService>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Loading