diff options
Diffstat (limited to 'Timeline.Tests')
-rw-r--r-- | Timeline.Tests/Controllers/TokenControllerTest.cs | 13 | ||||
-rw-r--r-- | Timeline.Tests/GlobalSuppressions.cs | 9 | ||||
-rw-r--r-- | Timeline.Tests/Mock/Services/MockStringLocalizer.cs | 31 | ||||
-rw-r--r-- | Timeline.Tests/Timeline.Tests.csproj | 6 |
4 files changed, 54 insertions, 5 deletions
diff --git a/Timeline.Tests/Controllers/TokenControllerTest.cs b/Timeline.Tests/Controllers/TokenControllerTest.cs index 8b1cf071..86a241e5 100644 --- a/Timeline.Tests/Controllers/TokenControllerTest.cs +++ b/Timeline.Tests/Controllers/TokenControllerTest.cs @@ -15,7 +15,7 @@ using static Timeline.ErrorCodes.Http.Token; namespace Timeline.Tests.Controllers
{
- public class TokenControllerTest
+ public class TokenControllerTest : IDisposable
{
private readonly Mock<IUserService> _mockUserService = new Mock<IUserService>();
private readonly TestClock _mockClock = new TestClock();
@@ -24,7 +24,14 @@ namespace Timeline.Tests.Controllers public TokenControllerTest()
{
- _controller = new TokenController(_mockUserService.Object, NullLogger<TokenController>.Instance, _mockClock);
+ _controller = new TokenController(_mockUserService.Object,
+ NullLogger<TokenController>.Instance, _mockClock,
+ new MockStringLocalizer<TokenController>());
+ }
+
+ public void Dispose()
+ {
+ _controller.Dispose();
}
[Theory]
@@ -110,7 +117,5 @@ namespace Timeline.Tests.Controllers .Which.Value.Should().BeAssignableTo<CommonResponse>()
.Which.Code.Should().Be(code);
}
-
- // TODO! Verify unit tests
}
}
diff --git a/Timeline.Tests/GlobalSuppressions.cs b/Timeline.Tests/GlobalSuppressions.cs new file mode 100644 index 00000000..6562efbb --- /dev/null +++ b/Timeline.Tests/GlobalSuppressions.cs @@ -0,0 +1,9 @@ +// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "This is not a UI application.")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Tests name have underscores.")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "Test classes do not need to implement it that way.")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "Test classes do not need to implement it that way.")]
diff --git a/Timeline.Tests/Mock/Services/MockStringLocalizer.cs b/Timeline.Tests/Mock/Services/MockStringLocalizer.cs new file mode 100644 index 00000000..7729d56c --- /dev/null +++ b/Timeline.Tests/Mock/Services/MockStringLocalizer.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Localization;
+using System.Collections.Generic;
+using System.Globalization;
+
+namespace Timeline.Tests.Mock.Services
+{
+ public class MockStringLocalizer : IStringLocalizer
+ {
+ private const string mockKey = "MOCK_KEY";
+ private const string mockString = "THIS IS A MOCK LOCALIZED STRING.";
+
+ public LocalizedString this[string name] => new LocalizedString(name, mockString);
+
+ public LocalizedString this[string name, params object[] arguments] => new LocalizedString(name, mockString);
+
+ public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
+ {
+ yield return new LocalizedString(mockKey, mockString);
+ }
+
+ public IStringLocalizer WithCulture(CultureInfo culture)
+ {
+ return this;
+ }
+ }
+
+ public class MockStringLocalizer<T> : MockStringLocalizer, IStringLocalizer<T>
+ {
+
+ }
+}
diff --git a/Timeline.Tests/Timeline.Tests.csproj b/Timeline.Tests/Timeline.Tests.csproj index 3f88f174..a611dfd3 100644 --- a/Timeline.Tests/Timeline.Tests.csproj +++ b/Timeline.Tests/Timeline.Tests.csproj @@ -15,9 +15,13 @@ <PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
- <PackageReference Include="Moq" Version="4.13.0" />
+ <PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
|