From 9bc08731aad112f100bcbc105f2cca910948651f Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 20 Oct 2019 16:24:11 +0800 Subject: ... --- Timeline.Tests/Controllers/TokenControllerTest.cs | 13 ++++++--- Timeline.Tests/GlobalSuppressions.cs | 9 +++++++ .../Mock/Services/MockStringLocalizer.cs | 31 ++++++++++++++++++++++ Timeline.Tests/Timeline.Tests.csproj | 6 ++++- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 Timeline.Tests/GlobalSuppressions.cs create mode 100644 Timeline.Tests/Mock/Services/MockStringLocalizer.cs (limited to 'Timeline.Tests') 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 _mockUserService = new Mock(); private readonly TestClock _mockClock = new TestClock(); @@ -24,7 +24,14 @@ namespace Timeline.Tests.Controllers public TokenControllerTest() { - _controller = new TokenController(_mockUserService.Object, NullLogger.Instance, _mockClock); + _controller = new TokenController(_mockUserService.Object, + NullLogger.Instance, _mockClock, + new MockStringLocalizer()); + } + + public void Dispose() + { + _controller.Dispose(); } [Theory] @@ -110,7 +117,5 @@ namespace Timeline.Tests.Controllers .Which.Value.Should().BeAssignableTo() .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 GetAllStrings(bool includeParentCultures) + { + yield return new LocalizedString(mockKey, mockString); + } + + public IStringLocalizer WithCulture(CultureInfo culture) + { + return this; + } + } + + public class MockStringLocalizer : MockStringLocalizer, IStringLocalizer + { + + } +} 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 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + all -- cgit v1.2.3