From b0db67f87baa1edf556fa4592d4e41e4f5058b30 Mon Sep 17 00:00:00 2001 From: Valerii Dekhtiuk Date: Mon, 18 Dec 2023 23:58:17 +0200 Subject: [PATCH] Add some corrections --- .../appsettings.IntegrationTests.json | 4 +- .../Streetcode.WebApi/appsettings.Local.json | 3 +- Streetcode/Streetcode.WebApi/appsettings.json | 3 +- .../Update/StreetcodeUpdateControllerTests.cs | 151 ------------------ .../Streetcode/ExtractTestUpdateStreetcode.cs | 56 ------- .../Streetcode.XIntegrationTest.csproj | 4 + 6 files changed, 7 insertions(+), 214 deletions(-) delete mode 100644 Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Update/StreetcodeUpdateControllerTests.cs delete mode 100644 Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestUpdateStreetcode.cs diff --git a/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json b/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json index 384688a80..53cd46a8b 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json +++ b/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json @@ -1,8 +1,6 @@ { "ConnectionStrings": { - //"DefaultConnection": "Server=DESKTOP-I7Q35NQ\\SQLEXPRESS;Database=StreetcodeDbtest;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true;TrustServerCertificate=true" - - "DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDbtest;Integrated Security=True" + "DefaultConnection": "Server=DESKTOP-I7Q35NQ\\SQLEXPRESS;Database=StreetcodeDbtest;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true;TrustServerCertificate=true" }, "Blob": { "BlobStoreKey": "BigThirtyTwoBiteCoolTestKeyCrypt", diff --git a/Streetcode/Streetcode.WebApi/appsettings.Local.json b/Streetcode/Streetcode.WebApi/appsettings.Local.json index 469b824dc..0fe7bd709 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.Local.json +++ b/Streetcode/Streetcode.WebApi/appsettings.Local.json @@ -1,7 +1,6 @@ { "ConnectionStrings": { - // "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" - "DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDbtest;Integrated Security=True" + "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" }, "CORS": { "AllowedOrigins": [ "http://localhost:3000" ], diff --git a/Streetcode/Streetcode.WebApi/appsettings.json b/Streetcode/Streetcode.WebApi/appsettings.json index 1e6c1d2c4..73350553e 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.json +++ b/Streetcode/Streetcode.WebApi/appsettings.json @@ -1,7 +1,6 @@ { "ConnectionStrings": { - // "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" - "DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=StreetcodeDbtest;Integrated Security=True" + "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" }, "EmailConfiguration": { "From": "streetcodefordev@gmail.com", diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Update/StreetcodeUpdateControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Update/StreetcodeUpdateControllerTests.cs deleted file mode 100644 index 1349106c1..000000000 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Update/StreetcodeUpdateControllerTests.cs +++ /dev/null @@ -1,151 +0,0 @@ -using Streetcode.BLL.DTO.AdditionalContent.Subtitles; -using Streetcode.BLL.DTO.AdditionalContent.Tag; -using Streetcode.BLL.DTO.Analytics.Update; -using Streetcode.BLL.DTO.Media.Art; -using Streetcode.BLL.DTO.Media.Audio; -using Streetcode.BLL.DTO.Media.Images; -using Streetcode.BLL.DTO.Media.Video; -using Streetcode.BLL.DTO.Partners.Update; -using Streetcode.BLL.DTO.Sources.Update; -using Streetcode.BLL.DTO.Streetcode.RelatedFigure; -using Streetcode.BLL.DTO.Streetcode.TextContent.Fact; -using Streetcode.BLL.DTO.Streetcode.Update; -using Streetcode.BLL.DTO.Timeline.Update; -using Streetcode.BLL.DTO.Toponyms; -using Streetcode.BLL.Enums; -using Streetcode.DAL.Entities.Streetcode; -using Streetcode.XIntegrationTest.ControllerTests.Utils; -using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; -using System.Net; -using Xunit; - -namespace Streetcode.XIntegrationTest.ControllerTests.Streetcode.Update -{ - public class StreetcodeUpdateControllerTests : - BaseControllerTests, IClassFixture> - { - public StreetcodeUpdateControllerTests(CustomWebApplicationFactory factory) - : base(factory, "/api/Streetcode") - { - - } - - [Fact] - [ExtractTestUpdateStreetcode] - public async Task Update_ReturnSuccessStatusCode() - { - StreetcodeContent expectedStreetcode = ExtractTestUpdateStreetcode.StreetcodeForTest; - - var updateStreetCodeDTO = CreateMoqStreetCodeDTO( - expectedStreetcode.Id, - expectedStreetcode.Index, - expectedStreetcode.TransliterationUrl); - var response = await client.UpdateAsync(updateStreetCodeDTO); - - Assert.True(response.IsSuccessStatusCode); - } - - [Fact] - [ExtractTestUpdateStreetcode] - public async Task Update_ChangesTitleAndTransliterationUrl() - { - StreetcodeContent expectedStreetcode = ExtractTestUpdateStreetcode.StreetcodeForTest; - - var updateStreetCodeDTO = CreateMoqStreetCodeDTO( - expectedStreetcode.Id, - expectedStreetcode.Index, - expectedStreetcode.TransliterationUrl); - await client.UpdateAsync(updateStreetCodeDTO); - - var responseGetByIdUpdated = await client.GetByIdAsync(expectedStreetcode.Id); - var streetCodeContent = CaseIsensitiveJsonDeserializer.Deserialize(responseGetByIdUpdated.Content); - Assert.Multiple(() => - { - Assert.Equal(updateStreetCodeDTO.Title, streetCodeContent.Title); - Assert.Equal(updateStreetCodeDTO.DateString, streetCodeContent.DateString); - }); - } - - [Fact] - [ExtractTestUpdateStreetcode] - public async Task Update_WithInvalidId_ReturnsBadRequest() - { - - StreetcodeContent expectedStreetcode = ExtractTestUpdateStreetcode.StreetcodeForTest; - var updateStreetCodeDTO = CreateMoqStreetCodeDTO( - expectedStreetcode.Id + 1, - expectedStreetcode.Index, - expectedStreetcode.TransliterationUrl); - var response = await client.UpdateAsync(updateStreetCodeDTO); - - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - - [Fact] - [ExtractTestUpdateStreetcode] - public async Task Update_WithInvalidData_ReturnsBadRequest() - { - StreetcodeContent expectedStreetcode = ExtractTestUpdateStreetcode.StreetcodeForTest; - var updateStreetCodeDTO = CreateMoqStreetCodeDTO( - expectedStreetcode.Id, - expectedStreetcode.Index, - expectedStreetcode.TransliterationUrl); - updateStreetCodeDTO.Title = null; // Invalid data - var response = await client.UpdateAsync(updateStreetCodeDTO); - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - - [Fact] - [ExtractTestUpdateStreetcode] - public async Task Update_WithInvalidTags_ReturnsBadRequest() - { - StreetcodeContent expectedStreetcode = ExtractTestUpdateStreetcode.StreetcodeForTest; - var updateStreetCodeDTO = CreateMoqStreetCodeDTO( - expectedStreetcode.Id, - expectedStreetcode.Index, - expectedStreetcode.TransliterationUrl); - - // Invalid tag data - updateStreetCodeDTO.Tags = new List - { - new StreetcodeTagUpdateDTO - { - Id = 9999, // Non-existent tag ID - Title = "Invalid Tag", - IsVisible = true, - Index = 0, - StreetcodeId = expectedStreetcode.Id, - ModelState = ModelState.Updated - }, - }; - - var response = await client.UpdateAsync(updateStreetCodeDTO); - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - - private StreetcodeUpdateDTO CreateMoqStreetCodeDTO(int id, int index, string transliterationUrl ) - { - return new StreetcodeUpdateDTO - { - Id = id, - Index = index, - Title = "New Title", - TransliterationUrl = transliterationUrl, - Tags = new List(), - Facts = new List(), - Audios = new List(), - Images = new List(), - Videos = new List(), - Partners = new List(), - Toponyms = new List(), - Subtitles = new List(), - DateString = "22 травня 2023", - TimelineItems = new List(), - RelatedFigures = new List(), - StreetcodeArts = new List(), - StatisticRecords = new List(), - StreetcodeCategoryContents = new List(), - }; - } - } -} diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestUpdateStreetcode.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestUpdateStreetcode.cs deleted file mode 100644 index 8e0f5b71a..000000000 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestUpdateStreetcode.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Streetcode.DAL.Entities.Streetcode; -using System.Reflection; -using Xunit.Sdk; - -namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - class ExtractTestUpdateStreetcode : BeforeAfterTestAttribute - { - public static StreetcodeContent StreetcodeForTest; - - public override void Before(MethodInfo methodUnderTest) - { - var sqlDbHelper = BaseControllerTests.GetSqlDbHelper(); - StreetcodeForTest = sqlDbHelper.GetExistItem(); - if (StreetcodeForTest == null) - { - StreetcodeForTest = sqlDbHelper.AddNewItem(new StreetcodeContent() - { - Index = new Random().Next(0, 1000000), - UpdatedAt = DateTime.Now, - CreatedAt = DateTime.Now, - EventStartOrPersonBirthDate = DateTime.Now, - EventEndOrPersonDeathDate = DateTime.Now, - ViewCount = 1, - DateString = "20 травня 2023", - Alias = "dsf", - Title = "Title", - TransliterationUrl = Guid.NewGuid().ToString(), - Teaser = "Test Teaser", - }); - sqlDbHelper.SaveChanges(); - } - } - - public override void After(MethodInfo methodUnderTest) - { - var sqlDbHelper = BaseControllerTests.GetSqlDbHelper(); - var streetcodeContent = sqlDbHelper.GetExistItem(); - if (streetcodeContent != null) - { - // Restore the original StreetcodeContent - streetcodeContent.EventStartOrPersonBirthDate = StreetcodeForTest.EventStartOrPersonBirthDate; - streetcodeContent.EventEndOrPersonDeathDate = StreetcodeForTest.EventEndOrPersonDeathDate; - streetcodeContent.ViewCount = StreetcodeForTest.ViewCount; - streetcodeContent.DateString = StreetcodeForTest.DateString; - streetcodeContent.Alias = StreetcodeForTest.Alias; - streetcodeContent.Title = StreetcodeForTest.Title; - streetcodeContent.TransliterationUrl = StreetcodeForTest.TransliterationUrl; - streetcodeContent.Teaser = StreetcodeForTest.Teaser; - - sqlDbHelper.SaveChanges(); - } - } - } -} diff --git a/Streetcode/Streetcode.XIntegrationTest/Streetcode.XIntegrationTest.csproj b/Streetcode/Streetcode.XIntegrationTest/Streetcode.XIntegrationTest.csproj index 9e022df0c..460f80ab3 100644 --- a/Streetcode/Streetcode.XIntegrationTest/Streetcode.XIntegrationTest.csproj +++ b/Streetcode/Streetcode.XIntegrationTest/Streetcode.XIntegrationTest.csproj @@ -51,4 +51,8 @@ + + + +