Skip to content

Commit

Permalink
Merge pull request #182 from FoldingCoin/develop
Browse files Browse the repository at this point in the history
Merge v1.2.0
  • Loading branch information
StrungSafe committed Nov 9, 2018
2 parents d382720 + 02ce0a2 commit 8788495
Show file tree
Hide file tree
Showing 60 changed files with 1,524 additions and 732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using Interfaces;
using NSubstitute;
using NSubstitute.ClearExtensions;
using NUnit.Framework;
using StatsDownload.Email;

Expand All @@ -14,18 +15,42 @@ public void SetUp()
{
emailServiceMock = Substitute.For<IEmailService>();

systemUnderTest = NewStatsDownloadApiEmailProvider(emailServiceMock);
emailSettingsServiceMock = Substitute.For<IEmailSettingsService>();
emailSettingsServiceMock.GetFromDisplayName().Returns("DisplayName");

systemUnderTest = NewStatsDownloadApiEmailProvider(emailServiceMock, emailSettingsServiceMock);
}

private IEmailService emailServiceMock;

private IEmailSettingsService emailSettingsServiceMock;

private IStatsDownloadApiEmailService systemUnderTest;

[Test]
public void Constructor_WhenNullDependencyProvided_ThrowsException()
{
Assert.Throws<ArgumentNullException>(() =>
NewStatsDownloadApiEmailProvider(null));
NewStatsDownloadApiEmailProvider(null, emailSettingsServiceMock));
Assert.Throws<ArgumentNullException>(() =>
NewStatsDownloadApiEmailProvider(emailServiceMock, null));
}

[TestCase(null)]
[TestCase("")]
[TestCase("\t")]
[TestCase("\n")]
public void SendUnhandledExceptionEmail_WhenEmptyDisplayName_DoesNotPrependDisplayName(string displayName)
{
emailSettingsServiceMock.ClearSubstitute();
emailSettingsServiceMock.GetFromDisplayName().Returns(displayName);

var exception = new Exception("test message");

systemUnderTest.SendUnhandledExceptionEmail(exception);

emailServiceMock.Received().SendEmail("API Unhandled Exception Caught",
"The StatsDownload API experienced an unhandled exception. Contact your technical advisor with the exception message. Exception Message: test message");
}

[Test]
Expand All @@ -35,13 +60,14 @@ public void SendUnhandledExceptionEmail_WhenInvoked_SendsEmail()

systemUnderTest.SendUnhandledExceptionEmail(exception);

emailServiceMock.Received().SendEmail("API Unhandled Exception Caught",
emailServiceMock.Received().SendEmail("DisplayName - API Unhandled Exception Caught",
"The StatsDownload API experienced an unhandled exception. Contact your technical advisor with the exception message. Exception Message: test message");
}

private IStatsDownloadApiEmailService NewStatsDownloadApiEmailProvider(IEmailService emailService)
private IStatsDownloadApiEmailService NewStatsDownloadApiEmailProvider(IEmailService emailService,
IEmailSettingsService emailSettingsService)
{
return new StatsDownloadApiEmailProvider(emailService);
return new StatsDownloadApiEmailProvider(emailService, emailSettingsService);
}
}
}
2 changes: 1 addition & 1 deletion Api/StatsDownloadApi.Core/StatsDownloadApi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 20 additions & 2 deletions Api/StatsDownloadApi.Core/StatsDownloadApiEmailProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,33 @@ public class StatsDownloadApiEmailProvider : IStatsDownloadApiEmailService
{
private readonly IEmailService emailService;

public StatsDownloadApiEmailProvider(IEmailService emailService)
private readonly IEmailSettingsService emailSettingsService;

public StatsDownloadApiEmailProvider(IEmailService emailService, IEmailSettingsService emailSettingsService)
{
this.emailService = emailService ?? throw new ArgumentNullException(nameof(emailService));
this.emailSettingsService =
emailSettingsService ?? throw new ArgumentNullException(nameof(emailSettingsService));
}

public void SendUnhandledExceptionEmail(Exception exception)
{
emailService.SendEmail(EmailMessages.UnhandledExceptionHeader,
string subject = GetSubject(EmailMessages.UnhandledExceptionHeader);

emailService.SendEmail(subject,
string.Format(EmailMessages.UnhandledExceptionBody, exception.Message));
}

private string GetSubject(string baseSubject)
{
string displayName = emailSettingsService.GetFromDisplayName();

if (string.IsNullOrWhiteSpace(displayName))
{
return baseSubject;
}

return $"{displayName} - {baseSubject}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions Api/StatsDownloadApi.WebApi/StatsDownloadApi.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,15 +12,15 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Windsor" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.3" />
<PackageReference Include="Castle.Windsor" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
<PackageReference Include="MySql.Data" Version="8.0.12" />
<PackageReference Include="NLog" Version="4.5.8" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.6.0" />
<PackageReference Include="NLog" Version="4.5.10" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.7.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
{
public interface IStatsDownloadEmailService : IFileDownloadEmailService, IStatsUploadEmailService
{
void SendTestEmail();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace StatsDownload.Core.Interfaces
{
public interface IStatsFileDateTimeFormatsAndOffsetService
{
(string format, int hourOffset)[] GetStatsFileDateTimeFormatsAndOffset();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace StatsDownload.Core.Interfaces
{
public interface IStatsFileDateTimeFormatsAndOffsetSettings
{
string GetStatsFileTimeZoneAndOffsetSettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Windsor" Version="4.1.0" />
<PackageReference Include="Castle.Windsor" Version="4.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,23 @@ public void GetDownloadsReadyForUpload_WhenNoFilesReadyForUpload_ReturnsEmptyLis
Assert.That(actual.Count, Is.EqualTo(0));
}

[Test]
public void GetFileData_WhenFileDataDbNull_ReturnsNull()
{
var dbParameter = Substitute.For<DbParameter>();
dbParameter.Value.Returns(DBNull.Value);

databaseConnectionServiceMock.ClearSubstitute();
databaseConnectionServiceMock.CreateParameter("@FileData", DbType.String, ParameterDirection.Output, -1)
.Returns(dbParameter);
databaseConnectionServiceMock.CreateParameter("@DownloadId", DbType.Int32, ParameterDirection.Input)
.Returns(Substitute.For<DbParameter>());

string actual = systemUnderTest.GetFileData(100);

Assert.That(actual, Is.Null);
}

[Test]
public void GetFileData_WhenInvoked_GetFileData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private string GetFileData(IDatabaseConnectionService databaseConnection, int do
databaseConnection.ExecuteStoredProcedure(Constants.StatsUploadDatabase.GetFileDataProcedureName,
new List<DbParameter> { download, fileName, fileExtension, fileData });

return (string) fileData.Value;
return fileData.Value as string;
}

private bool IsUserDataValid(AddUserDataParameters addUserParameters, UserData userData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Shared/StatsDownload.Email/EmailProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public EmailResult SendEmail(string subject, string body)
{
sb.AppendLine("Attempting to send email:");
sb.AppendLine($"Subject: {subject}");
sb.Append($"Body: {body}");
sb.AppendLine($"Body: {body}");

MailAddress fromAddress = NewMailAddress();

Expand Down
2 changes: 1 addition & 1 deletion Shared/StatsDownload.Email/StatsDownload.Email.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Shared/StatsDownload.Logging/StatsDownload.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 8788495

Please sign in to comment.