From e7ca87f25dae2f806469043ee556d4790d9ebcae Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Mar 2020 03:04:23 +0800 Subject: ... --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 14a0a59e..cad74e6c 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -6,11 +6,11 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using Timeline.Models.Http; -using Timeline.Tests.Helpers; +using TimelineApp.Models.Http; +using TimelineApp.Tests.Helpers; using Xunit; -namespace Timeline.Tests.IntegratedTests +namespace TimelineApp.Tests.IntegratedTests { public class TimelineTest : IntegratedTestBase { -- cgit v1.2.3 From 52c59d7cd949ee6ccc89fbb25231666e1e589fe2 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Mar 2020 15:46:59 +0800 Subject: Revert namespace name change. --- .../ErrorResponseCodeGenerator.csproj | 2 +- ErrorResponseCodeGenerator/Program.cs | 2 +- Timeline.ErrorCodes/ErrorCodes.cs | 2 +- Timeline.ErrorCodes/Timeline.ErrorCodes.csproj | 7 + Timeline.ErrorCodes/TimelineApp.ErrorCodes.csproj | 7 - Timeline.Tests/ErrorCodeTest.cs | 4 +- .../Helpers/AsyncFunctionAssertionsExtensions.cs | 2 +- Timeline.Tests/Helpers/HttpClientExtensions.cs | 2 +- Timeline.Tests/Helpers/ImageHelper.cs | 2 +- Timeline.Tests/Helpers/ParameterInfoAssertions.cs | 2 +- Timeline.Tests/Helpers/ReflectionHelper.cs | 2 +- Timeline.Tests/Helpers/ResponseAssertions.cs | 6 +- Timeline.Tests/Helpers/TestApplication.cs | 6 +- .../IntegratedTests/AuthorizationTest.cs | 4 +- .../IntegratedTests/IntegratedTestBase.cs | 8 +- .../IntegratedTests/PersonalTimelineTest.cs | 6 +- Timeline.Tests/IntegratedTests/TimelineTest.cs | 6 +- Timeline.Tests/IntegratedTests/TokenTest.cs | 8 +- Timeline.Tests/IntegratedTests/UserAvatarTest.cs | 8 +- Timeline.Tests/IntegratedTests/UserTest.cs | 6 +- Timeline.Tests/PasswordGenerator.cs | 4 +- Timeline.Tests/Timeline.Tests.csproj | 33 ++++ Timeline.Tests/TimelineApp.Tests.csproj | 33 ---- Timeline.Tests/UsernameValidatorUnitTest.cs | 6 +- Timeline.sln | 6 +- Timeline/Auth/Attribute.cs | 4 +- Timeline/Auth/MyAuthenticationHandler.cs | 6 +- Timeline/Auth/PrincipalExtensions.cs | 4 +- Timeline/Configs/JwtConfiguration.cs | 2 +- Timeline/Controllers/ControllerAuthExtensions.cs | 6 +- Timeline/Controllers/PersonalTimelineController.cs | 10 +- .../Controllers/Testing/TestingAuthController.cs | 4 +- Timeline/Controllers/TimelineController.cs | 12 +- Timeline/Controllers/TokenController.cs | 10 +- Timeline/Controllers/UserAvatarController.cs | 18 +- Timeline/Controllers/UserController.cs | 16 +- Timeline/Entities/DataEntity.cs | 2 +- Timeline/Entities/DatabaseContext.cs | 2 +- Timeline/Entities/JwtTokenEntity.cs | 2 +- Timeline/Entities/TimelineEntity.cs | 4 +- Timeline/Entities/TimelineMemberEntity.cs | 2 +- Timeline/Entities/TimelinePostEntity.cs | 2 +- Timeline/Entities/UserAvatarEntity.cs | 2 +- Timeline/Entities/UserEntity.cs | 2 +- Timeline/Filters/Header.cs | 4 +- Timeline/Filters/Timeline.cs | 6 +- Timeline/Formatters/StringInputFormatter.cs | 2 +- Timeline/Helpers/InvalidModelResponseFactory.cs | 4 +- Timeline/Helpers/LanguageHelper.cs | 2 +- Timeline/Helpers/Log.cs | 2 +- .../Helpers/StringLocalizerFactoryExtensions.cs | 2 +- .../20200105150407_Initialize.Designer.cs | 4 +- Timeline/Migrations/20200105150407_Initialize.cs | 2 +- .../20200131100517_RefactorUser.Designer.cs | 4 +- Timeline/Migrations/20200131100517_RefactorUser.cs | 2 +- .../20200221064341_AddJwtToken.Designer.cs | 4 +- Timeline/Migrations/20200221064341_AddJwtToken.cs | 2 +- .../20200229103848_AddPostLocalId.Designer.cs | 4 +- .../Migrations/20200229103848_AddPostLocalId.cs | 2 +- .../20200306110049_AddDataTable.Designer.cs | 4 +- Timeline/Migrations/20200306110049_AddDataTable.cs | 2 +- .../20200306111553_DropUserDetails.Designer.cs | 4 +- .../Migrations/20200306111553_DropUserDetails.cs | 2 +- .../Migrations/DatabaseContextModelSnapshot.cs | 4 +- .../Models/Converters/JsonDateTimeConverter.cs | 2 +- Timeline/Models/Http/Common.cs | 4 +- Timeline/Models/Http/ErrorResponse.cs | 4 +- Timeline/Models/Http/Timeline.cs | 4 +- Timeline/Models/Http/TimelineController.cs | 4 +- Timeline/Models/Http/TokenController.cs | 2 +- Timeline/Models/Http/UserController.cs | 6 +- Timeline/Models/Http/UserInfo.cs | 4 +- Timeline/Models/Timeline.cs | 2 +- Timeline/Models/User.cs | 2 +- Timeline/Models/Validation/NameValidator.cs | 4 +- Timeline/Models/Validation/NicknameValidator.cs | 4 +- .../Models/Validation/TimelineNameValidator.cs | 2 +- Timeline/Models/Validation/UsernameValidator.cs | 2 +- Timeline/Models/Validation/Validator.cs | 6 +- Timeline/Program.cs | 4 +- .../Authentication/AuthHandler.Designer.cs | 4 +- .../ControllerAuthExtensions.Designer.cs | 4 +- .../Controllers/TimelineController.Designer.cs | 4 +- .../Controllers/TokenController.Designer.cs | 4 +- .../Controllers/UserAvatarController.Designer.cs | 4 +- .../Controllers/UserController.Designer.cs | 4 +- Timeline/Resources/Filters.Designer.cs | 4 +- Timeline/Resources/Messages.Designer.cs | 4 +- Timeline/Resources/Models/Http/Common.Designer.cs | 4 +- .../Models/Validation/NameValidator.Designer.cs | 4 +- .../Validation/NicknameValidator.Designer.cs | 4 +- .../Models/Validation/Validator.Designer.cs | 4 +- .../Resources/Services/DataManager.Designer.cs | 4 +- Timeline/Resources/Services/Exception.Designer.cs | 4 +- .../Resources/Services/TimelineService.Designer.cs | 4 +- .../Services/UserAvatarService.Designer.cs | 4 +- .../Resources/Services/UserService.Designer.cs | 4 +- .../Services/UserTokenService.Designer.cs | 4 +- Timeline/Services/BadPasswordException.cs | 4 +- Timeline/Services/Clock.cs | 2 +- Timeline/Services/ConflictException.cs | 2 +- Timeline/Services/DataManager.cs | 4 +- Timeline/Services/DatabaseCorruptedException.cs | 2 +- Timeline/Services/ETagGenerator.cs | 2 +- Timeline/Services/ImageException.cs | 2 +- Timeline/Services/ImageValidator.cs | 2 +- .../Services/JwtUserTokenBadFormatException.cs | 4 +- Timeline/Services/PasswordBadFormatException.cs | 2 +- Timeline/Services/PasswordService.cs | 2 +- Timeline/Services/PathProvider.cs | 2 +- Timeline/Services/TimelineNotExistException.cs | 2 +- Timeline/Services/TimelinePostNotExistException.cs | 2 +- Timeline/Services/TimelineService.cs | 32 ++-- Timeline/Services/UserAvatarService.cs | 6 +- Timeline/Services/UserNotExistException.cs | 4 +- Timeline/Services/UserRoleConvert.cs | 4 +- Timeline/Services/UserService.cs | 12 +- Timeline/Services/UserTokenException.cs | 2 +- Timeline/Services/UserTokenManager.cs | 4 +- Timeline/Services/UserTokenService.cs | 6 +- Timeline/Startup.cs | 18 +- Timeline/Timeline.csproj | 207 ++++++++++++++++++++ Timeline/TimelineApp.csproj | 211 --------------------- 123 files changed, 505 insertions(+), 509 deletions(-) create mode 100644 Timeline.ErrorCodes/Timeline.ErrorCodes.csproj delete mode 100644 Timeline.ErrorCodes/TimelineApp.ErrorCodes.csproj create mode 100644 Timeline.Tests/Timeline.Tests.csproj delete mode 100644 Timeline.Tests/TimelineApp.Tests.csproj create mode 100644 Timeline/Timeline.csproj delete mode 100644 Timeline/TimelineApp.csproj (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/ErrorResponseCodeGenerator/ErrorResponseCodeGenerator.csproj b/ErrorResponseCodeGenerator/ErrorResponseCodeGenerator.csproj index a4ce64e6..8524b2e4 100644 --- a/ErrorResponseCodeGenerator/ErrorResponseCodeGenerator.csproj +++ b/ErrorResponseCodeGenerator/ErrorResponseCodeGenerator.csproj @@ -10,7 +10,7 @@ - + diff --git a/ErrorResponseCodeGenerator/Program.cs b/ErrorResponseCodeGenerator/Program.cs index 0d2b2a3e..5ea8aaca 100644 --- a/ErrorResponseCodeGenerator/Program.cs +++ b/ErrorResponseCodeGenerator/Program.cs @@ -45,7 +45,7 @@ namespace ErrorResponseCodeGenerator "; } - RecursiveAddErrorCode(typeof(TimelineApp.Models.Http.ErrorCodes), true); + RecursiveAddErrorCode(typeof(Timeline.Models.Http.ErrorCodes), true); code = @" using static Timeline.Resources.Messages; diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs index b60a96ac..eca0e18b 100644 --- a/Timeline.ErrorCodes/ErrorCodes.cs +++ b/Timeline.ErrorCodes/ErrorCodes.cs @@ -1,4 +1,4 @@ -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { /// /// All error code constants. diff --git a/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj b/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj new file mode 100644 index 00000000..01ca2568 --- /dev/null +++ b/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp3.1 + + + diff --git a/Timeline.ErrorCodes/TimelineApp.ErrorCodes.csproj b/Timeline.ErrorCodes/TimelineApp.ErrorCodes.csproj deleted file mode 100644 index 01ca2568..00000000 --- a/Timeline.ErrorCodes/TimelineApp.ErrorCodes.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - netcoreapp3.1 - - - diff --git a/Timeline.Tests/ErrorCodeTest.cs b/Timeline.Tests/ErrorCodeTest.cs index 3f8c855c..258ebf4e 100644 --- a/Timeline.Tests/ErrorCodeTest.cs +++ b/Timeline.Tests/ErrorCodeTest.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using TimelineApp.Models.Http; +using Timeline.Models.Http; using Xunit; using Xunit.Abstractions; -namespace TimelineApp.Tests +namespace Timeline.Tests { public class ErrorCodeTest { diff --git a/Timeline.Tests/Helpers/AsyncFunctionAssertionsExtensions.cs b/Timeline.Tests/Helpers/AsyncFunctionAssertionsExtensions.cs index 516c34e9..b78309c0 100644 --- a/Timeline.Tests/Helpers/AsyncFunctionAssertionsExtensions.cs +++ b/Timeline.Tests/Helpers/AsyncFunctionAssertionsExtensions.cs @@ -4,7 +4,7 @@ using FluentAssertions.Specialized; using System; using System.Threading.Tasks; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public static class AsyncFunctionAssertionsExtensions { diff --git a/Timeline.Tests/Helpers/HttpClientExtensions.cs b/Timeline.Tests/Helpers/HttpClientExtensions.cs index 952266b3..6513bbe7 100644 --- a/Timeline.Tests/Helpers/HttpClientExtensions.cs +++ b/Timeline.Tests/Helpers/HttpClientExtensions.cs @@ -6,7 +6,7 @@ using System.Net.Mime; using System.Text; using System.Threading.Tasks; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public static class HttpClientExtensions { diff --git a/Timeline.Tests/Helpers/ImageHelper.cs b/Timeline.Tests/Helpers/ImageHelper.cs index ffbb38ae..9bed0917 100644 --- a/Timeline.Tests/Helpers/ImageHelper.cs +++ b/Timeline.Tests/Helpers/ImageHelper.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; using System.IO; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public static class ImageHelper { diff --git a/Timeline.Tests/Helpers/ParameterInfoAssertions.cs b/Timeline.Tests/Helpers/ParameterInfoAssertions.cs index a714f410..d3e5a41e 100644 --- a/Timeline.Tests/Helpers/ParameterInfoAssertions.cs +++ b/Timeline.Tests/Helpers/ParameterInfoAssertions.cs @@ -5,7 +5,7 @@ using FluentAssertions.Primitives; using System; using System.Reflection; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public class ParameterInfoValueFormatter : IValueFormatter { diff --git a/Timeline.Tests/Helpers/ReflectionHelper.cs b/Timeline.Tests/Helpers/ReflectionHelper.cs index 16d68bb1..3f6036e3 100644 --- a/Timeline.Tests/Helpers/ReflectionHelper.cs +++ b/Timeline.Tests/Helpers/ReflectionHelper.cs @@ -1,7 +1,7 @@ using System.Linq; using System.Reflection; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public static class ReflectionHelper { diff --git a/Timeline.Tests/Helpers/ResponseAssertions.cs b/Timeline.Tests/Helpers/ResponseAssertions.cs index 4984d224..f01a0677 100644 --- a/Timeline.Tests/Helpers/ResponseAssertions.cs +++ b/Timeline.Tests/Helpers/ResponseAssertions.cs @@ -9,10 +9,10 @@ using System.Net.Http; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; -using TimelineApp.Models.Converters; -using TimelineApp.Models.Http; +using Timeline.Models.Converters; +using Timeline.Models.Http; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public class HttpResponseMessageValueFormatter : IValueFormatter { diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs index c655d337..52c2f2e2 100644 --- a/Timeline.Tests/Helpers/TestApplication.cs +++ b/Timeline.Tests/Helpers/TestApplication.cs @@ -6,10 +6,10 @@ using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.IO; -using TimelineApp.Entities; -using TimelineApp.Migrations; +using Timeline.Entities; +using Timeline.Migrations; -namespace TimelineApp.Tests.Helpers +namespace Timeline.Tests.Helpers { public class TestApplication : IDisposable { diff --git a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs index 69be9187..4aa6b3ae 100644 --- a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs +++ b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs @@ -2,10 +2,10 @@ using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; using System.Net; using System.Threading.Tasks; -using TimelineApp.Tests.Helpers; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class AuthorizationTest : IntegratedTestBase { diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs index e265c16e..dfde2ea5 100644 --- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs +++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Services; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Services; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public abstract class IntegratedTestBase : IClassFixture>, IDisposable { diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs index b6d3e827..7d0a68e8 100644 --- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class PersonalTimelineTest : IntegratedTestBase { diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index cad74e6c..14a0a59e 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -6,11 +6,11 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class TimelineTest : IntegratedTestBase { diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs index 10af46af..928d546c 100644 --- a/Timeline.Tests/IntegratedTests/TokenTest.cs +++ b/Timeline.Tests/IntegratedTests/TokenTest.cs @@ -4,12 +4,12 @@ using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Services; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Services; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class TokenTest : IntegratedTestBase { diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs index 8fd1d687..fa0120f1 100644 --- a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs +++ b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs @@ -13,12 +13,12 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Services; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Services; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class UserAvatarTest : IntegratedTestBase { diff --git a/Timeline.Tests/IntegratedTests/UserTest.cs b/Timeline.Tests/IntegratedTests/UserTest.cs index eed13565..8ce76299 100644 --- a/Timeline.Tests/IntegratedTests/UserTest.cs +++ b/Timeline.Tests/IntegratedTests/UserTest.cs @@ -4,11 +4,11 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using TimelineApp.Models.Http; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Http; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests.IntegratedTests +namespace Timeline.Tests.IntegratedTests { public class UserTest : IntegratedTestBase { diff --git a/Timeline.Tests/PasswordGenerator.cs b/Timeline.Tests/PasswordGenerator.cs index bb6c538d..6c07836b 100644 --- a/Timeline.Tests/PasswordGenerator.cs +++ b/Timeline.Tests/PasswordGenerator.cs @@ -1,9 +1,9 @@ using System; -using TimelineApp.Services; +using Timeline.Services; using Xunit; using Xunit.Abstractions; -namespace TimelineApp.Tests +namespace Timeline.Tests { public class PasswordGenerator { diff --git a/Timeline.Tests/Timeline.Tests.csproj b/Timeline.Tests/Timeline.Tests.csproj new file mode 100644 index 00000000..1f00cc6c --- /dev/null +++ b/Timeline.Tests/Timeline.Tests.csproj @@ -0,0 +1,33 @@ + + + + netcoreapp3.1 + + 8.0 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + diff --git a/Timeline.Tests/TimelineApp.Tests.csproj b/Timeline.Tests/TimelineApp.Tests.csproj deleted file mode 100644 index 1f445f8b..00000000 --- a/Timeline.Tests/TimelineApp.Tests.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - netcoreapp3.1 - - 8.0 - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - diff --git a/Timeline.Tests/UsernameValidatorUnitTest.cs b/Timeline.Tests/UsernameValidatorUnitTest.cs index f436c091..8824362b 100644 --- a/Timeline.Tests/UsernameValidatorUnitTest.cs +++ b/Timeline.Tests/UsernameValidatorUnitTest.cs @@ -1,9 +1,9 @@ using FluentAssertions; -using TimelineApp.Models.Validation; -using TimelineApp.Tests.Helpers; +using Timeline.Models.Validation; +using Timeline.Tests.Helpers; using Xunit; -namespace TimelineApp.Tests +namespace Timeline.Tests { public class UsernameValidatorUnitTest : IClassFixture { diff --git a/Timeline.sln b/Timeline.sln index fc6e0d50..dfffe385 100644 --- a/Timeline.sln +++ b/Timeline.sln @@ -2,13 +2,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimelineApp", "Timeline\TimelineApp.csproj", "{A34D323C-5233-4754-B14F-4819CE9C27CA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline", "Timeline\Timeline.csproj", "{A34D323C-5233-4754-B14F-4819CE9C27CA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimelineApp.Tests", "Timeline.Tests\TimelineApp.Tests.csproj", "{3D76D578-37BC-43C2-97BF-9C6DD3825F10}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline.Tests", "Timeline.Tests\Timeline.Tests.csproj", "{3D76D578-37BC-43C2-97BF-9C6DD3825F10}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ErrorResponseCodeGenerator", "ErrorResponseCodeGenerator\ErrorResponseCodeGenerator.csproj", "{F325F802-75DE-4527-A299-F668281B0E4D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimelineApp.ErrorCodes", "Timeline.ErrorCodes\TimelineApp.ErrorCodes.csproj", "{1044E3B0-1010-47CA-956E-B6E8FE87055B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline.ErrorCodes", "Timeline.ErrorCodes\Timeline.ErrorCodes.csproj", "{1044E3B0-1010-47CA-956E-B6E8FE87055B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Timeline/Auth/Attribute.cs b/Timeline/Auth/Attribute.cs index 51e20bdf..86d0109b 100644 --- a/Timeline/Auth/Attribute.cs +++ b/Timeline/Auth/Attribute.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Authorization; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Auth +namespace Timeline.Auth { public class AdminAuthorizeAttribute : AuthorizeAttribute { diff --git a/Timeline/Auth/MyAuthenticationHandler.cs b/Timeline/Auth/MyAuthenticationHandler.cs index 5e119b69..3c97c329 100644 --- a/Timeline/Auth/MyAuthenticationHandler.cs +++ b/Timeline/Auth/MyAuthenticationHandler.cs @@ -8,10 +8,10 @@ using System.Linq; using System.Security.Claims; using System.Text.Encodings.Web; using System.Threading.Tasks; -using TimelineApp.Services; -using static TimelineApp.Resources.Authentication.AuthHandler; +using Timeline.Services; +using static Timeline.Resources.Authentication.AuthHandler; -namespace TimelineApp.Auth +namespace Timeline.Auth { public static class AuthenticationConstants { diff --git a/Timeline/Auth/PrincipalExtensions.cs b/Timeline/Auth/PrincipalExtensions.cs index e7eb04b7..ad7a887f 100644 --- a/Timeline/Auth/PrincipalExtensions.cs +++ b/Timeline/Auth/PrincipalExtensions.cs @@ -1,7 +1,7 @@ using System.Security.Principal; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Auth +namespace Timeline.Auth { internal static class PrincipalExtensions { diff --git a/Timeline/Configs/JwtConfiguration.cs b/Timeline/Configs/JwtConfiguration.cs index ce8dd48b..af8052de 100644 --- a/Timeline/Configs/JwtConfiguration.cs +++ b/Timeline/Configs/JwtConfiguration.cs @@ -1,4 +1,4 @@ -namespace TimelineApp.Configs +namespace Timeline.Configs { public class JwtConfiguration { diff --git a/Timeline/Controllers/ControllerAuthExtensions.cs b/Timeline/Controllers/ControllerAuthExtensions.cs index 9c7ea601..00a65454 100644 --- a/Timeline/Controllers/ControllerAuthExtensions.cs +++ b/Timeline/Controllers/ControllerAuthExtensions.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Security.Claims; -using TimelineApp.Auth; -using static TimelineApp.Resources.Controllers.ControllerAuthExtensions; +using Timeline.Auth; +using static Timeline.Resources.Controllers.ControllerAuthExtensions; -namespace TimelineApp.Controllers +namespace Timeline.Controllers { public static class ControllerAuthExtensions { diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs index 0c0694cb..cef04a97 100644 --- a/Timeline/Controllers/PersonalTimelineController.cs +++ b/Timeline/Controllers/PersonalTimelineController.cs @@ -4,12 +4,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Threading.Tasks; -using TimelineApp.Filters; -using TimelineApp.Models.Http; -using TimelineApp.Models.Validation; -using TimelineApp.Services; +using Timeline.Filters; +using Timeline.Models.Http; +using Timeline.Models.Validation; +using Timeline.Services; -namespace TimelineApp.Controllers +namespace Timeline.Controllers { [ApiController] [CatchTimelineNotExistException] diff --git a/Timeline/Controllers/Testing/TestingAuthController.cs b/Timeline/Controllers/Testing/TestingAuthController.cs index 6061f003..4d3b3ec7 100644 --- a/Timeline/Controllers/Testing/TestingAuthController.cs +++ b/Timeline/Controllers/Testing/TestingAuthController.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using TimelineApp.Auth; +using Timeline.Auth; -namespace TimelineApp.Controllers.Testing +namespace Timeline.Controllers.Testing { [Route("testing/auth")] [ApiController] diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index e3baff12..25290ca5 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -7,13 +7,13 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using TimelineApp.Filters; -using TimelineApp.Models; -using TimelineApp.Models.Http; -using TimelineApp.Models.Validation; -using TimelineApp.Services; +using Timeline.Filters; +using Timeline.Models; +using Timeline.Models.Http; +using Timeline.Models.Validation; +using Timeline.Services; -namespace TimelineApp.Controllers +namespace Timeline.Controllers { [ApiController] [CatchTimelineNotExistException] diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs index 47dcc0aa..1fb0b17a 100644 --- a/Timeline/Controllers/TokenController.cs +++ b/Timeline/Controllers/TokenController.cs @@ -5,12 +5,12 @@ using Microsoft.Extensions.Logging; using System; using System.Globalization; using System.Threading.Tasks; -using TimelineApp.Helpers; -using TimelineApp.Models.Http; -using TimelineApp.Services; -using static TimelineApp.Resources.Controllers.TokenController; +using Timeline.Helpers; +using Timeline.Models.Http; +using Timeline.Services; +using static Timeline.Resources.Controllers.TokenController; -namespace TimelineApp.Controllers +namespace Timeline.Controllers { [Route("token")] [ApiController] diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs index 089cef94..f4f3db3e 100644 --- a/Timeline/Controllers/UserAvatarController.cs +++ b/Timeline/Controllers/UserAvatarController.cs @@ -6,15 +6,15 @@ using Microsoft.Net.Http.Headers; using System; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Auth; -using TimelineApp.Filters; -using TimelineApp.Helpers; -using TimelineApp.Models.Http; -using TimelineApp.Models.Validation; -using TimelineApp.Services; -using static TimelineApp.Resources.Controllers.UserAvatarController; - -namespace TimelineApp.Controllers +using Timeline.Auth; +using Timeline.Filters; +using Timeline.Helpers; +using Timeline.Models.Http; +using Timeline.Models.Validation; +using Timeline.Services; +using static Timeline.Resources.Controllers.UserAvatarController; + +namespace Timeline.Controllers { [ApiController] public class UserAvatarController : Controller diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 4106c750..a3e8d816 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -5,15 +5,15 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Auth; -using TimelineApp.Helpers; -using TimelineApp.Models.Http; -using TimelineApp.Models.Validation; -using TimelineApp.Services; -using static TimelineApp.Resources.Controllers.UserController; -using static TimelineApp.Resources.Messages; +using Timeline.Auth; +using Timeline.Helpers; +using Timeline.Models.Http; +using Timeline.Models.Validation; +using Timeline.Services; +using static Timeline.Resources.Controllers.UserController; +using static Timeline.Resources.Messages; -namespace TimelineApp.Controllers +namespace Timeline.Controllers { [ApiController] public class UserController : Controller diff --git a/Timeline/Entities/DataEntity.cs b/Timeline/Entities/DataEntity.cs index dd8a8ae7..b21e2dbf 100644 --- a/Timeline/Entities/DataEntity.cs +++ b/Timeline/Entities/DataEntity.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { [Table("data")] public class DataEntity diff --git a/Timeline/Entities/DatabaseContext.cs b/Timeline/Entities/DatabaseContext.cs index 5c074d2c..8899308c 100644 --- a/Timeline/Entities/DatabaseContext.cs +++ b/Timeline/Entities/DatabaseContext.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; -namespace TimelineApp.Entities +namespace Timeline.Entities { public class DatabaseContext : DbContext { diff --git a/Timeline/Entities/JwtTokenEntity.cs b/Timeline/Entities/JwtTokenEntity.cs index 6e5ae9a8..40cb230a 100644 --- a/Timeline/Entities/JwtTokenEntity.cs +++ b/Timeline/Entities/JwtTokenEntity.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { [Table("jwt_token")] public class JwtTokenEntity diff --git a/Timeline/Entities/TimelineEntity.cs b/Timeline/Entities/TimelineEntity.cs index c902a690..56b36d4e 100644 --- a/Timeline/Entities/TimelineEntity.cs +++ b/Timeline/Entities/TimelineEntity.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using TimelineApp.Models.Http; +using Timeline.Models.Http; -namespace TimelineApp.Entities +namespace Timeline.Entities { #pragma warning disable CA2227 // Collection properties should be read only // TODO: Create index for this table. diff --git a/Timeline/Entities/TimelineMemberEntity.cs b/Timeline/Entities/TimelineMemberEntity.cs index e421ca2e..e76f2099 100644 --- a/Timeline/Entities/TimelineMemberEntity.cs +++ b/Timeline/Entities/TimelineMemberEntity.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { [Table("timeline_members")] public class TimelineMemberEntity diff --git a/Timeline/Entities/TimelinePostEntity.cs b/Timeline/Entities/TimelinePostEntity.cs index 8cdecef5..24bfc7a3 100644 --- a/Timeline/Entities/TimelinePostEntity.cs +++ b/Timeline/Entities/TimelinePostEntity.cs @@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { [Table("timeline_posts")] public class TimelinePostEntity diff --git a/Timeline/Entities/UserAvatarEntity.cs b/Timeline/Entities/UserAvatarEntity.cs index b32faf06..3c2720f7 100644 --- a/Timeline/Entities/UserAvatarEntity.cs +++ b/Timeline/Entities/UserAvatarEntity.cs @@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This is data base entity.")] [Table("user_avatars")] diff --git a/Timeline/Entities/UserEntity.cs b/Timeline/Entities/UserEntity.cs index 6c193da8..1ef3f98c 100644 --- a/Timeline/Entities/UserEntity.cs +++ b/Timeline/Entities/UserEntity.cs @@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace TimelineApp.Entities +namespace Timeline.Entities { public static class UserRoles { diff --git a/Timeline/Filters/Header.cs b/Timeline/Filters/Header.cs index 3892e451..0db11faf 100644 --- a/Timeline/Filters/Header.cs +++ b/Timeline/Filters/Header.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using TimelineApp.Models.Http; +using Timeline.Models.Http; -namespace TimelineApp.Filters +namespace Timeline.Filters { public class RequireContentTypeAttribute : ActionFilterAttribute { diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs index 28ac8818..e133c9d6 100644 --- a/Timeline/Filters/Timeline.cs +++ b/Timeline/Filters/Timeline.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using TimelineApp.Models.Http; -using TimelineApp.Services; +using Timeline.Models.Http; +using Timeline.Services; -namespace TimelineApp.Filters +namespace Timeline.Filters { public class CatchTimelineNotExistExceptionAttribute : ExceptionFilterAttribute { diff --git a/Timeline/Formatters/StringInputFormatter.cs b/Timeline/Formatters/StringInputFormatter.cs index e6831d0a..b1924268 100644 --- a/Timeline/Formatters/StringInputFormatter.cs +++ b/Timeline/Formatters/StringInputFormatter.cs @@ -5,7 +5,7 @@ using System.Net.Mime; using System.Text; using System.Threading.Tasks; -namespace TimelineApp.Formatters +namespace Timeline.Formatters { public class StringInputFormatter : TextInputFormatter { diff --git a/Timeline/Helpers/InvalidModelResponseFactory.cs b/Timeline/Helpers/InvalidModelResponseFactory.cs index 09273657..9b253e7d 100644 --- a/Timeline/Helpers/InvalidModelResponseFactory.cs +++ b/Timeline/Helpers/InvalidModelResponseFactory.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Mvc; using System.Text; -using TimelineApp.Models.Http; +using Timeline.Models.Http; -namespace TimelineApp.Helpers +namespace Timeline.Helpers { public static class InvalidModelResponseFactory { diff --git a/Timeline/Helpers/LanguageHelper.cs b/Timeline/Helpers/LanguageHelper.cs index c5272253..b0156b8b 100644 --- a/Timeline/Helpers/LanguageHelper.cs +++ b/Timeline/Helpers/LanguageHelper.cs @@ -1,6 +1,6 @@ using System.Linq; -namespace TimelineApp.Helpers +namespace Timeline.Helpers { public static class LanguageHelper { diff --git a/Timeline/Helpers/Log.cs b/Timeline/Helpers/Log.cs index bc122e76..68c975fa 100644 --- a/Timeline/Helpers/Log.cs +++ b/Timeline/Helpers/Log.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Text; -namespace TimelineApp.Helpers +namespace Timeline.Helpers { public static class Log { diff --git a/Timeline/Helpers/StringLocalizerFactoryExtensions.cs b/Timeline/Helpers/StringLocalizerFactoryExtensions.cs index 45994c36..c2252b2c 100644 --- a/Timeline/Helpers/StringLocalizerFactoryExtensions.cs +++ b/Timeline/Helpers/StringLocalizerFactoryExtensions.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.Localization; using System.Reflection; -namespace TimelineApp.Helpers +namespace Timeline.Helpers { internal static class StringLocalizerFactoryExtensions { diff --git a/Timeline/Migrations/20200105150407_Initialize.Designer.cs b/Timeline/Migrations/20200105150407_Initialize.Designer.cs index 46670fa5..99e4eaac 100644 --- a/Timeline/Migrations/20200105150407_Initialize.Designer.cs +++ b/Timeline/Migrations/20200105150407_Initialize.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200105150407_Initialize")] diff --git a/Timeline/Migrations/20200105150407_Initialize.cs b/Timeline/Migrations/20200105150407_Initialize.cs index 0013259c..4e12ef83 100644 --- a/Timeline/Migrations/20200105150407_Initialize.cs +++ b/Timeline/Migrations/20200105150407_Initialize.cs @@ -1,7 +1,7 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public partial class Initialize : Migration { diff --git a/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs b/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs index 02fde575..9b78eb15 100644 --- a/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs +++ b/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200131100517_RefactorUser")] diff --git a/Timeline/Migrations/20200131100517_RefactorUser.cs b/Timeline/Migrations/20200131100517_RefactorUser.cs index af6235e1..8597ed50 100644 --- a/Timeline/Migrations/20200131100517_RefactorUser.cs +++ b/Timeline/Migrations/20200131100517_RefactorUser.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public partial class RefactorUser : Migration { diff --git a/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs b/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs index 7c5b26b8..eb328b52 100644 --- a/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs +++ b/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200221064341_AddJwtToken")] diff --git a/Timeline/Migrations/20200221064341_AddJwtToken.cs b/Timeline/Migrations/20200221064341_AddJwtToken.cs index 00d23d0f..628970c6 100644 --- a/Timeline/Migrations/20200221064341_AddJwtToken.cs +++ b/Timeline/Migrations/20200221064341_AddJwtToken.cs @@ -2,7 +2,7 @@ using System.Security.Cryptography; using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public static class JwtTokenGenerateHelper { diff --git a/Timeline/Migrations/20200229103848_AddPostLocalId.Designer.cs b/Timeline/Migrations/20200229103848_AddPostLocalId.Designer.cs index 3abac60e..cf6ae8a3 100644 --- a/Timeline/Migrations/20200229103848_AddPostLocalId.Designer.cs +++ b/Timeline/Migrations/20200229103848_AddPostLocalId.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200229103848_AddPostLocalId")] diff --git a/Timeline/Migrations/20200229103848_AddPostLocalId.cs b/Timeline/Migrations/20200229103848_AddPostLocalId.cs index 029498ba..497b38a1 100644 --- a/Timeline/Migrations/20200229103848_AddPostLocalId.cs +++ b/Timeline/Migrations/20200229103848_AddPostLocalId.cs @@ -1,7 +1,7 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public partial class AddPostLocalId : Migration { diff --git a/Timeline/Migrations/20200306110049_AddDataTable.Designer.cs b/Timeline/Migrations/20200306110049_AddDataTable.Designer.cs index e7fdd35a..336ffc18 100644 --- a/Timeline/Migrations/20200306110049_AddDataTable.Designer.cs +++ b/Timeline/Migrations/20200306110049_AddDataTable.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200306110049_AddDataTable")] diff --git a/Timeline/Migrations/20200306110049_AddDataTable.cs b/Timeline/Migrations/20200306110049_AddDataTable.cs index 81a1b67f..e33bf4c9 100644 --- a/Timeline/Migrations/20200306110049_AddDataTable.cs +++ b/Timeline/Migrations/20200306110049_AddDataTable.cs @@ -1,7 +1,7 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public partial class AddDataTable : Migration { diff --git a/Timeline/Migrations/20200306111553_DropUserDetails.Designer.cs b/Timeline/Migrations/20200306111553_DropUserDetails.Designer.cs index 775665ac..f0c4dc08 100644 --- a/Timeline/Migrations/20200306111553_DropUserDetails.Designer.cs +++ b/Timeline/Migrations/20200306111553_DropUserDetails.Designer.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] [Migration("20200306111553_DropUserDetails")] diff --git a/Timeline/Migrations/20200306111553_DropUserDetails.cs b/Timeline/Migrations/20200306111553_DropUserDetails.cs index d5d74cce..0a176461 100644 --- a/Timeline/Migrations/20200306111553_DropUserDetails.cs +++ b/Timeline/Migrations/20200306111553_DropUserDetails.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { public partial class DropUserDetails : Migration { diff --git a/Timeline/Migrations/DatabaseContextModelSnapshot.cs b/Timeline/Migrations/DatabaseContextModelSnapshot.cs index 50094f3e..8170b2f0 100644 --- a/Timeline/Migrations/DatabaseContextModelSnapshot.cs +++ b/Timeline/Migrations/DatabaseContextModelSnapshot.cs @@ -3,9 +3,9 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Migrations +namespace Timeline.Migrations { [DbContext(typeof(DatabaseContext))] partial class DatabaseContextModelSnapshot : ModelSnapshot diff --git a/Timeline/Models/Converters/JsonDateTimeConverter.cs b/Timeline/Models/Converters/JsonDateTimeConverter.cs index 057186de..ef129a01 100644 --- a/Timeline/Models/Converters/JsonDateTimeConverter.cs +++ b/Timeline/Models/Converters/JsonDateTimeConverter.cs @@ -4,7 +4,7 @@ using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; -namespace TimelineApp.Models.Converters +namespace Timeline.Models.Converters { public class JsonDateTimeConverter : JsonConverter { diff --git a/Timeline/Models/Http/Common.cs b/Timeline/Models/Http/Common.cs index f30fdb0d..a9fc8a79 100644 --- a/Timeline/Models/Http/Common.cs +++ b/Timeline/Models/Http/Common.cs @@ -1,6 +1,6 @@ -using static TimelineApp.Resources.Models.Http.Common; +using static Timeline.Resources.Models.Http.Common; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class CommonResponse { diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index d6cb5ca0..9f7e70e1 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -1,7 +1,7 @@  -using static TimelineApp.Resources.Messages; +using static Timeline.Resources.Messages; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public static class ErrorResponse diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 637a775d..55c3a3bf 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -4,9 +4,9 @@ using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Routing; using System; using System.Collections.Generic; -using TimelineApp.Controllers; +using Timeline.Controllers; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class TimelinePostContentInfo { diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs index b389c549..ce5f3b98 100644 --- a/Timeline/Models/Http/TimelineController.cs +++ b/Timeline/Models/Http/TimelineController.cs @@ -1,8 +1,8 @@ using System; using System.ComponentModel.DataAnnotations; -using TimelineApp.Models.Validation; +using Timeline.Models.Validation; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class TimelinePostCreateRequestContent { diff --git a/Timeline/Models/Http/TokenController.cs b/Timeline/Models/Http/TokenController.cs index 3376fb61..ea8b59ed 100644 --- a/Timeline/Models/Http/TokenController.cs +++ b/Timeline/Models/Http/TokenController.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class CreateTokenRequest { diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs index c024c757..e4c95cbd 100644 --- a/Timeline/Models/Http/UserController.cs +++ b/Timeline/Models/Http/UserController.cs @@ -1,9 +1,9 @@ using AutoMapper; using System.ComponentModel.DataAnnotations; -using TimelineApp.Models.Validation; -using TimelineApp.Services; +using Timeline.Models.Validation; +using Timeline.Services; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class UserPatchRequest { diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs index fcbbe7c9..4f887549 100644 --- a/Timeline/Models/Http/UserInfo.cs +++ b/Timeline/Models/Http/UserInfo.cs @@ -3,9 +3,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Routing; using System; -using TimelineApp.Controllers; +using Timeline.Controllers; -namespace TimelineApp.Models.Http +namespace Timeline.Models.Http { public class UserInfo { diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs index 52f38e42..e2ff525e 100644 --- a/Timeline/Models/Timeline.cs +++ b/Timeline/Models/Timeline.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace TimelineApp.Models +namespace Timeline.Models { public enum TimelineVisibility { diff --git a/Timeline/Models/User.cs b/Timeline/Models/User.cs index 3b88a1b3..37777eba 100644 --- a/Timeline/Models/User.cs +++ b/Timeline/Models/User.cs @@ -1,4 +1,4 @@ -namespace TimelineApp.Models +namespace Timeline.Models { public class User { diff --git a/Timeline/Models/Validation/NameValidator.cs b/Timeline/Models/Validation/NameValidator.cs index cf276309..dec2b872 100644 --- a/Timeline/Models/Validation/NameValidator.cs +++ b/Timeline/Models/Validation/NameValidator.cs @@ -1,7 +1,7 @@ using System.Linq; -using static TimelineApp.Resources.Models.Validation.NameValidator; +using static Timeline.Resources.Models.Validation.NameValidator; -namespace TimelineApp.Models.Validation +namespace Timeline.Models.Validation { public class NameValidator : Validator { diff --git a/Timeline/Models/Validation/NicknameValidator.cs b/Timeline/Models/Validation/NicknameValidator.cs index cef80b9f..1d6ab163 100644 --- a/Timeline/Models/Validation/NicknameValidator.cs +++ b/Timeline/Models/Validation/NicknameValidator.cs @@ -1,7 +1,7 @@ using System; -using static TimelineApp.Resources.Models.Validation.NicknameValidator; +using static Timeline.Resources.Models.Validation.NicknameValidator; -namespace TimelineApp.Models.Validation +namespace Timeline.Models.Validation { public class NicknameValidator : Validator { diff --git a/Timeline/Models/Validation/TimelineNameValidator.cs b/Timeline/Models/Validation/TimelineNameValidator.cs index 68110466..f1ab54e8 100644 --- a/Timeline/Models/Validation/TimelineNameValidator.cs +++ b/Timeline/Models/Validation/TimelineNameValidator.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Models.Validation +namespace Timeline.Models.Validation { public class TimelineNameValidator : NameValidator { diff --git a/Timeline/Models/Validation/UsernameValidator.cs b/Timeline/Models/Validation/UsernameValidator.cs index bc0a9fe4..87bbf85f 100644 --- a/Timeline/Models/Validation/UsernameValidator.cs +++ b/Timeline/Models/Validation/UsernameValidator.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Models.Validation +namespace Timeline.Models.Validation { public class UsernameValidator : NameValidator { diff --git a/Timeline/Models/Validation/Validator.cs b/Timeline/Models/Validation/Validator.cs index 2c61705e..ead7dbef 100644 --- a/Timeline/Models/Validation/Validator.cs +++ b/Timeline/Models/Validation/Validator.cs @@ -2,10 +2,10 @@ using Microsoft.Extensions.Localization; using System; using System.ComponentModel.DataAnnotations; -using TimelineApp.Helpers; -using static TimelineApp.Resources.Models.Validation.Validator; +using Timeline.Helpers; +using static Timeline.Resources.Models.Validation.Validator; -namespace TimelineApp.Models.Validation +namespace Timeline.Models.Validation { /// /// A validator to validate value. diff --git a/Timeline/Program.cs b/Timeline/Program.cs index 70c67d87..c49f74b0 100644 --- a/Timeline/Program.cs +++ b/Timeline/Program.cs @@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Resources; -using TimelineApp.Entities; +using Timeline.Entities; [assembly: NeutralResourcesLanguage("en")] -namespace TimelineApp +namespace Timeline { public static class Program { diff --git a/Timeline/Resources/Authentication/AuthHandler.Designer.cs b/Timeline/Resources/Authentication/AuthHandler.Designer.cs index 6005e2cd..fd4540ea 100644 --- a/Timeline/Resources/Authentication/AuthHandler.Designer.cs +++ b/Timeline/Resources/Authentication/AuthHandler.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Authentication { +namespace Timeline.Resources.Authentication { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Authentication { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Authentication.AuthHandler", typeof(AuthHandler).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Authentication.AuthHandler", typeof(AuthHandler).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs b/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs index 019699d9..70a1d605 100644 --- a/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs +++ b/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Controllers { +namespace Timeline.Resources.Controllers { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Controllers { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Controllers.ControllerAuthExtensions", typeof(ControllerAuthExtensions).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.ControllerAuthExtensions", typeof(ControllerAuthExtensions).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Controllers/TimelineController.Designer.cs b/Timeline/Resources/Controllers/TimelineController.Designer.cs index 0560dd08..ae6414e6 100644 --- a/Timeline/Resources/Controllers/TimelineController.Designer.cs +++ b/Timeline/Resources/Controllers/TimelineController.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Controllers { +namespace Timeline.Resources.Controllers { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Controllers { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Controllers.TimelineController", typeof(TimelineController).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.TimelineController", typeof(TimelineController).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Controllers/TokenController.Designer.cs b/Timeline/Resources/Controllers/TokenController.Designer.cs index a4ea9657..a7c2864b 100644 --- a/Timeline/Resources/Controllers/TokenController.Designer.cs +++ b/Timeline/Resources/Controllers/TokenController.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Controllers { +namespace Timeline.Resources.Controllers { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Controllers { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Controllers.TokenController", typeof(TokenController).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.TokenController", typeof(TokenController).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Controllers/UserAvatarController.Designer.cs b/Timeline/Resources/Controllers/UserAvatarController.Designer.cs index 0165c4f0..e6eeb1e8 100644 --- a/Timeline/Resources/Controllers/UserAvatarController.Designer.cs +++ b/Timeline/Resources/Controllers/UserAvatarController.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Controllers { +namespace Timeline.Resources.Controllers { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Controllers { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Controllers.UserAvatarController", typeof(UserAvatarController).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.UserAvatarController", typeof(UserAvatarController).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Controllers/UserController.Designer.cs b/Timeline/Resources/Controllers/UserController.Designer.cs index 277b85e0..c8067614 100644 --- a/Timeline/Resources/Controllers/UserController.Designer.cs +++ b/Timeline/Resources/Controllers/UserController.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Controllers { +namespace Timeline.Resources.Controllers { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Controllers { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Controllers.UserController", typeof(UserController).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.UserController", typeof(UserController).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Filters.Designer.cs b/Timeline/Resources/Filters.Designer.cs index 3e29398d..dedfe498 100644 --- a/Timeline/Resources/Filters.Designer.cs +++ b/Timeline/Resources/Filters.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources { +namespace Timeline.Resources { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Filters", typeof(Filters).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Filters", typeof(Filters).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index d85f5399..4123cb8b 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources { +namespace Timeline.Resources { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Messages", typeof(Messages).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Messages", typeof(Messages).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Models/Http/Common.Designer.cs b/Timeline/Resources/Models/Http/Common.Designer.cs index fbbdeeca..5165463e 100644 --- a/Timeline/Resources/Models/Http/Common.Designer.cs +++ b/Timeline/Resources/Models/Http/Common.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Models.Http { +namespace Timeline.Resources.Models.Http { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Models.Http { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Models.Http.Common", typeof(Common).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Http.Common", typeof(Common).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Models/Validation/NameValidator.Designer.cs b/Timeline/Resources/Models/Validation/NameValidator.Designer.cs index af8ceeb7..5b869226 100644 --- a/Timeline/Resources/Models/Validation/NameValidator.Designer.cs +++ b/Timeline/Resources/Models/Validation/NameValidator.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Models.Validation { +namespace Timeline.Resources.Models.Validation { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Models.Validation { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Models.Validation.NameValidator", typeof(NameValidator).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Validation.NameValidator", typeof(NameValidator).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Models/Validation/NicknameValidator.Designer.cs b/Timeline/Resources/Models/Validation/NicknameValidator.Designer.cs index 04d616b8..522f305a 100644 --- a/Timeline/Resources/Models/Validation/NicknameValidator.Designer.cs +++ b/Timeline/Resources/Models/Validation/NicknameValidator.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Models.Validation { +namespace Timeline.Resources.Models.Validation { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Models.Validation { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Models.Validation.NicknameValidator", typeof(NicknameValidator).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Validation.NicknameValidator", typeof(NicknameValidator).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Models/Validation/Validator.Designer.cs b/Timeline/Resources/Models/Validation/Validator.Designer.cs index 442c874b..74d4c169 100644 --- a/Timeline/Resources/Models/Validation/Validator.Designer.cs +++ b/Timeline/Resources/Models/Validation/Validator.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Models.Validation { +namespace Timeline.Resources.Models.Validation { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Models.Validation { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Models.Validation.Validator", typeof(Validator).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Validation.Validator", typeof(Validator).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/DataManager.Designer.cs b/Timeline/Resources/Services/DataManager.Designer.cs index e5d5539a..0872059a 100644 --- a/Timeline/Resources/Services/DataManager.Designer.cs +++ b/Timeline/Resources/Services/DataManager.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.DataManager", typeof(DataManager).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.DataManager", typeof(DataManager).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/Exception.Designer.cs b/Timeline/Resources/Services/Exception.Designer.cs index 2fd350f9..0c721d92 100644 --- a/Timeline/Resources/Services/Exception.Designer.cs +++ b/Timeline/Resources/Services/Exception.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.Exception", typeof(Exception).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.Exception", typeof(Exception).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/TimelineService.Designer.cs b/Timeline/Resources/Services/TimelineService.Designer.cs index 65f98577..4c3de1cd 100644 --- a/Timeline/Resources/Services/TimelineService.Designer.cs +++ b/Timeline/Resources/Services/TimelineService.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.TimelineService", typeof(TimelineService).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.TimelineService", typeof(TimelineService).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/UserAvatarService.Designer.cs b/Timeline/Resources/Services/UserAvatarService.Designer.cs index 1bed55f3..c72d4215 100644 --- a/Timeline/Resources/Services/UserAvatarService.Designer.cs +++ b/Timeline/Resources/Services/UserAvatarService.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.UserAvatarService", typeof(UserAvatarService).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserAvatarService", typeof(UserAvatarService).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/UserService.Designer.cs b/Timeline/Resources/Services/UserService.Designer.cs index 73cd7bcd..cdf7f390 100644 --- a/Timeline/Resources/Services/UserService.Designer.cs +++ b/Timeline/Resources/Services/UserService.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.UserService", typeof(UserService).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserService", typeof(UserService).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Resources/Services/UserTokenService.Designer.cs b/Timeline/Resources/Services/UserTokenService.Designer.cs index 6cdca6a9..3c3c7e41 100644 --- a/Timeline/Resources/Services/UserTokenService.Designer.cs +++ b/Timeline/Resources/Services/UserTokenService.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace TimelineApp.Resources.Services { +namespace Timeline.Resources.Services { using System; @@ -39,7 +39,7 @@ namespace TimelineApp.Resources.Services { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimelineApp.Resources.Services.UserTokenService", typeof(UserTokenService).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserTokenService", typeof(UserTokenService).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Timeline/Services/BadPasswordException.cs b/Timeline/Services/BadPasswordException.cs index 93251055..f609371d 100644 --- a/Timeline/Services/BadPasswordException.cs +++ b/Timeline/Services/BadPasswordException.cs @@ -1,7 +1,7 @@ using System; -using TimelineApp.Helpers; +using Timeline.Helpers; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class BadPasswordException : Exception diff --git a/Timeline/Services/Clock.cs b/Timeline/Services/Clock.cs index 68441e92..0499c0c6 100644 --- a/Timeline/Services/Clock.cs +++ b/Timeline/Services/Clock.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace TimelineApp.Services +namespace Timeline.Services { /// /// Convenient for unit test. diff --git a/Timeline/Services/ConflictException.cs b/Timeline/Services/ConflictException.cs index be9ec2c0..6ede183a 100644 --- a/Timeline/Services/ConflictException.cs +++ b/Timeline/Services/ConflictException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { /// /// Thrown when a resource already exists and conflicts with the given resource. diff --git a/Timeline/Services/DataManager.cs b/Timeline/Services/DataManager.cs index a4241c1b..d447b0d5 100644 --- a/Timeline/Services/DataManager.cs +++ b/Timeline/Services/DataManager.cs @@ -2,9 +2,9 @@ using System; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Services +namespace Timeline.Services { /// /// A data manager controlling data. diff --git a/Timeline/Services/DatabaseCorruptedException.cs b/Timeline/Services/DatabaseCorruptedException.cs index f5bd0c85..9988e0ad 100644 --- a/Timeline/Services/DatabaseCorruptedException.cs +++ b/Timeline/Services/DatabaseCorruptedException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class DatabaseCorruptedException : Exception diff --git a/Timeline/Services/ETagGenerator.cs b/Timeline/Services/ETagGenerator.cs index b7efd037..d328ea20 100644 --- a/Timeline/Services/ETagGenerator.cs +++ b/Timeline/Services/ETagGenerator.cs @@ -2,7 +2,7 @@ using System.Security.Cryptography; using System.Threading.Tasks; -namespace TimelineApp.Services +namespace Timeline.Services { public interface IETagGenerator { diff --git a/Timeline/Services/ImageException.cs b/Timeline/Services/ImageException.cs index f3f3b010..c6126aa3 100644 --- a/Timeline/Services/ImageException.cs +++ b/Timeline/Services/ImageException.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class ImageException : Exception diff --git a/Timeline/Services/ImageValidator.cs b/Timeline/Services/ImageValidator.cs index f10bb4d0..c331d912 100644 --- a/Timeline/Services/ImageValidator.cs +++ b/Timeline/Services/ImageValidator.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using System.Threading.Tasks; -namespace TimelineApp.Services +namespace Timeline.Services { public interface IImageValidator { diff --git a/Timeline/Services/JwtUserTokenBadFormatException.cs b/Timeline/Services/JwtUserTokenBadFormatException.cs index 81450486..c528c3e3 100644 --- a/Timeline/Services/JwtUserTokenBadFormatException.cs +++ b/Timeline/Services/JwtUserTokenBadFormatException.cs @@ -1,8 +1,8 @@ using System; using System.Globalization; -using static TimelineApp.Resources.Services.Exception; +using static Timeline.Resources.Services.Exception; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class JwtUserTokenBadFormatException : UserTokenBadFormatException diff --git a/Timeline/Services/PasswordBadFormatException.cs b/Timeline/Services/PasswordBadFormatException.cs index 4db52092..2029ebb4 100644 --- a/Timeline/Services/PasswordBadFormatException.cs +++ b/Timeline/Services/PasswordBadFormatException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] diff --git a/Timeline/Services/PasswordService.cs b/Timeline/Services/PasswordService.cs index b08fe14d..e04a861b 100644 --- a/Timeline/Services/PasswordService.cs +++ b/Timeline/Services/PasswordService.cs @@ -3,7 +3,7 @@ using System; using System.Runtime.CompilerServices; using System.Security.Cryptography; -namespace TimelineApp.Services +namespace Timeline.Services { /// /// Hashed password is of bad format. diff --git a/Timeline/Services/PathProvider.cs b/Timeline/Services/PathProvider.cs index 79f309a1..15e66972 100644 --- a/Timeline/Services/PathProvider.cs +++ b/Timeline/Services/PathProvider.cs @@ -5,7 +5,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -namespace TimelineApp.Services +namespace Timeline.Services { public interface IPathProvider { diff --git a/Timeline/Services/TimelineNotExistException.cs b/Timeline/Services/TimelineNotExistException.cs index b5bb0580..6dfd0bab 100644 --- a/Timeline/Services/TimelineNotExistException.cs +++ b/Timeline/Services/TimelineNotExistException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class TimelineNotExistException : Exception diff --git a/Timeline/Services/TimelinePostNotExistException.cs b/Timeline/Services/TimelinePostNotExistException.cs index 488bfe2b..c542e63e 100644 --- a/Timeline/Services/TimelinePostNotExistException.cs +++ b/Timeline/Services/TimelinePostNotExistException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] public class TimelinePostNotExistException : Exception diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 8c1e62d4..1bccb855 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -6,12 +6,12 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Entities; -using TimelineApp.Models; -using TimelineApp.Models.Validation; -using static TimelineApp.Resources.Services.TimelineService; +using Timeline.Entities; +using Timeline.Models; +using Timeline.Models.Validation; +using static Timeline.Resources.Services.TimelineService; -namespace TimelineApp.Services +namespace Timeline.Services { public enum TimelineUserRelationshipType { @@ -67,7 +67,7 @@ namespace TimelineApp.Services /// Thrown when is null. /// See remarks of . /// See remarks of . - Task GetTimeline(string name); + Task GetTimeline(string name); /// /// Set the properties of a timeline. @@ -252,7 +252,7 @@ namespace TimelineApp.Services /// /// If user with related user id does not exist, empty list will be returned. /// - Task> GetTimelines(TimelineUserRelationship? relate = null, List? visibility = null); + Task> GetTimelines(TimelineUserRelationship? relate = null, List? visibility = null); /// /// Create a timeline. @@ -264,7 +264,7 @@ namespace TimelineApp.Services /// Thrown when timeline name is invalid. /// Thrown when the timeline already exists. /// Thrown when the owner user does not exist. - Task CreateTimeline(string name, long owner); + Task CreateTimeline(string name, long owner); /// /// Delete a timeline. @@ -334,7 +334,7 @@ namespace TimelineApp.Services /// protected abstract Task FindTimelineId(string name); - public async Task GetTimeline(string name) + public async Task GetTimeline(string name) { if (name == null) throw new ArgumentNullException(nameof(name)); @@ -353,7 +353,7 @@ namespace TimelineApp.Services members.Add(await UserService.GetUserById(memberEntity.UserId)); } - return new Timeline + return new Models.Timeline { Name = timelineEntity.Name ?? ("@" + owner.Username), Description = timelineEntity.Description ?? "", @@ -849,7 +849,7 @@ namespace TimelineApp.Services } } - public async Task> GetTimelines(TimelineUserRelationship? relate = null, List? visibility = null) + public async Task> GetTimelines(TimelineUserRelationship? relate = null, List? visibility = null) { List entities; @@ -883,12 +883,12 @@ namespace TimelineApp.Services } } - var result = new List(); + var result = new List(); foreach (var entity in entities) { var owner = await _userService.GetUserById(entity.OwnerId); - var timeline = new Timeline + var timeline = new Models.Timeline { Name = entity.Name ?? ("@" + owner.Username), Description = entity.Description ?? "", @@ -908,7 +908,7 @@ namespace TimelineApp.Services return result; } - public async Task CreateTimeline(string name, long owner) + public async Task CreateTimeline(string name, long owner) { if (name == null) throw new ArgumentNullException(nameof(name)); @@ -934,7 +934,7 @@ namespace TimelineApp.Services _database.Timelines.Add(newEntity); await _database.SaveChangesAsync(); - return new Timeline + return new Models.Timeline { Name = name, Description = "", @@ -978,7 +978,7 @@ namespace TimelineApp.Services } } - public Task GetTimeline(string name) + public Task GetTimeline(string name) { var s = BranchName(name, out var realName); return s.GetTimeline(realName); diff --git a/Timeline/Services/UserAvatarService.cs b/Timeline/Services/UserAvatarService.cs index 5f2ce4ed..1b1be698 100644 --- a/Timeline/Services/UserAvatarService.cs +++ b/Timeline/Services/UserAvatarService.cs @@ -6,10 +6,10 @@ using System; using System.IO; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Entities; -using TimelineApp.Helpers; +using Timeline.Entities; +using Timeline.Helpers; -namespace TimelineApp.Services +namespace Timeline.Services { public class Avatar { diff --git a/Timeline/Services/UserNotExistException.cs b/Timeline/Services/UserNotExistException.cs index b51378ed..fd0b5ecf 100644 --- a/Timeline/Services/UserNotExistException.cs +++ b/Timeline/Services/UserNotExistException.cs @@ -1,7 +1,7 @@ using System; -using TimelineApp.Helpers; +using Timeline.Helpers; -namespace TimelineApp.Services +namespace Timeline.Services { /// /// The user requested does not exist. diff --git a/Timeline/Services/UserRoleConvert.cs b/Timeline/Services/UserRoleConvert.cs index 78c52ae3..f27ee1bb 100644 --- a/Timeline/Services/UserRoleConvert.cs +++ b/Timeline/Services/UserRoleConvert.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using TimelineApp.Entities; +using Timeline.Entities; -namespace TimelineApp.Services +namespace Timeline.Services { public static class UserRoleConvert { diff --git a/Timeline/Services/UserService.cs b/Timeline/Services/UserService.cs index 3279d2bd..e0a5ab50 100644 --- a/Timeline/Services/UserService.cs +++ b/Timeline/Services/UserService.cs @@ -4,13 +4,13 @@ using System; using System.Globalization; using System.Linq; using System.Threading.Tasks; -using TimelineApp.Entities; -using TimelineApp.Helpers; -using TimelineApp.Models; -using TimelineApp.Models.Validation; -using static TimelineApp.Resources.Services.UserService; +using Timeline.Entities; +using Timeline.Helpers; +using Timeline.Models; +using Timeline.Models.Validation; +using static Timeline.Resources.Services.UserService; -namespace TimelineApp.Services +namespace Timeline.Services { public interface IUserService { diff --git a/Timeline/Services/UserTokenException.cs b/Timeline/Services/UserTokenException.cs index 99d26dec..ed0bae1a 100644 --- a/Timeline/Services/UserTokenException.cs +++ b/Timeline/Services/UserTokenException.cs @@ -1,6 +1,6 @@ using System; -namespace TimelineApp.Services +namespace Timeline.Services { [Serializable] diff --git a/Timeline/Services/UserTokenManager.cs b/Timeline/Services/UserTokenManager.cs index 4a044353..6decf8f9 100644 --- a/Timeline/Services/UserTokenManager.cs +++ b/Timeline/Services/UserTokenManager.cs @@ -1,9 +1,9 @@ using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; -using TimelineApp.Models; +using Timeline.Models; -namespace TimelineApp.Services +namespace Timeline.Services { public class UserTokenCreateResult { diff --git a/Timeline/Services/UserTokenService.cs b/Timeline/Services/UserTokenService.cs index 76501ce3..86f3a0f7 100644 --- a/Timeline/Services/UserTokenService.cs +++ b/Timeline/Services/UserTokenService.cs @@ -5,10 +5,10 @@ using System.Globalization; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Security.Claims; -using TimelineApp.Configs; -using TimelineApp.Entities; +using Timeline.Configs; +using Timeline.Entities; -namespace TimelineApp.Services +namespace Timeline.Services { public class UserTokenInfo { diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index d34bee25..85822a14 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -10,15 +10,15 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using System; using System.Text.Json.Serialization; -using TimelineApp.Auth; -using TimelineApp.Configs; -using TimelineApp.Entities; -using TimelineApp.Formatters; -using TimelineApp.Helpers; -using TimelineApp.Models.Converters; -using TimelineApp.Services; - -namespace TimelineApp +using Timeline.Auth; +using Timeline.Configs; +using Timeline.Entities; +using Timeline.Formatters; +using Timeline.Helpers; +using Timeline.Models.Converters; +using Timeline.Services; + +namespace Timeline { [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")] public class Startup diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj new file mode 100644 index 00000000..c9da9a2e --- /dev/null +++ b/Timeline/Timeline.csproj @@ -0,0 +1,207 @@ + + + netcoreapp3.1 + 1f6fb74d-4277-4bc0-aeea-b1fc5ffb0b43 + crupest + + 8.0 + enable + + + + + PreserveNewest + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + True + True + AuthHandler.resx + + + True + True + ControllerAuthExtensions.resx + + + True + True + TimelineController.resx + + + True + True + TokenController.resx + + + True + True + UserAvatarController.resx + + + True + True + UserController.resx + + + True + True + Filters.resx + + + True + True + Messages.resx + + + True + True + Common.resx + + + True + True + NicknameValidator.resx + + + True + True + NameValidator.resx + + + True + True + Validator.resx + + + True + True + DataManager.resx + + + True + True + Exception.resx + + + True + True + TimelineService.resx + + + True + True + UserAvatarService.resx + + + True + True + UserService.resx + + + True + True + UserTokenService.resx + + + + + + ResXFileCodeGenerator + AuthHandler.Designer.cs + + + ResXFileCodeGenerator + ControllerAuthExtensions.Designer.cs + + + ResXFileCodeGenerator + TimelineController.Designer.cs + + + Designer + ResXFileCodeGenerator + TokenController.Designer.cs + + + ResXFileCodeGenerator + UserAvatarController.Designer.cs + + + ResXFileCodeGenerator + UserController.Designer.cs + + + ResXFileCodeGenerator + Filters.Designer.cs + + + ResXFileCodeGenerator + Messages.Designer.cs + + + ResXFileCodeGenerator + Common.Designer.cs + + + ResXFileCodeGenerator + NicknameValidator.Designer.cs + + + ResXFileCodeGenerator + NameValidator.Designer.cs + + + ResXFileCodeGenerator + Validator.Designer.cs + + + ResXFileCodeGenerator + DataManager.Designer.cs + + + ResXFileCodeGenerator + Exception.Designer.cs + + + ResXFileCodeGenerator + TimelineService.Designer.cs + + + ResXFileCodeGenerator + UserAvatarService.Designer.cs + + + ResXFileCodeGenerator + UserService.Designer.cs + + + ResXFileCodeGenerator + UserTokenService.Designer.cs + + + diff --git a/Timeline/TimelineApp.csproj b/Timeline/TimelineApp.csproj deleted file mode 100644 index 6fb88ae9..00000000 --- a/Timeline/TimelineApp.csproj +++ /dev/null @@ -1,211 +0,0 @@ - - - netcoreapp3.1 - 1f6fb74d-4277-4bc0-aeea-b1fc5ffb0b43 - crupest - - 8.0 - enable - - - - - - - - - PreserveNewest - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - True - True - AuthHandler.resx - - - True - True - ControllerAuthExtensions.resx - - - True - True - TimelineController.resx - - - True - True - TokenController.resx - - - True - True - UserAvatarController.resx - - - True - True - UserController.resx - - - True - True - Filters.resx - - - True - True - Messages.resx - - - True - True - Common.resx - - - True - True - NicknameValidator.resx - - - True - True - NameValidator.resx - - - True - True - Validator.resx - - - True - True - DataManager.resx - - - True - True - Exception.resx - - - True - True - TimelineService.resx - - - True - True - UserAvatarService.resx - - - True - True - UserService.resx - - - True - True - UserTokenService.resx - - - - - - ResXFileCodeGenerator - AuthHandler.Designer.cs - - - ResXFileCodeGenerator - ControllerAuthExtensions.Designer.cs - - - ResXFileCodeGenerator - TimelineController.Designer.cs - - - Designer - ResXFileCodeGenerator - TokenController.Designer.cs - - - ResXFileCodeGenerator - UserAvatarController.Designer.cs - - - ResXFileCodeGenerator - UserController.Designer.cs - - - ResXFileCodeGenerator - Filters.Designer.cs - - - ResXFileCodeGenerator - Messages.Designer.cs - - - ResXFileCodeGenerator - Common.Designer.cs - - - ResXFileCodeGenerator - NicknameValidator.Designer.cs - - - ResXFileCodeGenerator - NameValidator.Designer.cs - - - ResXFileCodeGenerator - Validator.Designer.cs - - - ResXFileCodeGenerator - DataManager.Designer.cs - - - ResXFileCodeGenerator - Exception.Designer.cs - - - ResXFileCodeGenerator - TimelineService.Designer.cs - - - ResXFileCodeGenerator - UserAvatarService.Designer.cs - - - ResXFileCodeGenerator - UserService.Designer.cs - - - ResXFileCodeGenerator - UserTokenService.Designer.cs - - - -- cgit v1.2.3 From 5eaacedda31da86116f25158bd07e5ad8954e7b2 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Mar 2020 19:37:58 +0800 Subject: ... --- .../IntegratedTests/IntegratedTestBase.cs | 29 ++-- .../IntegratedTests/PersonalTimelineTest.cs | 153 +++++++++++---------- Timeline.Tests/IntegratedTests/TimelineTest.cs | 72 ++++++---- Timeline.Tests/IntegratedTests/TokenTest.cs | 1 + Timeline/Controllers/TimelineController.cs | 14 ++ Timeline/Controllers/UserController.cs | 1 + Timeline/Entities/TimelineEntity.cs | 2 +- Timeline/Models/Http/Timeline.cs | 24 ++-- Timeline/Models/Http/UserInfo.cs | 2 +- Timeline/Models/Timeline.cs | 17 ++- Timeline/Services/TimelineService.cs | 79 ++++++----- Timeline/Startup.cs | 3 +- 12 files changed, 242 insertions(+), 155 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs index dfde2ea5..66904629 100644 --- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs +++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs @@ -1,10 +1,13 @@ -using AutoMapper; -using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Net.Http; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; +using Timeline.Models; +using Timeline.Models.Converters; using Timeline.Models.Http; using Timeline.Services; using Timeline.Tests.Helpers; @@ -14,12 +17,6 @@ namespace Timeline.Tests.IntegratedTests { public abstract class IntegratedTestBase : IClassFixture>, IDisposable { - static IntegratedTestBase() - { - FluentAssertions.AssertionOptions.AssertEquivalencyUsing(options => - options.Excluding(m => m.RuntimeType == typeof(UserInfoLinks))); - } - protected TestApplication TestApp { get; } protected WebApplicationFactory Factory => TestApp.Factory; @@ -63,12 +60,22 @@ namespace Timeline.Tests.IntegratedTests var userInfoList = new List(); var userService = scope.ServiceProvider.GetRequiredService(); - var mapper = scope.ServiceProvider.GetRequiredService(); - foreach (var user in users) { userService.CreateUser(user).Wait(); - userInfoList.Add(mapper.Map(user)); + } + + using var client = CreateDefaultClient().Result; + var options = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + options.Converters.Add(new JsonStringEnumConverter()); + options.Converters.Add(new JsonDateTimeConverter()); + foreach (var user in users) + { + var s = client.GetStringAsync($"/users/{user.Username}").Result; + userInfoList.Add(JsonSerializer.Deserialize(s, options)); } UserInfos = userInfoList; diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs index 7d0a68e8..aa37e898 100644 --- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; +using Timeline.Models; using Timeline.Models.Http; using Timeline.Tests.Helpers; using Xunit; @@ -23,7 +24,7 @@ namespace Timeline.Tests.IntegratedTests public async Task TimelineGet_Should_Work() { using var client = await CreateDefaultClient(); - var res = await client.GetAsync("users/user1/timeline"); + var res = await client.GetAsync("timelines/@user1"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; body.Owner.Should().BeEquivalentTo(UserInfos[1]); @@ -37,31 +38,31 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var res = await client.GetAsync("users/user!!!/timeline"); + var res = await client.GetAsync("timelines/@user!!!"); res.Should().BeInvalidModel(); } { - var res = await client.PatchAsJsonAsync("users/user!!!/timeline", new TimelinePatchRequest { }); + var res = await client.PatchAsJsonAsync("timelines/@user!!!", new TimelinePatchRequest { }); res.Should().BeInvalidModel(); } { - var res = await client.PutAsync("users/user!!!/timeline/members/user1", null); + var res = await client.PutAsync("timelines/@user!!!/members/user1", null); res.Should().BeInvalidModel(); } { - var res = await client.DeleteAsync("users/user!!!/timeline/members/user1"); + var res = await client.DeleteAsync("timelines/@user!!!/members/user1"); res.Should().BeInvalidModel(); } { - var res = await client.GetAsync("users/user!!!/timeline/posts"); + var res = await client.GetAsync("timelines/@user!!!/posts"); res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("users/user!!!/timeline/posts", new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@user!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); res.Should().BeInvalidModel(); } { - var res = await client.DeleteAsync("users/user!!!/timeline/posts/123"); + var res = await client.DeleteAsync("timelines/@user!!!/posts/123"); res.Should().BeInvalidModel(); } } @@ -71,31 +72,31 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var res = await client.GetAsync("users/usernotexist/timeline"); + var res = await client.GetAsync("timelines/@usernotexist"); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.PatchAsJsonAsync("users/usernotexist/timeline", new TimelinePatchRequest { }); + var res = await client.PatchAsJsonAsync("timelines/@usernotexist", new TimelinePatchRequest { }); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.PutAsync("users/usernotexist/timeline/members/user1", null); + var res = await client.PutAsync("timelines/@usernotexist/members/user1", null); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.DeleteAsync("users/usernotexist/timeline/members/user1"); + var res = await client.DeleteAsync("timelines/@usernotexist/members/user1"); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.GetAsync("users/usernotexist/timeline/posts"); + var res = await client.GetAsync("timelines/@usernotexist/posts"); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.PostAsJsonAsync("users/usernotexist/timeline/posts", new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@usernotexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } { - var res = await client.DeleteAsync("users/usernotexist/timeline/posts/123"); + var res = await client.DeleteAsync("timelines/@usernotexist/posts/123"); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); } } @@ -107,7 +108,7 @@ namespace Timeline.Tests.IntegratedTests async Task AssertDescription(string description) { - var res = await client.GetAsync("users/user1/timeline"); + var res = await client.GetAsync("timelines/@user1"); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Description.Should().Be(description); @@ -117,21 +118,21 @@ namespace Timeline.Tests.IntegratedTests await AssertDescription(""); { - var res = await client.PatchAsJsonAsync("users/user1/timeline", + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Description = mockDescription }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); await AssertDescription(mockDescription); } { - var res = await client.PatchAsJsonAsync("users/user1/timeline", + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Description = null }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); await AssertDescription(mockDescription); } { - var res = await client.PatchAsJsonAsync("users/user1/timeline", + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Description = "" }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(""); @@ -142,7 +143,7 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task Member_Should_Work() { - const string getUrl = "users/user1/timeline"; + const string getUrl = "timelines/@user1"; using var client = await CreateClientAsUser(); async Task AssertMembers(IList members) @@ -163,23 +164,23 @@ namespace Timeline.Tests.IntegratedTests await AssertEmptyMembers(); { - var res = await client.PutAsync("/users/user1/timeline/members/usernotexist", null); + var res = await client.PutAsync("/timelines/@user1/members/usernotexist", null); res.Should().HaveStatusCode(400) .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist); } await AssertEmptyMembers(); { - var res = await client.PutAsync("/users/user1/timeline/members/user2", null); + var res = await client.PutAsync("/timelines/@user1/members/user2", null); res.Should().HaveStatusCode(200); } await AssertMembers(new List { UserInfos[2] }); { - var res = await client.DeleteAsync("/users/user1/timeline/members/user2"); + var res = await client.DeleteAsync("/timelines/@user1/members/user2"); res.Should().BeDelete(true); } await AssertEmptyMembers(); { - var res = await client.DeleteAsync("/users/user1/timeline/members/users2"); + var res = await client.DeleteAsync("/timelines/@user1/members/users2"); res.Should().BeDelete(false); } await AssertEmptyMembers(); @@ -193,37 +194,37 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAs(userNumber); { - var res = await client.GetAsync("users/user1/timeline"); + var res = await client.GetAsync("timelines/@user1"); res.Should().HaveStatusCode(get); } { - var res = await client.PatchAsJsonAsync("users/user1/timeline", new TimelinePatchRequest { Description = "hahaha" }); + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Description = "hahaha" }); res.Should().HaveStatusCode(opPatchUser); } { - var res = await client.PatchAsJsonAsync("users/admin/timeline", new TimelinePatchRequest { Description = "hahaha" }); + var res = await client.PatchAsJsonAsync("timelines/@admin", new TimelinePatchRequest { Description = "hahaha" }); res.Should().HaveStatusCode(opPatchAdmin); } { - var res = await client.PutAsync("users/user1/timeline/members/user2", null); + var res = await client.PutAsync("timelines/@user1/members/user2", null); res.Should().HaveStatusCode(opMemberUser); } { - var res = await client.DeleteAsync("users/user1/timeline/members/user2"); + var res = await client.DeleteAsync("timelines/@user1/members/user2"); res.Should().HaveStatusCode(opMemberUser); } { - var res = await client.PutAsync("users/admin/timeline/members/user2", null); + var res = await client.PutAsync("timelines/@admin/members/user2", null); res.Should().HaveStatusCode(opMemberAdmin); } { - var res = await client.DeleteAsync("users/admin/timeline/members/user2"); + var res = await client.DeleteAsync("timelines/@admin/members/user2"); res.Should().HaveStatusCode(opMemberAdmin); } } @@ -231,13 +232,13 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task Visibility_Test() { - const string userUrl = "users/user1/timeline/posts"; - const string adminUrl = "users/admin/timeline/posts"; + const string userUrl = "timelines/@user1/posts"; + const string adminUrl = "timelines/@admin/posts"; { using var client = await CreateClientAsUser(); using var content = new StringContent(@"{""visibility"":""abcdefg""}", System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json); - var res = await client.PatchAsync("users/user1/timeline", content); + var res = await client.PatchAsync("timelines/@user1", content); res.Should().BeInvalidModel(); } { // default visibility is registered @@ -257,7 +258,7 @@ namespace Timeline.Tests.IntegratedTests { // change visibility to public { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("users/user1/timeline", + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); res.Should().HaveStatusCode(200); } @@ -272,12 +273,12 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var res = await client.PatchAsJsonAsync("users/user1/timeline", + var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("users/admin/timeline", + var res = await client.PatchAsJsonAsync("timelines/@admin", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } @@ -299,7 +300,7 @@ namespace Timeline.Tests.IntegratedTests } { // add member using var client = await CreateClientAsAdministrator(); - var res = await client.PutAsync("/users/admin/timeline/members/user1", null); + var res = await client.PutAsync("/timelines/@admin/members/user1", null); res.Should().HaveStatusCode(200); } { // now user can read admin's @@ -316,15 +317,15 @@ namespace Timeline.Tests.IntegratedTests { using (var client = await CreateClientAsUser()) { - var res = await client.PutAsync("users/user1/timeline/members/user2", null); + var res = await client.PutAsync("timelines/@user1/members/user2", null); res.Should().HaveStatusCode(200); } using (var client = await CreateDefaultClient()) { { // no auth should get 401 - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(401); } } @@ -332,13 +333,13 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { { // post self's - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } { // post other not as a member should get 403 - var res = await client.PostAsJsonAsync("users/admin/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@admin/posts", + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(403); } } @@ -346,8 +347,8 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsAdministrator()) { { // post as admin - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } } @@ -355,8 +356,8 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAs(2)) { { // post as member - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } } @@ -368,8 +369,8 @@ namespace Timeline.Tests.IntegratedTests async Task CreatePost(int userNumber) { using var client = await CreateClientAs(userNumber); - var res = await client.PostAsJsonAsync($"users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync($"timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa")); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Id; @@ -378,53 +379,53 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { { - var res = await client.PutAsync("users/user1/timeline/members/user2", null); + var res = await client.PutAsync("timelines/@user1/members/user2", null); res.Should().HaveStatusCode(200); } { - var res = await client.PutAsync("users/user1/timeline/members/user3", null); + var res = await client.PutAsync("timelines/@user1/members/user3", null); res.Should().HaveStatusCode(200); } } { // no auth should get 401 using var client = await CreateDefaultClient(); - var res = await client.DeleteAsync("users/user1/timeline/posts/12"); + var res = await client.DeleteAsync("timelines/@user1/posts/12"); res.Should().HaveStatusCode(401); } { // self can delete self var postId = await CreatePost(1); using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"users/user1/timeline/posts/{postId}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); res.Should().HaveStatusCode(200); } { // admin can delete any var postId = await CreatePost(1); using var client = await CreateClientAsAdministrator(); - var res = await client.DeleteAsync($"users/user1/timeline/posts/{postId}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); res.Should().HaveStatusCode(200); } { // owner can delete other var postId = await CreatePost(2); using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"users/user1/timeline/posts/{postId}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); res.Should().HaveStatusCode(200); } { // author can delete self var postId = await CreatePost(2); using var client = await CreateClientAs(2); - var res = await client.DeleteAsync($"users/user1/timeline/posts/{postId}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); res.Should().HaveStatusCode(200); } { // otherwise is forbidden var postId = await CreatePost(2); using var client = await CreateClientAs(3); - var res = await client.DeleteAsync($"users/user1/timeline/posts/{postId}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); res.Should().HaveStatusCode(403); } } @@ -435,31 +436,31 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsUser(); { - var res = await client.GetAsync("users/user1/timeline/posts"); + var res = await client.GetAsync("timelines/@user1/posts"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEmpty(); } { - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = null }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest(null)); res.Should().BeInvalidModel(); } const string mockContent = "aaa"; TimelinePostInfo createRes; { - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = mockContent }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest(mockContent)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which; body.Should().NotBeNull(); - body.Content.Should().Be(mockContent); + body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent)); body.Author.Should().BeEquivalentTo(UserInfos[1]); createRes = body; } { - var res = await client.GetAsync("users/user1/timeline/posts"); + var res = await client.GetAsync("timelines/@user1/posts"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes); @@ -468,33 +469,33 @@ namespace Timeline.Tests.IntegratedTests var mockTime2 = DateTime.Now.AddDays(-1); TimelinePostInfo createRes2; { - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = mockContent2, Time = mockTime2 }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which; body.Should().NotBeNull(); - body.Content.Should().Be(mockContent2); + body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent2)); body.Author.Should().BeEquivalentTo(UserInfos[1]); body.Time.Should().BeCloseTo(mockTime2, 1000); createRes2 = body; } { - var res = await client.GetAsync("users/user1/timeline/posts"); + var res = await client.GetAsync("timelines/@user1/posts"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes, createRes2); } { - var res = await client.DeleteAsync($"users/user1/timeline/posts/{createRes.Id}"); + var res = await client.DeleteAsync($"timelines/@user1/posts/{createRes.Id}"); res.Should().BeDelete(true); } { - var res = await client.DeleteAsync("users/user1/timeline/posts/30000"); + var res = await client.DeleteAsync("timelines/@user1/posts/30000"); res.Should().BeDelete(false); } { - var res = await client.GetAsync("users/user1/timeline/posts"); + var res = await client.GetAsync("timelines/@user1/posts"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes2); @@ -509,8 +510,8 @@ namespace Timeline.Tests.IntegratedTests async Task CreatePost(DateTime time) { - var res = await client.PostAsJsonAsync("users/user1/timeline/posts", - new TimelinePostCreateRequest { Content = "aaa", Time = time }); + var res = await client.PostAsJsonAsync("timelines/@user1/posts", + TimelineHelper.TextPostCreateRequest("aaa", time)); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Id; @@ -522,7 +523,7 @@ namespace Timeline.Tests.IntegratedTests var id2 = await CreatePost(now); { - var res = await client.GetAsync("users/user1/timeline/posts"); + var res = await client.GetAsync("timelines/@user1/posts"); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Select(p => p.Id).Should().Equal(id1, id2, id0); diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 14a0a59e..3fceb1d5 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -6,12 +6,38 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Timeline.Models; using Timeline.Models.Http; using Timeline.Tests.Helpers; using Xunit; namespace Timeline.Tests.IntegratedTests { + public static class TimelineHelper + { + public static TimelinePostContentInfo TextPostContent(string text) + { + return new TimelinePostContentInfo + { + Type = "text", + Text = text + }; + } + + public static TimelinePostCreateRequest TextPostCreateRequest(string text, DateTime? time = null) + { + return new TimelinePostCreateRequest + { + Content = new TimelinePostCreateRequestContent + { + Type = "text", + Text = text + }, + Time = time + }; + } + } + public class TimelineTest : IntegratedTestBase { public TimelineTest(WebApplicationFactory factory) @@ -45,7 +71,7 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateDefaultClient(); { - var res = await client.GetAsync("/users/user1/timeline"); + var res = await client.GetAsync("/timelines/@user1"); user1Timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; } @@ -80,7 +106,7 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAsUser(); { - var res = await client.PutAsync("/users/user1/timeline/members/user3", null); + var res = await client.PutAsync("/timelines/@user1/members/user3", null); res.Should().HaveStatusCode(200); } @@ -90,7 +116,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.PatchAsJsonAsync("/users/user1/timeline", new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); + var res = await client.PatchAsJsonAsync("/timelines/@user1", new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); res.Should().HaveStatusCode(200); } @@ -100,7 +126,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/users/user1/timeline"); + var res = await client.GetAsync("/timelines/@user1"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -123,7 +149,7 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAs(2); { - var res = await client.PutAsync("/users/user2/timeline/members/user3", null); + var res = await client.PutAsync("/timelines/@user2/members/user3", null); res.Should().HaveStatusCode(200); } @@ -133,7 +159,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.PatchAsJsonAsync("/users/user2/timeline", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); + var res = await client.PatchAsJsonAsync("/timelines/@user2", new TimelinePatchRequest { Visibility = TimelineVisibility.Register }); res.Should().HaveStatusCode(200); } @@ -143,7 +169,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/users/user2/timeline"); + var res = await client.GetAsync("/timelines/@user2"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -165,7 +191,7 @@ namespace Timeline.Tests.IntegratedTests var client = await CreateClientAs(3); { - var res = await client.PatchAsJsonAsync("/users/user3/timeline", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); + var res = await client.PatchAsJsonAsync("/timelines/@user3", new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } @@ -175,7 +201,7 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.GetAsync("/users/user3/timeline"); + var res = await client.GetAsync("/timelines/@user3"); var timeline = res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which; testResultRelate.Add(timeline); @@ -396,7 +422,7 @@ namespace Timeline.Tests.IntegratedTests res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("timelines/aaa!!!/posts", new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/aaa!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); res.Should().BeInvalidModel(); } { @@ -430,7 +456,7 @@ namespace Timeline.Tests.IntegratedTests res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); } { - var res = await client.PostAsJsonAsync("timelines/notexist/posts", new TimelinePostCreateRequest { Content = "aaa" }); + var res = await client.PostAsJsonAsync("timelines/notexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); } { @@ -673,7 +699,7 @@ namespace Timeline.Tests.IntegratedTests { { // no auth should get 401 var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(401); } } @@ -682,12 +708,12 @@ namespace Timeline.Tests.IntegratedTests { { // post self's var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } { // post other not as a member should get 403 var res = await client.PostAsJsonAsync("timelines/t0/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(403); } } @@ -696,7 +722,7 @@ namespace Timeline.Tests.IntegratedTests { { // post as admin var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } } @@ -705,7 +731,7 @@ namespace Timeline.Tests.IntegratedTests { { // post as member var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } } @@ -720,7 +746,7 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAs(userNumber); var res = await client.PostAsJsonAsync($"timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa" }); + TimelineHelper.TextPostCreateRequest("aaa")); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Id; @@ -795,19 +821,19 @@ namespace Timeline.Tests.IntegratedTests } { var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = null }); + TimelineHelper.TextPostCreateRequest(null)); res.Should().BeInvalidModel(); } const string mockContent = "aaa"; TimelinePostInfo createRes; { var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = mockContent }); + TimelineHelper.TextPostCreateRequest(mockContent)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which; body.Should().NotBeNull(); - body.Content.Should().Be(mockContent); + body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent)); body.Author.Should().BeEquivalentTo(UserInfos[1]); createRes = body; } @@ -822,12 +848,12 @@ namespace Timeline.Tests.IntegratedTests TimelinePostInfo createRes2; { var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = mockContent2, Time = mockTime2 }); + TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which; body.Should().NotBeNull(); - body.Content.Should().Be(mockContent2); + body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent2)); body.Author.Should().BeEquivalentTo(UserInfos[1]); body.Time.Should().BeCloseTo(mockTime2, 1000); createRes2 = body; @@ -865,7 +891,7 @@ namespace Timeline.Tests.IntegratedTests async Task CreatePost(DateTime time) { var res = await client.PostAsJsonAsync("timelines/t1/posts", - new TimelinePostCreateRequest { Content = "aaa", Time = time }); + TimelineHelper.TextPostCreateRequest("aaa", time)); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Id; diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs index 928d546c..7b28746f 100644 --- a/Timeline.Tests/IntegratedTests/TokenTest.cs +++ b/Timeline.Tests/IntegratedTests/TokenTest.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using Timeline.Models; using Timeline.Models.Http; using Timeline.Services; using Timeline.Tests.Helpers; diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 38fe7475..440b0d19 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -113,6 +114,19 @@ namespace Timeline.Controllers return result; } + // TODO: Make cache available. + [HttpGet("timelines/{name}/posts/{id}/data")] + public async Task>> PostDataGet([FromRoute][GeneralTimelineName] string name, [FromRoute] long id) + { + if (!this.IsAdministrator() && !await _service.HasReadPermission(name, this.GetOptionalUserId())) + { + return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); + } + + var data = await _service.GetPostData(name, id); + return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + } + [HttpPost("timelines/{name}/posts")] [Authorize] public async Task> PostPost([FromRoute][GeneralTimelineName] string name, [FromBody] TimelinePostCreateRequest body) diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index a3e8d816..0bc8bcda 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using Timeline.Auth; using Timeline.Helpers; +using Timeline.Models; using Timeline.Models.Http; using Timeline.Models.Validation; using Timeline.Services; diff --git a/Timeline/Entities/TimelineEntity.cs b/Timeline/Entities/TimelineEntity.cs index 56b36d4e..3149d4c2 100644 --- a/Timeline/Entities/TimelineEntity.cs +++ b/Timeline/Entities/TimelineEntity.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using Timeline.Models.Http; +using Timeline.Models; namespace Timeline.Entities { diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 55c3a3bf..9e2aefd0 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -72,25 +72,27 @@ namespace Timeline.Models.Http } } - public class TimelinePostConverter : ITypeConverter + public class TimelinePostContentResolver : IValueResolver { private readonly IActionContextAccessor _actionContextAccessor; private readonly IUrlHelperFactory _urlHelperFactory; - public TimelinePostConverter(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) + public TimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) { _actionContextAccessor = actionContextAccessor; _urlHelperFactory = urlHelperFactory; } - public TimelinePostContentInfo Convert(ITimelinePostContent source, TimelinePostContentInfo destination, ResolutionContext context) + public TimelinePostContentInfo Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo destMember, ResolutionContext context) { if (_actionContextAccessor.ActionContext == null) throw new InvalidOperationException("No action context, can't fill urls."); var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); - if (source is TextTimelinePostContent textContent) + var sourceContent = source.Content; + + if (sourceContent is TextTimelinePostContent textContent) { return new TimelinePostContentInfo { @@ -98,14 +100,21 @@ namespace Timeline.Models.Http Text = textContent.Text }; } - else if (source is ImageTimelinePostContent imageContent) + else if (sourceContent is ImageTimelinePostContent imageContent) { return new TimelinePostContentInfo { Type = TimelinePostContentTypes.Image, - Url = urlHelper.ActionLink(action: "PostDataGet", nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name }) + Url = urlHelper.ActionLink( + action: nameof(TimelineController.PostDataGet), + controller: nameof(TimelineController)[0..^nameof(Controller).Length], + values: new { Name = source.TimelineName, Id = source.Id }) }; } + else + { + throw new InvalidOperationException("Unknown content type."); + } } } @@ -114,8 +123,7 @@ namespace Timeline.Models.Http public TimelineInfoAutoMapperProfile() { CreateMap().ForMember(u => u._links, opt => opt.MapFrom()); - CreateMap(); - CreateMap().ConvertUsing(); + CreateMap().ForMember(p => p.Content, opt => opt.MapFrom()); CreateMap(); } } diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs index 4f887549..b4bf14c1 100644 --- a/Timeline/Models/Http/UserInfo.cs +++ b/Timeline/Models/Http/UserInfo.cs @@ -45,7 +45,7 @@ namespace Timeline.Models.Http { Self = urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { destination.Username }), Avatar = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController)[0..^nameof(Controller).Length], new { destination.Username }), - Timeline = urlHelper.ActionLink(nameof(PersonalTimelineController.TimelineGet), nameof(PersonalTimelineController)[0..^nameof(Controller).Length], new { destination.Username }) + Timeline = urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { Name = "@" + destination.Username }) }; return result; } diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs index 6d4c924d..803a5c5c 100644 --- a/Timeline/Models/Timeline.cs +++ b/Timeline/Models/Timeline.cs @@ -48,11 +48,22 @@ namespace Timeline.Models public class TimelinePost { + public TimelinePost(long id, ITimelinePostContent content, DateTime time, User author, DateTime lastUpdated, string timelineName) + { + Id = id; + Content = content; + Time = time; + Author = author; + LastUpdated = lastUpdated; + TimelineName = timelineName; + } + public long Id { get; set; } - public ITimelinePostContent Content { get; set; } = default!; + public ITimelinePostContent Content { get; set; } public DateTime Time { get; set; } - public User Author { get; set; } = default!; - public DateTime LastUpdated { get; set; } = default!; + public User Author { get; set; } + public DateTime LastUpdated { get; set; } + public string TimelineName { get; set; } } #pragma warning disable CA1724 // Type names should not match namespaces diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 1bccb855..3a5825ae 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -32,12 +32,14 @@ namespace Timeline.Services public long UserId { get; set; } } - public class DataWithType + public class PostData { #pragma warning disable CA1819 // Properties should not return arrays public byte[] Data { get; set; } = default!; #pragma warning restore CA1819 // Properties should not return arrays public string Type { get; set; } = default!; + public string ETag { get; set; } = default!; + public DateTime LastModified { get; set; } = default!; } /// @@ -103,7 +105,7 @@ namespace Timeline.Services /// /// Use this method to retrieve the image of image post. /// - Task GetPostData(string name, long postId); + Task GetPostData(string name, long postId); /// /// Create a new text post in timeline. @@ -334,6 +336,8 @@ namespace Timeline.Services /// protected abstract Task FindTimelineId(string name); + protected abstract string GenerateName(string name); + public async Task GetTimeline(string name) { if (name == null) @@ -355,7 +359,7 @@ namespace Timeline.Services return new Models.Timeline { - Name = timelineEntity.Name ?? ("@" + owner.Username), + Name = GenerateName(name), Description = timelineEntity.Description ?? "", Owner = owner, Visibility = timelineEntity.Visibility, @@ -387,19 +391,19 @@ namespace Timeline.Services _ => throw new DatabaseCorruptedException(string.Format(CultureInfo.InvariantCulture, ExceptionDatabaseUnknownContentType, type)) }; - posts.Add(new TimelinePost - { - Id = entity.LocalId, - Content = content, - Author = author, - Time = entity.Time, - LastUpdated = entity.LastUpdated - }); + posts.Add(new TimelinePost( + id: entity.LocalId, + content: content, + time: entity.Time, + author: author, + lastUpdated: entity.LastUpdated, + timelineName: GenerateName(name) + )); } } return posts; } - public async Task GetPostData(string name, long postId) + public async Task GetPostData(string name, long postId) { if (name == null) throw new ArgumentNullException(nameof(name)); @@ -437,10 +441,12 @@ namespace Timeline.Services await Database.SaveChangesAsync(); } - return new DataWithType + return new PostData { Data = data, - Type = postEntity.ExtraContent + Type = postEntity.ExtraContent, + ETag = tag, + LastModified = postEntity.LastUpdated }; } @@ -474,14 +480,15 @@ namespace Timeline.Services Database.TimelinePosts.Add(postEntity); await Database.SaveChangesAsync(); - return new TimelinePost - { - Id = postEntity.LocalId, - Content = new TextTimelinePostContent(text), - Author = author, - Time = finalTime, - LastUpdated = currentTime - }; + + return new TimelinePost( + id: postEntity.LocalId, + content: new TextTimelinePostContent(text), + time: finalTime, + author: author, + lastUpdated: currentTime, + timelineName: GenerateName(name) + ); } public async Task CreateImagePost(string name, long authorId, byte[] data, DateTime? time) @@ -521,14 +528,14 @@ namespace Timeline.Services Database.TimelinePosts.Add(postEntity); await Database.SaveChangesAsync(); - return new TimelinePost - { - Id = postEntity.LocalId, - Content = new ImageTimelinePostContent(tag), - Author = author, - Time = finalTime, - LastUpdated = currentTime - }; + return new TimelinePost( + id: postEntity.LocalId, + content: new ImageTimelinePostContent(tag), + time: finalTime, + author: author, + lastUpdated: currentTime, + timelineName: GenerateName(name) + ); } public async Task DeletePost(string name, long id) @@ -767,6 +774,11 @@ namespace Timeline.Services return timelineEntity.Id; } } + + protected override string GenerateName(string name) + { + return name; + } } public class PersonalTimelineService : BaseTimelineManager, IPersonalTimelineService @@ -818,6 +830,11 @@ namespace Timeline.Services return newTimelineEntity.Id; } } + + protected override string GenerateName(string name) + { + return "@" + name; + } } public class TimelineService : ITimelineService @@ -996,7 +1013,7 @@ namespace Timeline.Services return s.GetPosts(realName); } - public Task GetPostData(string name, long postId) + public Task GetPostData(string name, long postId) { var s = BranchName(name, out var realName); return s.GetPostData(realName, postId); diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 85822a14..d2fd22bd 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -101,7 +101,8 @@ namespace Timeline services.AddUserAvatarService(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.TryAddSingleton(); -- cgit v1.2.3 From 706eb877178d9c7f41b93927dedfc6c7ff27b7fd Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Mar 2020 22:27:30 +0800 Subject: Add invalid model tests. --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 3fceb1d5..5a721205 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -909,5 +909,50 @@ namespace Timeline.Tests.IntegratedTests .Which.Select(p => p.Id).Should().Equal(id1, id2, id0); } } + + [Fact] + public async Task CreatePost_InvalidModel() + { + await CreateTestTimelines(); + + using var client = await CreateClientAsUser(); + + { + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = null }); + res.Should().BeInvalidModel(); + } + + { + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null } }); + res.Should().BeInvalidModel(); + } + + { + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } }); + res.Should().BeInvalidModel(); + } + + { + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } }); + res.Should().BeInvalidModel(); + } + + { + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } }); + res.Should().BeInvalidModel(); + } + + { + // image not base64 + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } }); + res.Should().BeInvalidModel(); + } + + { + // image base64 not image + var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } }); + res.Should().BeInvalidModel(); + } + } } } -- cgit v1.2.3 From a908d22253b7d6cb5f07eecf5b35c64e4bab0390 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 17:25:39 +0800 Subject: New logic for HasPostModifyPermission --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 4 ++++ Timeline/Controllers/TimelineController.cs | 8 ++++---- Timeline/Services/TimelineService.cs | 21 +++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 5a721205..720140f1 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -868,6 +868,10 @@ namespace Timeline.Tests.IntegratedTests var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}"); res.Should().BeDelete(true); } + { + var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}"); + res.Should().BeDelete(false); + } { var res = await client.DeleteAsync("timelines/t1/posts/30000"); res.Should().BeDelete(false); diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 440b0d19..d21603cd 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -189,12 +189,12 @@ namespace Timeline.Controllers [Authorize] public async Task> PostDelete([FromRoute][GeneralTimelineName] string name, [FromRoute] long id) { + if (!this.IsAdministrator() && !await _service.HasPostModifyPermission(name, id, this.GetUserId())) + { + return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); + } try { - if (!this.IsAdministrator() && !await _service.HasPostModifyPermission(name, id, this.GetUserId())) - { - return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); - } await _service.DeletePost(name, id); return CommonDeleteResponse.Delete(); } diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 3a5825ae..97280728 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -210,19 +210,18 @@ namespace Timeline.Services /// /// See remarks of . /// The id of the user to check on. + /// True if you want it to throw . Default false. /// True if can modify, false if can't modify. /// Thrown when is null. /// See remarks of . /// See remarks of . - /// - /// Thrown when the post with given id does not exist or is deleted already. - /// + /// Thrown when the post with given id does not exist or is deleted already and is true. /// /// This method does not check whether the user is administrator. /// It only checks whether he is the author of the post or the owner of the timeline. /// Return false when user with modifier id does not exist. /// - Task HasPostModifyPermission(string name, long id, long modifierId); + Task HasPostModifyPermission(string name, long id, long modifierId, bool throwOnPostNotExist = false); /// /// Verify whether a user is member of a timeline. @@ -705,7 +704,7 @@ namespace Timeline.Services } } - public async Task HasPostModifyPermission(string name, long id, long modifierId) + public async Task HasPostModifyPermission(string name, long id, long modifierId, bool throwOnPostNotExist = false) { if (name == null) throw new ArgumentNullException(nameof(name)); @@ -716,10 +715,12 @@ namespace Timeline.Services var postEntity = await Database.TimelinePosts.Where(p => p.Id == id).Select(p => new { p.AuthorId }).SingleOrDefaultAsync(); - if (postEntity == null) - throw new TimelinePostNotExistException(name, id); + if (postEntity == null && throwOnPostNotExist) + { + throw new TimelinePostNotExistException(name, id, false); + } - return timelineEntity.OwnerId == modifierId || postEntity.AuthorId == modifierId; + return timelineEntity.OwnerId == modifierId || postEntity == null || postEntity.AuthorId == modifierId; } public async Task IsMemberOf(string name, long userId) @@ -1055,10 +1056,10 @@ namespace Timeline.Services return s.HasReadPermission(realName, visitorId); } - public Task HasPostModifyPermission(string name, long id, long modifierId) + public Task HasPostModifyPermission(string name, long id, long modifierId, bool throwOnPostNotExist = false) { var s = BranchName(name, out var realName); - return s.HasPostModifyPermission(realName, id, modifierId); + return s.HasPostModifyPermission(realName, id, modifierId, throwOnPostNotExist); } public Task IsMemberOf(string name, long userId) -- cgit v1.2.3 From 53b237832d3d967b531a8dc130ebbf2ede173741 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 18:16:18 +0800 Subject: ... --- Timeline.ErrorCodes/ErrorCodes.cs | 9 +- .../IntegratedTests/PersonalTimelineTest.cs | 533 --------------------- Timeline.Tests/IntegratedTests/TimelineTest.cs | 308 +++++++----- Timeline/Controllers/TimelineController.cs | 4 +- Timeline/Filters/Timeline.cs | 2 +- Timeline/Models/Http/ErrorResponse.cs | 29 +- Timeline/Resources/Messages.Designer.cs | 51 +- Timeline/Resources/Messages.resx | 21 +- Timeline/Services/TimelineService.cs | 14 +- 9 files changed, 270 insertions(+), 701 deletions(-) delete mode 100644 Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs index eca0e18b..ef150921 100644 --- a/Timeline.ErrorCodes/ErrorCodes.cs +++ b/Timeline.ErrorCodes/ErrorCodes.cs @@ -56,16 +56,13 @@ public const int BadFormat_BadSize = 1_103_00_03; } - public static class TimelineCommon + public static class TimelineController { public const int NameConflict = 1_104_01_01; public const int NotExist = 1_104_02_01; public const int MemberPut_NotExist = 1_104_03_01; - } - - public static class TimelineController - { - public const int QueryRelateNotExist = 1_105_01_01; + public const int QueryRelateNotExist = 1_104_04_01; + public const int PostNoData = 1_104_05_01; } } } diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs deleted file mode 100644 index aa37e898..00000000 --- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs +++ /dev/null @@ -1,533 +0,0 @@ -using FluentAssertions; -using Microsoft.AspNetCore.Mvc.Testing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; -using Timeline.Models; -using Timeline.Models.Http; -using Timeline.Tests.Helpers; -using Xunit; - -namespace Timeline.Tests.IntegratedTests -{ - public class PersonalTimelineTest : IntegratedTestBase - { - public PersonalTimelineTest(WebApplicationFactory factory) - : base(factory, 3) - { - - } - - [Fact] - public async Task TimelineGet_Should_Work() - { - using var client = await CreateDefaultClient(); - var res = await client.GetAsync("timelines/@user1"); - var body = res.Should().HaveStatusCode(200) - .And.HaveJsonBody().Which; - body.Owner.Should().BeEquivalentTo(UserInfos[1]); - body.Visibility.Should().Be(TimelineVisibility.Register); - body.Description.Should().Be(""); - body.Members.Should().NotBeNull().And.BeEmpty(); - } - - [Fact] - public async Task InvalidModel_BadUsername() - { - using var client = await CreateClientAsAdministrator(); - { - var res = await client.GetAsync("timelines/@user!!!"); - res.Should().BeInvalidModel(); - } - { - var res = await client.PatchAsJsonAsync("timelines/@user!!!", new TimelinePatchRequest { }); - res.Should().BeInvalidModel(); - } - { - var res = await client.PutAsync("timelines/@user!!!/members/user1", null); - res.Should().BeInvalidModel(); - } - { - var res = await client.DeleteAsync("timelines/@user!!!/members/user1"); - res.Should().BeInvalidModel(); - } - { - var res = await client.GetAsync("timelines/@user!!!/posts"); - res.Should().BeInvalidModel(); - } - { - var res = await client.PostAsJsonAsync("timelines/@user!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().BeInvalidModel(); - } - { - var res = await client.DeleteAsync("timelines/@user!!!/posts/123"); - res.Should().BeInvalidModel(); - } - } - - [Fact] - public async Task NotFound() - { - using var client = await CreateClientAsAdministrator(); - { - var res = await client.GetAsync("timelines/@usernotexist"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.PatchAsJsonAsync("timelines/@usernotexist", new TimelinePatchRequest { }); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.PutAsync("timelines/@usernotexist/members/user1", null); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.DeleteAsync("timelines/@usernotexist/members/user1"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.GetAsync("timelines/@usernotexist/posts"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.PostAsJsonAsync("timelines/@usernotexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - { - var res = await client.DeleteAsync("timelines/@usernotexist/posts/123"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); - } - } - - [Fact] - public async Task Description_Should_Work() - { - using var client = await CreateClientAsUser(); - - async Task AssertDescription(string description) - { - var res = await client.GetAsync("timelines/@user1"); - var body = res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Description.Should().Be(description); - } - - const string mockDescription = "haha"; - - await AssertDescription(""); - { - var res = await client.PatchAsJsonAsync("timelines/@user1", - new TimelinePatchRequest { Description = mockDescription }); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); - await AssertDescription(mockDescription); - } - { - var res = await client.PatchAsJsonAsync("timelines/@user1", - new TimelinePatchRequest { Description = null }); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); - await AssertDescription(mockDescription); - } - { - var res = await client.PatchAsJsonAsync("timelines/@user1", - new TimelinePatchRequest { Description = "" }); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody().Which.Description.Should().Be(""); - await AssertDescription(""); - } - } - - [Fact] - public async Task Member_Should_Work() - { - const string getUrl = "timelines/@user1"; - using var client = await CreateClientAsUser(); - - async Task AssertMembers(IList members) - { - var res = await client.GetAsync(getUrl); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Members.Should().NotBeNull().And.BeEquivalentTo(members); - } - - async Task AssertEmptyMembers() - { - var res = await client.GetAsync(getUrl); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Members.Should().NotBeNull().And.BeEmpty(); - } - - await AssertEmptyMembers(); - { - var res = await client.PutAsync("/timelines/@user1/members/usernotexist", null); - res.Should().HaveStatusCode(400) - .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist); - } - await AssertEmptyMembers(); - { - var res = await client.PutAsync("/timelines/@user1/members/user2", null); - res.Should().HaveStatusCode(200); - } - await AssertMembers(new List { UserInfos[2] }); - { - var res = await client.DeleteAsync("/timelines/@user1/members/user2"); - res.Should().BeDelete(true); - } - await AssertEmptyMembers(); - { - var res = await client.DeleteAsync("/timelines/@user1/members/users2"); - res.Should().BeDelete(false); - } - await AssertEmptyMembers(); - } - - [Theory] - [InlineData(-1, 200, 401, 401, 401, 401)] - [InlineData(1, 200, 200, 403, 200, 403)] - [InlineData(0, 200, 200, 200, 200, 200)] - public async Task Permission_Timeline(int userNumber, int get, int opPatchUser, int opPatchAdmin, int opMemberUser, int opMemberAdmin) - { - using var client = await CreateClientAs(userNumber); - { - var res = await client.GetAsync("timelines/@user1"); - res.Should().HaveStatusCode(get); - } - - { - var res = await client.PatchAsJsonAsync("timelines/@user1", new TimelinePatchRequest { Description = "hahaha" }); - res.Should().HaveStatusCode(opPatchUser); - } - - { - var res = await client.PatchAsJsonAsync("timelines/@admin", new TimelinePatchRequest { Description = "hahaha" }); - res.Should().HaveStatusCode(opPatchAdmin); - } - - { - var res = await client.PutAsync("timelines/@user1/members/user2", null); - res.Should().HaveStatusCode(opMemberUser); - } - - { - var res = await client.DeleteAsync("timelines/@user1/members/user2"); - res.Should().HaveStatusCode(opMemberUser); - } - - { - var res = await client.PutAsync("timelines/@admin/members/user2", null); - res.Should().HaveStatusCode(opMemberAdmin); - } - - { - var res = await client.DeleteAsync("timelines/@admin/members/user2"); - res.Should().HaveStatusCode(opMemberAdmin); - } - } - - [Fact] - public async Task Visibility_Test() - { - const string userUrl = "timelines/@user1/posts"; - const string adminUrl = "timelines/@admin/posts"; - { - - using var client = await CreateClientAsUser(); - using var content = new StringContent(@"{""visibility"":""abcdefg""}", System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json); - var res = await client.PatchAsync("timelines/@user1", content); - res.Should().BeInvalidModel(); - } - { // default visibility is registered - { - using var client = await CreateDefaultClient(); - var res = await client.GetAsync(userUrl); - res.Should().HaveStatusCode(403); - } - - { - using var client = await CreateClientAsUser(); - var res = await client.GetAsync(adminUrl); - res.Should().HaveStatusCode(200); - } - } - - { // change visibility to public - { - using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("timelines/@user1", - new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); - res.Should().HaveStatusCode(200); - } - { - using var client = await CreateDefaultClient(); - var res = await client.GetAsync(userUrl); - res.Should().HaveStatusCode(200); - } - } - - { // change visibility to private - { - using var client = await CreateClientAsAdministrator(); - { - var res = await client.PatchAsJsonAsync("timelines/@user1", - new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); - res.Should().HaveStatusCode(200); - } - { - var res = await client.PatchAsJsonAsync("timelines/@admin", - new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); - res.Should().HaveStatusCode(200); - } - } - { - using var client = await CreateDefaultClient(); - var res = await client.GetAsync(userUrl); - res.Should().HaveStatusCode(403); - } - { // user can't read admin's - using var client = await CreateClientAsUser(); - var res = await client.GetAsync(adminUrl); - res.Should().HaveStatusCode(403); - } - { // admin can read user's - using var client = await CreateClientAsAdministrator(); - var res = await client.GetAsync(userUrl); - res.Should().HaveStatusCode(200); - } - { // add member - using var client = await CreateClientAsAdministrator(); - var res = await client.PutAsync("/timelines/@admin/members/user1", null); - res.Should().HaveStatusCode(200); - } - { // now user can read admin's - using var client = await CreateClientAsUser(); - var res = await client.GetAsync(adminUrl); - res.Should().HaveStatusCode(200); - } - } - } - - - [Fact] - public async Task Permission_Post_Create() - { - using (var client = await CreateClientAsUser()) - { - var res = await client.PutAsync("timelines/@user1/members/user2", null); - res.Should().HaveStatusCode(200); - } - - using (var client = await CreateDefaultClient()) - { - { // no auth should get 401 - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(401); - } - } - - using (var client = await CreateClientAsUser()) - { - { // post self's - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(200); - } - { // post other not as a member should get 403 - var res = await client.PostAsJsonAsync("timelines/@admin/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(403); - } - } - - using (var client = await CreateClientAsAdministrator()) - { - { // post as admin - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(200); - } - } - - using (var client = await CreateClientAs(2)) - { - { // post as member - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(200); - } - } - } - - [Fact] - public async Task Permission_Post_Delete() - { - async Task CreatePost(int userNumber) - { - using var client = await CreateClientAs(userNumber); - var res = await client.PostAsJsonAsync($"timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa")); - return res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Id; - } - - using (var client = await CreateClientAsUser()) - { - { - var res = await client.PutAsync("timelines/@user1/members/user2", null); - res.Should().HaveStatusCode(200); - } - { - var res = await client.PutAsync("timelines/@user1/members/user3", null); - res.Should().HaveStatusCode(200); - } - } - - { // no auth should get 401 - using var client = await CreateDefaultClient(); - var res = await client.DeleteAsync("timelines/@user1/posts/12"); - res.Should().HaveStatusCode(401); - } - - { // self can delete self - var postId = await CreatePost(1); - using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); - res.Should().HaveStatusCode(200); - } - - { // admin can delete any - var postId = await CreatePost(1); - using var client = await CreateClientAsAdministrator(); - var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); - res.Should().HaveStatusCode(200); - } - - { // owner can delete other - var postId = await CreatePost(2); - using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); - res.Should().HaveStatusCode(200); - } - - { // author can delete self - var postId = await CreatePost(2); - using var client = await CreateClientAs(2); - var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); - res.Should().HaveStatusCode(200); - } - - { // otherwise is forbidden - var postId = await CreatePost(2); - using var client = await CreateClientAs(3); - var res = await client.DeleteAsync($"timelines/@user1/posts/{postId}"); - res.Should().HaveStatusCode(403); - } - } - - [Fact] - public async Task Post_Op_Should_Work() - { - { - using var client = await CreateClientAsUser(); - { - var res = await client.GetAsync("timelines/@user1/posts"); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Should().NotBeNull().And.BeEmpty(); - } - { - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest(null)); - res.Should().BeInvalidModel(); - } - const string mockContent = "aaa"; - TimelinePostInfo createRes; - { - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest(mockContent)); - var body = res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which; - body.Should().NotBeNull(); - body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent)); - body.Author.Should().BeEquivalentTo(UserInfos[1]); - createRes = body; - } - { - var res = await client.GetAsync("timelines/@user1/posts"); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Should().NotBeNull().And.BeEquivalentTo(createRes); - } - const string mockContent2 = "bbb"; - var mockTime2 = DateTime.Now.AddDays(-1); - TimelinePostInfo createRes2; - { - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); - var body = res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which; - body.Should().NotBeNull(); - body.Content.Should().BeEquivalentTo(TimelineHelper.TextPostContent(mockContent2)); - body.Author.Should().BeEquivalentTo(UserInfos[1]); - body.Time.Should().BeCloseTo(mockTime2, 1000); - createRes2 = body; - } - { - var res = await client.GetAsync("timelines/@user1/posts"); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Should().NotBeNull().And.BeEquivalentTo(createRes, createRes2); - } - { - var res = await client.DeleteAsync($"timelines/@user1/posts/{createRes.Id}"); - res.Should().BeDelete(true); - } - { - var res = await client.DeleteAsync("timelines/@user1/posts/30000"); - res.Should().BeDelete(false); - } - { - var res = await client.GetAsync("timelines/@user1/posts"); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Should().NotBeNull().And.BeEquivalentTo(createRes2); - } - } - } - - [Fact] - public async Task GetPost_Should_Ordered() - { - using var client = await CreateClientAsUser(); - - async Task CreatePost(DateTime time) - { - var res = await client.PostAsJsonAsync("timelines/@user1/posts", - TimelineHelper.TextPostCreateRequest("aaa", time)); - return res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Id; - } - - var now = DateTime.Now; - var id0 = await CreatePost(now.AddDays(1)); - var id1 = await CreatePost(now.AddDays(-1)); - var id2 = await CreatePost(now); - - { - var res = await client.GetAsync("timelines/@user1/posts"); - res.Should().HaveStatusCode(200) - .And.HaveJsonBody() - .Which.Select(p => p.Id).Should().Equal(id1, id2, id0); - } - } - } -} diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 720140f1..7206c675 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -43,7 +43,7 @@ namespace Timeline.Tests.IntegratedTests public TimelineTest(WebApplicationFactory factory) : base(factory, 3) { - + CreateTestTimelines().Wait(); } private List _testTimelines; @@ -61,11 +61,38 @@ namespace Timeline.Tests.IntegratedTests } } + private static string GeneratePersonalTimelineUrl(int id, string subpath = null) + { + return $"timelines/@{(id == 0 ? "admin" : ("user" + id))}{(subpath == null ? "" : ("/" + subpath))}"; + } + + private static string GenerateOrdinaryTimelineUrl(int id, string subpath = null) + { + return $"timelines/t{id}{(subpath == null ? "" : ("/" + subpath))}"; + } + + public static IEnumerable TimelineUrlGeneratorData() + { + yield return new[] { new Func(GeneratePersonalTimelineUrl) }; + yield return new[] { new Func(GenerateOrdinaryTimelineUrl) }; + } + [Fact] - public async Task TimelineList() + public async Task Personal_TimelineGet_Should_Work() { - await CreateTestTimelines(); + using var client = await CreateDefaultClient(); + var res = await client.GetAsync("timelines/@user1"); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody().Which; + body.Owner.Should().BeEquivalentTo(UserInfos[1]); + body.Visibility.Should().Be(TimelineVisibility.Register); + body.Description.Should().Be(""); + body.Members.Should().NotBeNull().And.BeEmpty(); + } + [Fact] + public async Task TimelineList() + { TimelineInfo user1Timeline; var client = await CreateDefaultClient(); @@ -91,8 +118,6 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task TimelineList_WithQuery() { - await CreateTestTimelines(); - var testResultRelate = new List(); var testResultOwn = new List(); var testResultJoin = new List(); @@ -336,7 +361,7 @@ namespace Timeline.Tests.IntegratedTests { var res = await client.PostAsJsonAsync("timelines", new TimelineCreateRequest { Name = "aaa" }); res.Should().HaveStatusCode(400) - .And.HaveCommonBody(ErrorCodes.TimelineCommon.NameConflict); + .And.HaveCommonBody(ErrorCodes.TimelineController.NameConflict); } } } @@ -344,8 +369,6 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task TimelineDelete_Should_Work() { - await CreateTestTimelines(); - { using var client = await CreateDefaultClient(); var res = await client.DeleteAsync("timelines/t1"); @@ -398,7 +421,7 @@ namespace Timeline.Tests.IntegratedTests } [Fact] - public async Task InvalidModel_BadName() + public async Task Ordinary_InvalidModel_BadName() { using var client = await CreateClientAsAdministrator(); { @@ -432,49 +455,117 @@ namespace Timeline.Tests.IntegratedTests } [Fact] - public async Task NotFound() + public async Task Personal_InvalidModel_BadUsername() + { + using var client = await CreateClientAsAdministrator(); + { + var res = await client.GetAsync("timelines/@user!!!"); + res.Should().BeInvalidModel(); + } + { + var res = await client.PatchAsJsonAsync("timelines/@user!!!", new TimelinePatchRequest { }); + res.Should().BeInvalidModel(); + } + { + var res = await client.PutAsync("timelines/@user!!!/members/user1", null); + res.Should().BeInvalidModel(); + } + { + var res = await client.DeleteAsync("timelines/@user!!!/members/user1"); + res.Should().BeInvalidModel(); + } + { + var res = await client.GetAsync("timelines/@user!!!/posts"); + res.Should().BeInvalidModel(); + } + { + var res = await client.PostAsJsonAsync("timelines/@user!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); + res.Should().BeInvalidModel(); + } + { + var res = await client.DeleteAsync("timelines/@user!!!/posts/123"); + res.Should().BeInvalidModel(); + } + } + + [Fact] + public async Task Ordinary_NotFound() { using var client = await CreateClientAsAdministrator(); { var res = await client.GetAsync("timelines/notexist"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.PatchAsJsonAsync("timelines/notexist", new TimelinePatchRequest { }); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.PutAsync("timelines/notexist/members/user1", null); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.DeleteAsync("timelines/notexist/members/user1"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.GetAsync("timelines/notexist/posts"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.PostAsJsonAsync("timelines/notexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } { var res = await client.DeleteAsync("timelines/notexist/posts/123"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); } } + [Fact] - public async Task Description_Should_Work() + public async Task PersonalNotFound() { - await CreateTestTimelines(); + using var client = await CreateClientAsAdministrator(); + { + var res = await client.GetAsync("timelines/@usernotexist"); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.PatchAsJsonAsync("timelines/@usernotexist", new TimelinePatchRequest { }); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.PutAsync("timelines/@usernotexist/members/user1", null); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.DeleteAsync("timelines/@usernotexist/members/user1"); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.GetAsync("timelines/@usernotexist/posts"); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.PostAsJsonAsync("timelines/@usernotexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + { + var res = await client.DeleteAsync("timelines/@usernotexist/posts/123"); + res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + } + } + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Description_Should_Work(Func generator) + { using var client = await CreateClientAsUser(); async Task AssertDescription(string description) { - var res = await client.GetAsync("timelines/t1"); + var res = await client.GetAsync(generator(1, null)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Description.Should().Be(description); @@ -484,21 +575,21 @@ namespace Timeline.Tests.IntegratedTests await AssertDescription(""); { - var res = await client.PatchAsJsonAsync("timelines/t1", + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Description = mockDescription }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); await AssertDescription(mockDescription); } { - var res = await client.PatchAsJsonAsync("timelines/t1", + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Description = null }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(mockDescription); await AssertDescription(mockDescription); } { - var res = await client.PatchAsJsonAsync("timelines/t1", + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Description = "" }); res.Should().HaveStatusCode(200) .And.HaveJsonBody().Which.Description.Should().Be(""); @@ -506,12 +597,11 @@ namespace Timeline.Tests.IntegratedTests } } - [Fact] - public async Task Member_Should_Work() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Member_Should_Work(Func generator) { - await CreateTestTimelines(); - - const string getUrl = "timelines/t1"; + var getUrl = generator(1, null); using var client = await CreateClientAsUser(); async Task AssertMembers(IList members) @@ -532,35 +622,40 @@ namespace Timeline.Tests.IntegratedTests await AssertEmptyMembers(); { - var res = await client.PutAsync("/timelines/t1/members/usernotexist", null); + var res = await client.PutAsync(generator(1, "members/usernotexist"), null); res.Should().HaveStatusCode(400) - .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist); + .And.HaveCommonBody(ErrorCodes.TimelineController.MemberPut_NotExist); } await AssertEmptyMembers(); { - var res = await client.PutAsync("/timelines/t1/members/user2", null); + var res = await client.PutAsync(generator(1, "members/user2"), null); res.Should().HaveStatusCode(200); } await AssertMembers(new List { UserInfos[2] }); { - var res = await client.DeleteAsync("/timelines/t1/members/user2"); + var res = await client.DeleteAsync(generator(1, "members/user2")); res.Should().BeDelete(true); } await AssertEmptyMembers(); { - var res = await client.DeleteAsync("/timelines/t1/members/users2"); + var res = await client.DeleteAsync(generator(1, "members/aaa")); res.Should().BeDelete(false); } await AssertEmptyMembers(); } [Theory] - [InlineData(-1, 200, 401, 401, 401, 401)] - [InlineData(1, 200, 200, 403, 200, 403)] - [InlineData(0, 200, 200, 200, 200, 200)] - public async Task Permission_Timeline(int userNumber, int get, int opPatchUser, int opPatchAdmin, int opMemberUser, int opMemberAdmin) + [InlineData(nameof(GenerateOrdinaryTimelineUrl), -1, 200, 401, 401, 401, 401)] + [InlineData(nameof(GenerateOrdinaryTimelineUrl), 1, 200, 200, 403, 200, 403)] + [InlineData(nameof(GenerateOrdinaryTimelineUrl), 0, 200, 200, 200, 200, 200)] + [InlineData(nameof(GeneratePersonalTimelineUrl), -1, 200, 401, 401, 401, 401)] + [InlineData(nameof(GeneratePersonalTimelineUrl), 1, 200, 200, 403, 200, 403)] + [InlineData(nameof(GeneratePersonalTimelineUrl), 0, 200, 200, 200, 200, 200)] + + public async Task Permission_Timeline(string generatorName, int userNumber, int get, int opPatchUser, int opPatchAdmin, int opMemberUser, int opMemberAdmin) { - await CreateTestTimelines(); + var method = GetType().GetMethod(generatorName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); + Func generator = (int id, string subpath) => (string)method.Invoke(null, new object[] { id, subpath }); using var client = await CreateClientAs(userNumber); { @@ -569,48 +664,47 @@ namespace Timeline.Tests.IntegratedTests } { - var res = await client.PatchAsJsonAsync("timelines/t1", new TimelinePatchRequest { Description = "hahaha" }); + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Description = "hahaha" }); res.Should().HaveStatusCode(opPatchUser); } { - var res = await client.PatchAsJsonAsync("timelines/t0", new TimelinePatchRequest { Description = "hahaha" }); + var res = await client.PatchAsJsonAsync(generator(0, null), new TimelinePatchRequest { Description = "hahaha" }); res.Should().HaveStatusCode(opPatchAdmin); } { - var res = await client.PutAsync("timelines/t1/members/user2", null); + var res = await client.PutAsync(generator(1, "members/user2"), null); res.Should().HaveStatusCode(opMemberUser); } { - var res = await client.DeleteAsync("timelines/t1/members/user2"); + var res = await client.DeleteAsync(generator(1, "members/user2")); res.Should().HaveStatusCode(opMemberUser); } { - var res = await client.PutAsync("timelines/t0/members/user2", null); + var res = await client.PutAsync(generator(0, "members/user2"), null); res.Should().HaveStatusCode(opMemberAdmin); } { - var res = await client.DeleteAsync("timelines/t0/members/user2"); + var res = await client.DeleteAsync(generator(0, "members/user2")); res.Should().HaveStatusCode(opMemberAdmin); } } - [Fact] - public async Task Visibility_Test() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Visibility_Test(Func generator) { - await CreateTestTimelines(); - - const string userUrl = "timelines/t1/posts"; - const string adminUrl = "timelines/t0/posts"; + var userUrl = generator(1, "posts"); + var adminUrl = generator(0, "posts"); { using var client = await CreateClientAsUser(); using var content = new StringContent(@"{""visibility"":""abcdefg""}", System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json); - var res = await client.PatchAsync("timelines/t1", content); + var res = await client.PatchAsync(generator(1, null), content); res.Should().BeInvalidModel(); } { // default visibility is registered @@ -630,7 +724,7 @@ namespace Timeline.Tests.IntegratedTests { // change visibility to public { using var client = await CreateClientAsUser(); - var res = await client.PatchAsJsonAsync("timelines/t1", + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Visibility = TimelineVisibility.Public }); res.Should().HaveStatusCode(200); } @@ -645,12 +739,12 @@ namespace Timeline.Tests.IntegratedTests { using var client = await CreateClientAsAdministrator(); { - var res = await client.PatchAsJsonAsync("timelines/t1", + var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } { - var res = await client.PatchAsJsonAsync("timelines/t0", + var res = await client.PatchAsJsonAsync(generator(0, null), new TimelinePatchRequest { Visibility = TimelineVisibility.Private }); res.Should().HaveStatusCode(200); } @@ -672,7 +766,7 @@ namespace Timeline.Tests.IntegratedTests } { // add member using var client = await CreateClientAsAdministrator(); - var res = await client.PutAsync("/timelines/t0/members/user1", null); + var res = await client.PutAsync(generator(0, "members/user1"), null); res.Should().HaveStatusCode(200); } { // now user can read admin's @@ -683,22 +777,20 @@ namespace Timeline.Tests.IntegratedTests } } - - [Fact] - public async Task Permission_Post_Create() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Permission_Post_Create(Func generator) { - await CreateTestTimelines(); - using (var client = await CreateClientAsUser()) { - var res = await client.PutAsync("timelines/t1/members/user2", null); + var res = await client.PutAsync(generator(1, "members/user2"), null); res.Should().HaveStatusCode(200); } using (var client = await CreateDefaultClient()) { { // no auth should get 401 - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(401); } @@ -707,12 +799,12 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { { // post self's - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } { // post other not as a member should get 403 - var res = await client.PostAsJsonAsync("timelines/t0/posts", + var res = await client.PostAsJsonAsync(generator(0, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(403); } @@ -721,7 +813,7 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsAdministrator()) { { // post as admin - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } @@ -730,22 +822,21 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAs(2)) { { // post as member - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().HaveStatusCode(200); } } } - [Fact] - public async Task Permission_Post_Delete() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Permission_Post_Delete(Func generator) { - await CreateTestTimelines(); - async Task CreatePost(int userNumber) { using var client = await CreateClientAs(userNumber); - var res = await client.PostAsJsonAsync($"timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa")); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() @@ -755,79 +846,78 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser()) { { - var res = await client.PutAsync("timelines/t1/members/user2", null); + var res = await client.PutAsync(generator(1, "members/user2"), null); res.Should().HaveStatusCode(200); } { - var res = await client.PutAsync("timelines/t1/members/user3", null); + var res = await client.PutAsync(generator(1, "members/user3"), null); res.Should().HaveStatusCode(200); } } { // no auth should get 401 using var client = await CreateDefaultClient(); - var res = await client.DeleteAsync("timelines/t1/posts/12"); + var res = await client.DeleteAsync(generator(1, "posts/12")); res.Should().HaveStatusCode(401); } { // self can delete self var postId = await CreatePost(1); using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"timelines/t1/posts/{postId}"); + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); res.Should().HaveStatusCode(200); } { // admin can delete any var postId = await CreatePost(1); using var client = await CreateClientAsAdministrator(); - var res = await client.DeleteAsync($"timelines/t1/posts/{postId}"); + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); res.Should().HaveStatusCode(200); } { // owner can delete other var postId = await CreatePost(2); using var client = await CreateClientAsUser(); - var res = await client.DeleteAsync($"timelines/t1/posts/{postId}"); + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); res.Should().HaveStatusCode(200); } { // author can delete self var postId = await CreatePost(2); using var client = await CreateClientAs(2); - var res = await client.DeleteAsync($"timelines/t1/posts/{postId}"); + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); res.Should().HaveStatusCode(200); } { // otherwise is forbidden var postId = await CreatePost(2); using var client = await CreateClientAs(3); - var res = await client.DeleteAsync($"timelines/t1/posts/{postId}"); + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); res.Should().HaveStatusCode(403); } } - [Fact] - public async Task Post_Op_Should_Work() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Post_Op_Should_Work(Func generator) { - await CreateTestTimelines(); - { using var client = await CreateClientAsUser(); { - var res = await client.GetAsync("timelines/t1/posts"); + var res = await client.GetAsync(generator(1, "posts")); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEmpty(); } { - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest(null)); res.Should().BeInvalidModel(); } const string mockContent = "aaa"; TimelinePostInfo createRes; { - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest(mockContent)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() @@ -838,7 +928,7 @@ namespace Timeline.Tests.IntegratedTests createRes = body; } { - var res = await client.GetAsync("timelines/t1/posts"); + var res = await client.GetAsync(generator(1, "posts")); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes); @@ -847,7 +937,7 @@ namespace Timeline.Tests.IntegratedTests var mockTime2 = DateTime.Now.AddDays(-1); TimelinePostInfo createRes2; { - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2)); var body = res.Should().HaveStatusCode(200) .And.HaveJsonBody() @@ -859,25 +949,25 @@ namespace Timeline.Tests.IntegratedTests createRes2 = body; } { - var res = await client.GetAsync("timelines/t1/posts"); + var res = await client.GetAsync(generator(1, "posts")); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes, createRes2); } { - var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}"); + var res = await client.DeleteAsync(generator(1, $"posts/{createRes.Id}")); res.Should().BeDelete(true); } { - var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}"); + var res = await client.DeleteAsync(generator(1, $"posts/{createRes.Id}")); res.Should().BeDelete(false); } { - var res = await client.DeleteAsync("timelines/t1/posts/30000"); + var res = await client.DeleteAsync(generator(1, "posts/30000")); res.Should().BeDelete(false); } { - var res = await client.GetAsync("timelines/t1/posts"); + var res = await client.GetAsync(generator(1, "posts")); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Should().NotBeNull().And.BeEquivalentTo(createRes2); @@ -885,16 +975,15 @@ namespace Timeline.Tests.IntegratedTests } } - [Fact] - public async Task GetPost_Should_Ordered() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task GetPost_Should_Ordered(Func generator) { - await CreateTestTimelines(); - using var client = await CreateClientAsUser(); async Task CreatePost(DateTime time) { - var res = await client.PostAsJsonAsync("timelines/t1/posts", + var res = await client.PostAsJsonAsync(generator(1, "posts"), TimelineHelper.TextPostCreateRequest("aaa", time)); return res.Should().HaveStatusCode(200) .And.HaveJsonBody() @@ -907,54 +996,53 @@ namespace Timeline.Tests.IntegratedTests var id2 = await CreatePost(now); { - var res = await client.GetAsync("timelines/t1/posts"); + var res = await client.GetAsync(generator(1, "posts")); res.Should().HaveStatusCode(200) .And.HaveJsonBody() .Which.Select(p => p.Id).Should().Equal(id1, id2, id0); } } - [Fact] - public async Task CreatePost_InvalidModel() + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task CreatePost_InvalidModel(Func generator) { - await CreateTestTimelines(); - using var client = await CreateClientAsUser(); { - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = null }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = null }); res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null } }); res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } }); res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } }); res.Should().BeInvalidModel(); } { - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } }); res.Should().BeInvalidModel(); } { // image not base64 - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } }); res.Should().BeInvalidModel(); } { // image base64 not image - var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } }); + var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } }); res.Should().BeInvalidModel(); } } diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index d21603cd..0628937d 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -234,7 +234,7 @@ namespace Timeline.Controllers } catch (UserNotExistException) { - return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist()); + return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist()); } } @@ -272,7 +272,7 @@ namespace Timeline.Controllers } catch (ConflictException) { - return BadRequest(ErrorResponse.TimelineCommon.NameConflict()); + return BadRequest(ErrorResponse.TimelineController.NameConflict()); } } diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs index e133c9d6..76e8d751 100644 --- a/Timeline/Filters/Timeline.cs +++ b/Timeline/Filters/Timeline.cs @@ -17,7 +17,7 @@ namespace Timeline.Filters } else { - context.Result = new NotFoundObjectResult(ErrorResponse.TimelineCommon.NotExist()); + context.Result = new NotFoundObjectResult(ErrorResponse.TimelineController.NotExist()); } } } diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 9f7e70e1..9c5a7cfe 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -242,44 +242,39 @@ namespace Timeline.Models.Http } - public static class TimelineCommon + public static class TimelineController { public static CommonResponse NameConflict(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(TimelineCommon_NameConflict, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NameConflict, string.Format(TimelineController_NameConflict, formatArgs)); } public static CommonResponse CustomMessage_NameConflict(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NameConflict, string.Format(message, formatArgs)); } public static CommonResponse NotExist(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(TimelineCommon_NotExist, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NotExist, string.Format(TimelineController_NotExist, formatArgs)); } public static CommonResponse CustomMessage_NotExist(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NotExist, string.Format(message, formatArgs)); } public static CommonResponse MemberPut_NotExist(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(TimelineCommon_MemberPut_NotExist, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(TimelineController_MemberPut_NotExist, formatArgs)); } public static CommonResponse CustomMessage_MemberPut_NotExist(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs)); } - } - - public static class TimelineController - { - public static CommonResponse QueryRelateNotExist(params object?[] formatArgs) { return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(TimelineController_QueryRelateNotExist, formatArgs)); @@ -290,6 +285,16 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(message, formatArgs)); } + public static CommonResponse PostNoData(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(TimelineController_PostNoData, formatArgs)); + } + + public static CommonResponse CustomMessage_PostNoData(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(message, formatArgs)); + } + } } diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index fb093f07..cae91093 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -151,65 +151,74 @@ namespace Timeline.Resources { } /// - /// Looks up a localized string similar to The user to set as member does not exist.. + /// Looks up a localized string similar to Unknown type of post content.. /// - internal static string TimelineCommon_MemberPut_NotExist { + internal static string TimelineController_ContentUnknownType { get { - return ResourceManager.GetString("TimelineCommon_MemberPut_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineController_ContentUnknownType", resourceCulture); } } /// - /// Looks up a localized string similar to A timeline with given name already exists.. + /// Looks up a localized string similar to Data field is not a valid base64 string in image content.. /// - internal static string TimelineCommon_NameConflict { + internal static string TimelineController_ImageContentDataNotBase64 { get { - return ResourceManager.GetString("TimelineCommon_NameConflict", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataNotBase64", resourceCulture); } } /// - /// Looks up a localized string similar to The timeline with given name does not exist.. + /// Looks up a localized string similar to Data field is not a valid image after base64 decoding in image content.. /// - internal static string TimelineCommon_NotExist { + internal static string TimelineController_ImageContentDataNotImage { get { - return ResourceManager.GetString("TimelineCommon_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataNotImage", resourceCulture); } } /// - /// Looks up a localized string similar to Unknown type of post content.. + /// Looks up a localized string similar to Data field is required for image content.. /// - internal static string TimelineController_ContentUnknownType { + internal static string TimelineController_ImageContentDataRequired { get { - return ResourceManager.GetString("TimelineController_ContentUnknownType", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataRequired", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is not a valid base64 string in image content.. + /// Looks up a localized string similar to The user to set as member does not exist.. /// - internal static string TimelineController_ImageContentDataNotBase64 { + internal static string TimelineController_MemberPut_NotExist { get { - return ResourceManager.GetString("TimelineController_ImageContentDataNotBase64", resourceCulture); + return ResourceManager.GetString("TimelineController_MemberPut_NotExist", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is not a valid image after base64 decoding in image content.. + /// Looks up a localized string similar to A timeline with given name already exists.. /// - internal static string TimelineController_ImageContentDataNotImage { + internal static string TimelineController_NameConflict { get { - return ResourceManager.GetString("TimelineController_ImageContentDataNotImage", resourceCulture); + return ResourceManager.GetString("TimelineController_NameConflict", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is required for image content.. + /// Looks up a localized string similar to The timeline with given name does not exist.. /// - internal static string TimelineController_ImageContentDataRequired { + internal static string TimelineController_NotExist { get { - return ResourceManager.GetString("TimelineController_ImageContentDataRequired", resourceCulture); + return ResourceManager.GetString("TimelineController_NotExist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The post of that type has no data.. + /// + internal static string TimelineController_PostNoData { + get { + return ResourceManager.GetString("TimelineController_PostNoData", resourceCulture); } } diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx index 6a4cb1b6..631bd749 100644 --- a/Timeline/Resources/Messages.resx +++ b/Timeline/Resources/Messages.resx @@ -147,15 +147,6 @@ Model is of bad format. - - The user to set as member does not exist. - - - A timeline with given name already exists. - - - The timeline with given name does not exist. - Unknown type of post content. @@ -168,6 +159,18 @@ Data field is required for image content. + + The user to set as member does not exist. + + + A timeline with given name already exists. + + + The timeline with given name does not exist. + + + The post of that type has no data. + The user specified by query param "relate" does not exist. diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 97280728..301a1d97 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -287,11 +287,11 @@ namespace Timeline.Services } - public abstract class BaseTimelineManager : IBaseTimelineService + public abstract class BaseTimelineService : IBaseTimelineService { - protected BaseTimelineManager(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) + protected BaseTimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); Clock = clock; Database = database; ImageValidator = imageValidator; @@ -299,7 +299,7 @@ namespace Timeline.Services UserService = userService; } - private ILogger _logger; + private ILogger _logger; protected IClock Clock { get; } @@ -546,7 +546,7 @@ namespace Timeline.Services var post = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == id).SingleOrDefaultAsync(); - if (post == null) + if (post == null || post.Content == null) throw new TimelinePostNotExistException(name, id); string? dataTag = null; @@ -739,7 +739,7 @@ namespace Timeline.Services } } - public class OrdinaryTimelineService : BaseTimelineManager, IOrdinaryTimelineService + public class OrdinaryTimelineService : BaseTimelineService, IOrdinaryTimelineService { private readonly TimelineNameValidator _timelineNameValidator = new TimelineNameValidator(); @@ -782,7 +782,7 @@ namespace Timeline.Services } } - public class PersonalTimelineService : BaseTimelineManager, IPersonalTimelineService + public class PersonalTimelineService : BaseTimelineService, IPersonalTimelineService { public PersonalTimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) : base(loggerFactory, database, imageValidator, dataManager, userService, clock) -- cgit v1.2.3 From 57c9da7f6bc98fb70e26f5332ffccfd55f7eb69b Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 18:38:22 +0800 Subject: ... --- Timeline.ErrorCodes/ErrorCodes.cs | 3 +- Timeline.Tests/IntegratedTests/TimelineTest.cs | 137 +++++++++---------------- Timeline/Controllers/TimelineController.cs | 15 ++- Timeline/Models/Http/ErrorResponse.cs | 10 ++ Timeline/Resources/Messages.Designer.cs | 9 ++ Timeline/Resources/Messages.resx | 3 + 6 files changed, 85 insertions(+), 92 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs index ef150921..0af36383 100644 --- a/Timeline.ErrorCodes/ErrorCodes.cs +++ b/Timeline.ErrorCodes/ErrorCodes.cs @@ -62,7 +62,8 @@ public const int NotExist = 1_104_02_01; public const int MemberPut_NotExist = 1_104_03_01; public const int QueryRelateNotExist = 1_104_04_01; - public const int PostNoData = 1_104_05_01; + public const int PostNotExist = 1_104_05_01; + public const int PostNoData = 1_104_05_02; } } } diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 7206c675..8801a3ef 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -77,6 +77,22 @@ namespace Timeline.Tests.IntegratedTests yield return new[] { new Func(GenerateOrdinaryTimelineUrl) }; } + private static string GeneratePersonalTimelineUrlByName(string name, string subpath = null) + { + return $"timelines/@{name}{(subpath == null ? "" : ("/" + subpath))}"; + } + + private static string GenerateOrdinaryTimelineUrlByName(string name, string subpath = null) + { + return $"timelines/{name}{(subpath == null ? "" : ("/" + subpath))}"; + } + + public static IEnumerable TimelineUrlByNameGeneratorData() + { + yield return new[] { new Func(GeneratePersonalTimelineUrlByName) }; + yield return new[] { new Func(GenerateOrdinaryTimelineUrlByName) }; + } + [Fact] public async Task Personal_TimelineGet_Should_Work() { @@ -420,140 +436,83 @@ namespace Timeline.Tests.IntegratedTests } } - [Fact] - public async Task Ordinary_InvalidModel_BadName() + [Theory] + [MemberData(nameof(TimelineUrlByNameGeneratorData))] + public async Task InvalidModel_BadName(Func generator) { using var client = await CreateClientAsAdministrator(); { - var res = await client.GetAsync("timelines/aaa!!!"); - res.Should().BeInvalidModel(); - } - { - var res = await client.PatchAsJsonAsync("timelines/aaa!!!", new TimelinePatchRequest { }); + var res = await client.GetAsync(generator("aaa!!!", null)); res.Should().BeInvalidModel(); } { - var res = await client.PutAsync("timelines/aaa!!!/members/user1", null); + var res = await client.PatchAsJsonAsync(generator("aaa!!!", null), new TimelinePatchRequest { }); res.Should().BeInvalidModel(); } { - var res = await client.DeleteAsync("timelines/aaa!!!/members/user1"); + var res = await client.PutAsync(generator("aaa!!!", "members/user1"), null); res.Should().BeInvalidModel(); } { - var res = await client.GetAsync("timelines/aaa!!!/posts"); - res.Should().BeInvalidModel(); - } - { - var res = await client.PostAsJsonAsync("timelines/aaa!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().BeInvalidModel(); - } - { - var res = await client.DeleteAsync("timelines/aaa!!!/posts/123"); - res.Should().BeInvalidModel(); - } - } - - [Fact] - public async Task Personal_InvalidModel_BadUsername() - { - using var client = await CreateClientAsAdministrator(); - { - var res = await client.GetAsync("timelines/@user!!!"); + var res = await client.DeleteAsync(generator("aaa!!!/members", "user1")); res.Should().BeInvalidModel(); } { - var res = await client.PatchAsJsonAsync("timelines/@user!!!", new TimelinePatchRequest { }); + var res = await client.GetAsync(generator("aaa!!!", "posts")); res.Should().BeInvalidModel(); } { - var res = await client.PutAsync("timelines/@user!!!/members/user1", null); + var res = await client.PostAsJsonAsync(generator("aaa!!!", "posts"), TimelineHelper.TextPostCreateRequest("aaa")); res.Should().BeInvalidModel(); } { - var res = await client.DeleteAsync("timelines/@user!!!/members/user1"); + var res = await client.DeleteAsync(generator("aaa!!!", "posts/123")); res.Should().BeInvalidModel(); } { - var res = await client.GetAsync("timelines/@user!!!/posts"); - res.Should().BeInvalidModel(); - } - { - var res = await client.PostAsJsonAsync("timelines/@user!!!/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().BeInvalidModel(); - } - { - var res = await client.DeleteAsync("timelines/@user!!!/posts/123"); + var res = await client.GetAsync(generator("aaa!!!", "posts/123/data")); res.Should().BeInvalidModel(); } } - [Fact] - public async Task Ordinary_NotFound() + [Theory] + [MemberData(nameof(TimelineUrlByNameGeneratorData))] + public async Task Ordinary_NotFound(Func generator) { + var errorCode = generator == GenerateOrdinaryTimelineUrlByName ? ErrorCodes.TimelineController.NotExist : ErrorCodes.UserCommon.NotExist; + using var client = await CreateClientAsAdministrator(); { - var res = await client.GetAsync("timelines/notexist"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - { - var res = await client.PatchAsJsonAsync("timelines/notexist", new TimelinePatchRequest { }); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); + var res = await client.GetAsync(generator("notexist", null)); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.PutAsync("timelines/notexist/members/user1", null); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - { - var res = await client.DeleteAsync("timelines/notexist/members/user1"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - { - var res = await client.GetAsync("timelines/notexist/posts"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - { - var res = await client.PostAsJsonAsync("timelines/notexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - { - var res = await client.DeleteAsync("timelines/notexist/posts/123"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist); - } - } - - - [Fact] - public async Task PersonalNotFound() - { - using var client = await CreateClientAsAdministrator(); - { - var res = await client.GetAsync("timelines/@usernotexist"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.PatchAsJsonAsync(generator("notexist", null), new TimelinePatchRequest { }); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.PatchAsJsonAsync("timelines/@usernotexist", new TimelinePatchRequest { }); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.PutAsync(generator("notexist", "members/user1"), null); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.PutAsync("timelines/@usernotexist/members/user1", null); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.DeleteAsync(generator("notexist", "members/user1")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.DeleteAsync("timelines/@usernotexist/members/user1"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.GetAsync(generator("notexist", "posts")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.GetAsync("timelines/@usernotexist/posts"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.PostAsJsonAsync(generator("notexist", "posts"), TimelineHelper.TextPostCreateRequest("aaa")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.PostAsJsonAsync("timelines/@usernotexist/posts", TimelineHelper.TextPostCreateRequest("aaa")); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.DeleteAsync(generator("notexist", "posts/123")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } { - var res = await client.DeleteAsync("timelines/@usernotexist/posts/123"); - res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist); + var res = await client.GetAsync(generator("notexist", "posts/123/data")); + res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode); } } diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 0628937d..6e5438c4 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -123,8 +123,19 @@ namespace Timeline.Controllers return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } - var data = await _service.GetPostData(name, id); - return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + try + { + var data = await _service.GetPostData(name, id); + return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + } + catch (TimelinePostNotExistException) + { + return NotFound(ErrorResponse.TimelineController.PostNotExist()); + } + catch (InvalidOperationException) + { + return BadRequest(ErrorResponse.TimelineController.PostNoData()); + } } [HttpPost("timelines/{name}/posts")] diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 9c5a7cfe..bb9c44df 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -285,6 +285,16 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(message, formatArgs)); } + public static CommonResponse PostNotExist(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNotExist, string.Format(TimelineController_PostNotExist, formatArgs)); + } + + public static CommonResponse CustomMessage_PostNotExist(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNotExist, string.Format(message, formatArgs)); + } + public static CommonResponse PostNoData(params object?[] formatArgs) { return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(TimelineController_PostNoData, formatArgs)); diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index cae91093..40c4a1ce 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -222,6 +222,15 @@ namespace Timeline.Resources { } } + /// + /// Looks up a localized string similar to The post to operate on does not exist.. + /// + internal static string TimelineController_PostNotExist { + get { + return ResourceManager.GetString("TimelineController_PostNotExist", resourceCulture); + } + } + /// /// Looks up a localized string similar to The user specified by query param "relate" does not exist.. /// diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx index 631bd749..8d5543fe 100644 --- a/Timeline/Resources/Messages.resx +++ b/Timeline/Resources/Messages.resx @@ -171,6 +171,9 @@ The post of that type has no data. + + The post to operate on does not exist. + The user specified by query param "relate" does not exist. -- cgit v1.2.3 From 61a4a86c3c428cc7ca985f003fb23641d1bde2ee Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 23:11:58 +0800 Subject: Make all integrated tests async. --- Timeline.Tests/Helpers/ResponseAssertions.cs | 8 ++- Timeline.Tests/Helpers/TestApplication.cs | 31 ++++++----- .../IntegratedTests/IntegratedTestBase.cs | 61 +++++++++++++++------- Timeline.Tests/IntegratedTests/TimelineTest.cs | 6 ++- 4 files changed, 71 insertions(+), 35 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/Helpers/ResponseAssertions.cs b/Timeline.Tests/Helpers/ResponseAssertions.cs index f01a0677..024732f5 100644 --- a/Timeline.Tests/Helpers/ResponseAssertions.cs +++ b/Timeline.Tests/Helpers/ResponseAssertions.cs @@ -33,7 +33,9 @@ namespace Timeline.Tests.Helpers try { - var body = res.Content.ReadAsStringAsync().Result; + var task = res.Content.ReadAsStringAsync(); + task.Wait(); + var body = task.Result; if (body.Length > 40) { body = body[0..40] + " ..."; @@ -83,7 +85,9 @@ namespace Timeline.Tests.Helpers string body; try { - body = Subject.Content.ReadAsStringAsync().Result; + var task = Subject.Content.ReadAsStringAsync(); + task.Wait(); + body = task.Result; } catch (AggregateException e) { diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs index 52c2f2e2..11fe8f87 100644 --- a/Timeline.Tests/Helpers/TestApplication.cs +++ b/Timeline.Tests/Helpers/TestApplication.cs @@ -3,29 +3,35 @@ using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using Timeline.Entities; using Timeline.Migrations; +using Xunit; namespace Timeline.Tests.Helpers { - public class TestApplication : IDisposable + public class TestApplication : IAsyncLifetime { - public SqliteConnection DatabaseConnection { get; } + public SqliteConnection DatabaseConnection { get; private set; } - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } - public string WorkDir { get; } + public string WorkDir { get; private set; } public TestApplication(WebApplicationFactory factory) + { + Factory = factory; + } + + public async Task InitializeAsync() { WorkDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(WorkDir); DatabaseConnection = new SqliteConnection("Data Source=:memory:;"); - DatabaseConnection.Open(); + await DatabaseConnection.OpenAsync(); var options = new DbContextOptionsBuilder() .UseSqlite(DatabaseConnection) @@ -33,15 +39,15 @@ namespace Timeline.Tests.Helpers using (var context = new DatabaseContext(options)) { - context.Database.EnsureCreated(); + await context.Database.EnsureCreatedAsync(); context.JwtToken.Add(new JwtTokenEntity { Key = JwtTokenGenerateHelper.GenerateKey() }); - context.SaveChanges(); + await context.SaveChangesAsync(); } - Factory = factory.WithWebHostBuilder(builder => + Factory = Factory.WithWebHostBuilder(builder => { builder.ConfigureAppConfiguration((context, config) => { @@ -60,11 +66,10 @@ namespace Timeline.Tests.Helpers }); } - public void Dispose() + public async Task DisposeAsync() { - DatabaseConnection.Close(); - DatabaseConnection.Dispose(); - + await DatabaseConnection.CloseAsync(); + await DatabaseConnection.DisposeAsync(); Directory.Delete(WorkDir, true); } } diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs index 66904629..a4a7638c 100644 --- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs +++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs @@ -15,12 +15,16 @@ using Xunit; namespace Timeline.Tests.IntegratedTests { - public abstract class IntegratedTestBase : IClassFixture>, IDisposable + public abstract class IntegratedTestBase : IClassFixture>, IAsyncLifetime { protected TestApplication TestApp { get; } protected WebApplicationFactory Factory => TestApp.Factory; + public IReadOnlyList UserInfos { get; private set; } + + private readonly int _userCount; + public IntegratedTestBase(WebApplicationFactory factory) : this(factory, 1) { @@ -31,8 +35,30 @@ namespace Timeline.Tests.IntegratedTests if (userCount < 0) throw new ArgumentOutOfRangeException(nameof(userCount), userCount, "User count can't be negative."); - TestApp = new TestApplication(factory); + _userCount = userCount; + TestApp = new TestApplication(factory); + } + + protected virtual Task OnInitializeAsync() + { + return Task.CompletedTask; + } + + protected virtual Task OnDisposeAsync() + { + return Task.CompletedTask; + } + + protected virtual void OnDispose() + { + + } + + public async Task InitializeAsync() + { + await TestApp.InitializeAsync(); + using (var scope = Factory.Services.CreateScope()) { var users = new List() @@ -46,7 +72,7 @@ namespace Timeline.Tests.IntegratedTests } }; - for (int i = 1; i <= userCount; i++) + for (int i = 1; i <= _userCount; i++) { users.Add(new User { @@ -62,10 +88,10 @@ namespace Timeline.Tests.IntegratedTests var userService = scope.ServiceProvider.GetRequiredService(); foreach (var user in users) { - userService.CreateUser(user).Wait(); + await userService.CreateUser(user); } - using var client = CreateDefaultClient().Result; + using var client = await CreateDefaultClient(); var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase @@ -74,26 +100,23 @@ namespace Timeline.Tests.IntegratedTests options.Converters.Add(new JsonDateTimeConverter()); foreach (var user in users) { - var s = client.GetStringAsync($"/users/{user.Username}").Result; + var s = await client.GetStringAsync($"/users/{user.Username}"); userInfoList.Add(JsonSerializer.Deserialize(s, options)); } UserInfos = userInfoList; } + + await OnInitializeAsync(); + } + + public async Task DisposeAsync() + { + await OnDisposeAsync(); + OnDispose(); + await TestApp.DisposeAsync(); } - protected virtual void OnDispose() - { - } - - public void Dispose() - { - OnDispose(); - TestApp.Dispose(); - } - - public IReadOnlyList UserInfos { get; } - public Task CreateDefaultClient() { return Task.FromResult(Factory.CreateDefaultClient()); @@ -128,6 +151,6 @@ namespace Timeline.Tests.IntegratedTests public Task CreateClientAsUser() { return CreateClientAs(1); - } + } } } diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 8801a3ef..69a04003 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -43,7 +43,11 @@ namespace Timeline.Tests.IntegratedTests public TimelineTest(WebApplicationFactory factory) : base(factory, 3) { - CreateTestTimelines().Wait(); + } + + protected override async Task OnInitializeAsync() + { + await CreateTestTimelines(); } private List _testTimelines; -- cgit v1.2.3 From 70af7808deca84ad2d118c5002989a98e1623450 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 23:21:37 +0800 Subject: Add links test for timeline. --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 36 +++++++++++++++++----- .../Helpers/StringLocalizerFactoryExtensions.cs | 19 ------------ 2 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 Timeline/Helpers/StringLocalizerFactoryExtensions.cs (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 69a04003..215dcf17 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -98,16 +98,36 @@ namespace Timeline.Tests.IntegratedTests } [Fact] - public async Task Personal_TimelineGet_Should_Work() + public async Task TimelineGet_Should_Work() { using var client = await CreateDefaultClient(); - var res = await client.GetAsync("timelines/@user1"); - var body = res.Should().HaveStatusCode(200) - .And.HaveJsonBody().Which; - body.Owner.Should().BeEquivalentTo(UserInfos[1]); - body.Visibility.Should().Be(TimelineVisibility.Register); - body.Description.Should().Be(""); - body.Members.Should().NotBeNull().And.BeEmpty(); + { + var res = await client.GetAsync("timelines/@user1"); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody().Which; + body.Owner.Should().BeEquivalentTo(UserInfos[1]); + body.Visibility.Should().Be(TimelineVisibility.Register); + body.Description.Should().Be(""); + body.Members.Should().NotBeNull().And.BeEmpty(); + var links = body._links; + links.Should().NotBeNull(); + links.Self.Should().EndWith("/timelines/@user1"); + links.Posts.Should().EndWith("/timelines/@user1/posts"); + } + + { + var res = await client.GetAsync("timelines/t1"); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody().Which; + body.Owner.Should().BeEquivalentTo(UserInfos[1]); + body.Visibility.Should().Be(TimelineVisibility.Register); + body.Description.Should().Be(""); + body.Members.Should().NotBeNull().And.BeEmpty(); + var links = body._links; + links.Should().NotBeNull(); + links.Self.Should().EndWith("/timelines/t1"); + links.Posts.Should().EndWith("/timelines/t1/posts"); + } } [Fact] diff --git a/Timeline/Helpers/StringLocalizerFactoryExtensions.cs b/Timeline/Helpers/StringLocalizerFactoryExtensions.cs deleted file mode 100644 index c2252b2c..00000000 --- a/Timeline/Helpers/StringLocalizerFactoryExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ - -using Microsoft.Extensions.Localization; -using System.Reflection; - -namespace Timeline.Helpers -{ - internal static class StringLocalizerFactoryExtensions - { - internal static IStringLocalizer Create(this IStringLocalizerFactory factory, string basename) - { - return factory.Create(basename, new AssemblyName(typeof(StringLocalizerFactoryExtensions).Assembly.FullName!).Name); - } - - internal static StringLocalizer Create(this IStringLocalizerFactory factory) - { - return new StringLocalizer(factory); - } - } -} \ No newline at end of file -- cgit v1.2.3 From dfe715cec705c31b87f808b09c9fa1cb61e6583e Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 12 Mar 2020 19:12:15 +0800 Subject: Add integrated tests for image post. --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 116 ++++++++++++++++++++++++- Timeline/Controllers/TimelineController.cs | 2 +- 2 files changed, 116 insertions(+), 2 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 215dcf17..682cfd7c 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -1,11 +1,16 @@ using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Png; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Timeline.Entities; using Timeline.Models; using Timeline.Models.Http; using Timeline.Tests.Helpers; @@ -882,7 +887,7 @@ namespace Timeline.Tests.IntegratedTests [Theory] [MemberData(nameof(TimelineUrlGeneratorData))] - public async Task Post_Op_Should_Work(Func generator) + public async Task TextPost_ShouldWork(Func generator) { { using var client = await CreateClientAsUser(); @@ -1029,5 +1034,114 @@ namespace Timeline.Tests.IntegratedTests res.Should().BeInvalidModel(); } } + + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task ImagePost_ShouldWork(Func generator) + { + var imageData = ImageHelper.CreatePngWithSize(100, 200); + + long postId; + string postImageUrl; + + void AssertPostContent(TimelinePostContentInfo content) + { + content.Type.Should().Be(TimelinePostContentTypes.Image); + content.Url.Should().EndWith(generator(1, $"posts/{postId}/data")); + content.Text.Should().Be(null); + } + + using var client = await CreateClientAsUser(); + + { + var res = await client.PostAsJsonAsync(generator(1, "posts"), + new TimelinePostCreateRequest + { + Content = new TimelinePostCreateRequestContent + { + Type = TimelinePostContentTypes.Image, + Data = Convert.ToBase64String(imageData) + } + }); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody().Which; + postId = body.Id; + postImageUrl = body.Content.Url; + AssertPostContent(body.Content); + } + + { + var res = await client.GetAsync(generator(1, "posts")); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody().Which; + body.Should().HaveCount(1); + var post = body[0]; + post.Id.Should().Be(postId); + AssertPostContent(post.Content); + } + + { + var res = await client.GetAsync(generator(1, $"posts/{postId}/data")); + res.Content.Headers.ContentType.MediaType.Should().Be("image/png"); + var data = await res.Content.ReadAsByteArrayAsync(); + var image = Image.Load(data, out var format); + image.Width.Should().Be(100); + image.Height.Should().Be(200); + format.Name.Should().Be(PngFormat.Instance.Name); + } + + { + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); + res.Should().BeDelete(true); + } + + { + var res = await client.DeleteAsync(generator(1, $"posts/{postId}")); + res.Should().BeDelete(false); + } + + { + var res = await client.GetAsync(generator(1, "posts")); + res.Should().HaveStatusCode(200) + .And.HaveJsonBody() + .Which.Should().BeEmpty(); + } + + { + using var scope = TestApp.Factory.Services.CreateScope(); + var database = scope.ServiceProvider.GetRequiredService(); + var count = await database.Data.CountAsync(); + count.Should().Be(0); + } + } + + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task ImagePost_400(Func generator) + { + using var client = await CreateClientAsUser(); + + { + var res = await client.GetAsync(generator(1, "posts/11234/data")); + res.Should().HaveStatusCode(404) + .And.HaveCommonBody(ErrorCodes.TimelineController.PostNotExist); + } + + long postId; + { + var res = await client.PostAsJsonAsync(generator(1, "posts"), + TimelineHelper.TextPostCreateRequest("aaa")); + var body = res.Should().HaveStatusCode(200) + .And.HaveJsonBody() + .Which; + postId = body.Id; + } + + { + var res = await client.GetAsync(generator(1, $"posts/{postId}/data")); + res.Should().HaveStatusCode(400) + .And.HaveCommonBody(ErrorCodes.TimelineController.PostNoData); + } + } } } diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 6e5438c4..58390c29 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -126,7 +126,7 @@ namespace Timeline.Controllers try { var data = await _service.GetPostData(name, id); - return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue($"\"{data.ETag}\"")); } catch (TimelinePostNotExistException) { -- cgit v1.2.3