diff --git a/DeleteTextTest.cs b/DeleteTextTest.cs deleted file mode 100644 index 5bec1a065..000000000 --- a/DeleteTextTest.cs +++ /dev/null @@ -1,38 +0,0 @@ -using AutoMapper; -using Microsoft.EntityFrameworkCore.Query; -using Moq; -using Streetcode.BLL.MediatR.Streetcode.Text.Delete; -using Streetcode.DAL.Entities.Streetcode.TextContent; -using Streetcode.DAL.Repositories.Interfaces.Base; -using System.Linq.Expressions; -using Xunit; - -namespace Streetcode.XUnitTest.StreetcodeTest.TextTest -{ - public class DeleteTextTest - { - [Theory] - [InlineData(1)] - public async Task DeleteTextSuccessfull(int id) - { - var repository = new Mock(); - var mockMapper = new Mock(); - - repository.Setup(x => x.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny,IIncludableQueryable>>())) - .ReturnsAsync(new Text { Id= id }); - - repository.Setup(x => x.TextRepository.Delete(new Text() - { Id = id })); - - var handler = new DeleteTextHandler(repository.Object); - - var result = await handler.Handle(new DeleteTextCommand(id), CancellationToken.None); - - Assert.NotNull(result); - Assert.True(result.IsSuccess); - - } - - } -} diff --git a/GetAllTextsTest.cs b/GetAllTextsTest.cs deleted file mode 100644 index 23f0ddf4c..000000000 --- a/GetAllTextsTest.cs +++ /dev/null @@ -1,72 +0,0 @@ -using AutoMapper; -using Microsoft.EntityFrameworkCore.Query; -using Moq; -using Streetcode.BLL.DTO.Streetcode.TextContent; -using Streetcode.BLL.MediatR.Streetcode.Text.GetAll; -using Streetcode.DAL.Entities.Streetcode.TextContent; -using Streetcode.DAL.Repositories.Interfaces.Base; -using System.Linq.Expressions; -using Xunit; - -namespace Streetcode.XUnitTest.StreetcodeTest.TextTest -{ - public class GetAllTextsTest - { - [Fact] - public async Task GetAlltextsSuccess() - { - var repository = new Mock(); - var mockMapper = new Mock(); - - var testTextsList = new List() - { - new Text() { Id = 1 } - }; - - var testTextslistDTO = new List() - { - new TextDTO() { Id = 1 } - }; - - var testTexts = new Text() { Id = 1 }; - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync(testTexts); - - repository.Setup(repo => repo.TextRepository.GetAllAsync(null, null)).ReturnsAsync(testTextsList); - - mockMapper.Setup(x => x.Map>(It.IsAny>())).Returns(testTextslistDTO); - - var handler = new GetAllTextsHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetAllTextsQuery(), CancellationToken.None); - - Assert.NotNull(result); - Assert.NotEmpty(result.Value); - } - - [Fact] - public async Task GetAllTextsError() - { - var repository = new Mock(); - var mockMapper = new Mock(); - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync((Text)null); - - repository.Setup(repo => repo.TextRepository.GetAllAsync(null, null)).ReturnsAsync((List)null); - - mockMapper.Setup(x => x.Map>(It.IsAny>())).Returns(new List() { new TextDTO() { Id = 1 } }); - - var handler = new GetAllTextsHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetAllTextsQuery(), CancellationToken.None); - - Assert.NotNull(result); - } -} - -} - - diff --git a/GetStreetcodeArtByStreetcodeIdTest.cs b/GetStreetcodeArtByStreetcodeIdTest.cs deleted file mode 100644 index 20a24cafa..000000000 --- a/GetStreetcodeArtByStreetcodeIdTest.cs +++ /dev/null @@ -1,157 +0,0 @@ -using AutoMapper; -using FluentResults; -using Microsoft.EntityFrameworkCore.Query; -using Moq; -using Streetcode.BLL.DTO.Media.Images; -using Streetcode.BLL.MediatR.Media.StreetcodeArt.GetByStreetcodeId; -using Streetcode.DAL.Entities.Media.Images; -using Streetcode.DAL.Entities.Streetcode; -using Streetcode.DAL.Repositories.Interfaces.Base; -using System.Linq.Expressions; -using Xunit; - -namespace Streetcode.XUnitTest.MediaRTests.MediaTests.StreetcodeArtTest -{ - public class GetStreetcodeArtByStreetcodeIdTest - { - private Mock repository; - private Mock mockMapper; - - public GetStreetcodeArtByStreetcodeIdTest() - { - repository = new Mock(); - mockMapper = new Mock(); - } - - [Theory] - [InlineData(1)] - - public async Task GetStreetcodeArtByStreetcodeId_ReturnsCorrectStreetcodeArtByStreetcodeId(int streetcodeId) - { - var allStreetcodeArtsList = new List() - { - new StreetcodeArt() - { - Index = 1, - StreetcodeId = 1, - Streetcode = null, - ArtId = 1, - Art=null - - }, - - new StreetcodeArt() - { - Index = 2, - StreetcodeId = 2, - Streetcode = null, - ArtId = 2, - Art=null - } - }; - - var allStreetcodeArtsDTOList = new List() - { - new StreetcodeArtDTO - { - Index = 1, - StreetcodeId = 1, - Streetcode = null, - ArtId = 1, - Art=null - }, - - new StreetcodeArtDTO - { - Index = 2, - StreetcodeId = 2, - Streetcode = null, - ArtId = 2, - Art=null - } - }; - - repository.Setup(r => r.StreetcodeArtRepository.GetAllAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>>())) - .ReturnsAsync(allStreetcodeArtsList); - - mockMapper.Setup(x => x.Map>(It.IsAny>())).Returns(allStreetcodeArtsDTOList); - - var handler = new GetStreetcodeArtByStreetcodeIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetStreetcodeArtByStreetcodeIdQuery(streetcodeId), CancellationToken.None); - - Assert.Equal(streetcodeId, result.Value.First().ArtId); - - } - - [Theory] - [InlineData(1)] - - public async Task GetStreetcodeArtByStreetcodeId_ReturnCorrectTypeResult(int streetcodeId) - { - var allStreetcodeArtsList = new List() - { - new StreetcodeArt() - { - Index = 1, - StreetcodeId = 1, - Streetcode = null, - ArtId = 1, - Art=null - - }, - - new StreetcodeArt() - { - Index = 2, - StreetcodeId = 2, - Streetcode = null, - ArtId = 2, - Art=null - } - }; - - var allStreetcodeArtsDTOList = new List() - { - new StreetcodeArtDTO - { - Index = 1, - StreetcodeId = 1, - Streetcode = null, - ArtId = 1, - Art=null - }, - - new StreetcodeArtDTO - { - Index = 2, - StreetcodeId = 2, - Streetcode = null, - ArtId = 2, - Art=null - } - }; - - repository.Setup(r => r.StreetcodeArtRepository.GetAllAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>>())) - .ReturnsAsync(allStreetcodeArtsList); - - mockMapper.Setup(x => x.Map>(It.IsAny>())).Returns(allStreetcodeArtsDTOList); - - var handler = new GetStreetcodeArtByStreetcodeIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetStreetcodeArtByStreetcodeIdQuery(streetcodeId), CancellationToken.None); - - Assert.IsType>>(result); - - } - - } - -} - - - - - diff --git a/GetTextByIdTest.cs b/GetTextByIdTest.cs deleted file mode 100644 index 06d85a71e..000000000 --- a/GetTextByIdTest.cs +++ /dev/null @@ -1,68 +0,0 @@ -using AutoMapper; -using Microsoft.EntityFrameworkCore.Query; -using Moq; -using Streetcode.BLL.DTO.Streetcode.TextContent; -using Streetcode.BLL.MediatR.Streetcode.Text.GetById; -using Streetcode.DAL.Entities.Streetcode.TextContent; -using Streetcode.DAL.Repositories.Interfaces.Base; -using System.Linq.Expressions; -using Xunit; - -namespace Streetcode.XUnitTest.StreetcodeTest.TextTest -{ - public class GetTextByIdTest - { - [Theory] - [InlineData(2)] - public async Task GetTextByIdSuccess(int id) - { - var repository = new Mock(); - var mockMapper = new Mock(); - - var testText = new Text() { Id = id }; - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync(testText); - - mockMapper.Setup(x => x.Map(It.IsAny())).Returns((Text sourceText) => - { - return new TextDTO { Id = sourceText.Id }; - }); - var handler = new GetTextByIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetTextByIdQuery(id), CancellationToken.None); - - Assert.NotNull(result); - Assert.Equal(id, result.Value.Id); - } - - [Theory] - [InlineData(1)] - public async Task GetTextByIdTypeCheck(int id) - { - var repository = new Mock(); - var mockMapper = new Mock(); - - var testText = new Text() { Id = id }; - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync(testText); - - mockMapper.Setup(x => x.Map(It.IsAny())).Returns((Text sourceText) => - { - return new TextDTO { Id = sourceText.Id }; - }); - - var handler = new GetTextByIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetTextByIdQuery(2), CancellationToken.None); - - Assert.NotNull(result); - Assert.True(result.IsSuccess); - Assert.IsAssignableFrom(result.Value); - - } - } -} \ No newline at end of file diff --git a/GetTextByStreetcodeIdTest.cs b/GetTextByStreetcodeIdTest.cs deleted file mode 100644 index e60acf551..000000000 --- a/GetTextByStreetcodeIdTest.cs +++ /dev/null @@ -1,76 +0,0 @@ -using AutoMapper; -using Microsoft.EntityFrameworkCore.Query; -using Moq; -using Streetcode.BLL.DTO.Media.Images; -using Streetcode.BLL.DTO.Streetcode.TextContent; -using Streetcode.BLL.MediatR.Media.StreetcodeArt.GetByStreetcodeId; -using Streetcode.BLL.MediatR.Streetcode.Text.GetById; -using Streetcode.BLL.MediatR.Streetcode.Text.GetByStreetcodeId; -using Streetcode.DAL.Entities.Streetcode; -using Streetcode.DAL.Entities.Streetcode.TextContent; -using Streetcode.DAL.Repositories.Interfaces.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; -using Xunit; - -namespace Streetcode.XUnitTest.StreetcodeTest.TextTest -{ - public class GetTextByStreetcodeIdTest - { - - [Theory] - [InlineData(1)] - public async Task GetTextByStreetcodeIdSuccess(int id) - { - var repository = new Mock(); - var mockMapper = new Mock(); - - var testText = new Text() { StreetcodeId = id }; - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync(testText); - - mockMapper.Setup(x => x.Map(It.IsAny())).Returns((Text sourceText) => - { - return new TextDTO { StreetcodeId = sourceText.StreetcodeId }; - }); - var handler = new GetTextByIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetTextByIdQuery(id), CancellationToken.None); - - Assert.NotNull(result); - Assert.Equal(id, result.Value.StreetcodeId); - } - - [Theory] - [InlineData(1)] - public async Task GetTextByStreetcodeIdTypeCheck(int id) - { - var repository = new Mock(); - var mockMapper = new Mock(); - - var testText = new Text() { StreetcodeId = id }; - - repository.Setup(repo => repo.TextRepository.GetFirstOrDefaultAsync(It.IsAny>>(), - It.IsAny, IIncludableQueryable>?>())) - .ReturnsAsync(testText); - - mockMapper.Setup(x => x.Map(It.IsAny())).Returns((Text sourceText) => - { - return new TextDTO { StreetcodeId = sourceText.StreetcodeId }; - }); - - var handler = new GetTextByIdHandler(repository.Object, mockMapper.Object); - - var result = await handler.Handle(new GetTextByIdQuery(id), CancellationToken.None); - - Assert.NotNull(result); - Assert.IsType(result.ValueOrDefault); - } - } -} diff --git a/Logo-1.png b/Logo-1.png deleted file mode 100644 index d54149c52..000000000 Binary files a/Logo-1.png and /dev/null differ diff --git a/StreerCodeLogo2.jpg b/StreerCodeLogo2.jpg deleted file mode 100644 index 760f5e265..000000000 Binary files a/StreerCodeLogo2.jpg and /dev/null differ diff --git a/StreetCodeLogo.jpg b/StreetCodeLogo.jpg deleted file mode 100644 index d23ac6e93..000000000 Binary files a/StreetCodeLogo.jpg and /dev/null differ diff --git a/Streetcode/Streetcode.BLL/Interfaces/Logging/ILoggerService.cs b/Streetcode/Streetcode.BLL/Interfaces/Logging/ILoggerService.cs index 37e66ffa3..ba3df5bea 100644 --- a/Streetcode/Streetcode.BLL/Interfaces/Logging/ILoggerService.cs +++ b/Streetcode/Streetcode.BLL/Interfaces/Logging/ILoggerService.cs @@ -8,4 +8,4 @@ public interface ILoggerService void LogDebug(string msg); void LogError(object request, string errorMsg); } -} +} \ No newline at end of file diff --git a/Streetcode/Streetcode.BLL/MediatR/Streetcode/Streetcode/GetByFilter/GetStreetcodeByFilterHandler.cs b/Streetcode/Streetcode.BLL/MediatR/Streetcode/Streetcode/GetByFilter/GetStreetcodeByFilterHandler.cs index f37eba5dd..0e2344caf 100644 --- a/Streetcode/Streetcode.BLL/MediatR/Streetcode/Streetcode/GetByFilter/GetStreetcodeByFilterHandler.cs +++ b/Streetcode/Streetcode.BLL/MediatR/Streetcode/Streetcode/GetByFilter/GetStreetcodeByFilterHandler.cs @@ -26,6 +26,7 @@ public GetStreetcodeByFilterHandler(IRepositoryWrapper repositoryWrapper, ILogge public async Task>> Handle(GetStreetcodeByFilterQuery request, CancellationToken cancellationToken) { string searchQuery = request.Filter.SearchQuery; + searchQuery = searchQuery.Trim(); var results = new List(); diff --git a/Streetcode/Streetcode.BLL/Middleware/ApiRequestResponseMiddleware.cs b/Streetcode/Streetcode.BLL/Middleware/ApiRequestResponseMiddleware.cs new file mode 100644 index 000000000..4e3b6fd0e --- /dev/null +++ b/Streetcode/Streetcode.BLL/Middleware/ApiRequestResponseMiddleware.cs @@ -0,0 +1,145 @@ +using System.Reflection; +using System.Text; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.IdentityModel.Tokens; +using Newtonsoft.Json.Linq; + +namespace Streetcode.BLL.Middleware +{ + public class ApiRequestResponseMiddleware + { + private readonly RequestDelegate _next; + private readonly ILogger _loggerService; + private readonly RequestResponseMiddlewareOptions _options; + + public ApiRequestResponseMiddleware(RequestDelegate next, ILogger loggerService, IOptions options) + { + _loggerService = loggerService; + _options = options.Value; + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + var request = await GetRequestAsTextAsync(context.Request); + var requestTemplate = + $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}{Environment.NewLine}"; + requestTemplate += request.IsNullOrEmpty() ? "Request body is empty" : $"Request body: {request}"; + requestTemplate += $"{Environment.NewLine}"; + try + { + var response = await FormatResponseAsync(context, _next); + _loggerService.LogInformation($"{requestTemplate}Response body: {response}"); + } + catch (Exception exception) + { + _loggerService.LogError($"{requestTemplate}An unhandled exception was thrown by the application: {exception}"); + } + } + + private async Task FormatResponseAsync(HttpContext context, RequestDelegate next) + { + var originalBodyStream = context.Response.Body; + await using var responseBody = new MemoryStream(); + context.Response.Body = responseBody; + + await next(context); + + var response = await GetResponseAsTextAsync(context.Response); + var filteredResponse = GetFilteredBody(response); + await responseBody.CopyToAsync(originalBodyStream); + return filteredResponse; + } + + private async Task GetRequestAsTextAsync(HttpRequest request) + { + request.EnableBuffering(); + using var streamReader = new StreamReader(request.Body, leaveOpen: true); + var requestBody = await streamReader.ReadToEndAsync(); + request.Body.Position = 0; + + var filteredBody = GetFilteredBody(requestBody); + + return filteredBody; + } + + private async Task GetResponseAsTextAsync(HttpResponse response) + { + response.Body.Seek(0, SeekOrigin.Begin); + + var encoding = Encoding.UTF8; + + var text = await new StreamReader(response.Body, encoding).ReadToEndAsync(); + + response.Body.Seek(0, SeekOrigin.Begin); + + var filteredBody = GetFilteredBody(text); + + return filteredBody; + } + + private string GetFilteredBody(string body) + { + if (string.IsNullOrWhiteSpace(body)) + { + return string.Empty; + } + + try + { + var jsonObject = JToken.Parse(body); + + if (jsonObject.Type == JTokenType.Array) + { + var jsonArray = (JArray)jsonObject; + + foreach (var item in jsonArray) + { + TruncateProperties(item); + } + } + else if (jsonObject.Type == JTokenType.Object) + { + TruncateProperties(jsonObject); + } + + return jsonObject.ToString(); + } + catch (Exception ex) + { + _loggerService.LogError($"Unexpected error occured in {MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}. Tried to parse body: {body}. Exception: {ex}"); + return string.Empty; + } + } + + private void TruncateProperties(JToken token) + { + foreach (var property in token.Children().ToList()) + { + if (_options.PropertiesToIgnore.Contains(property.Name.ToLower())) + { + property.Remove(); + continue; + } + + var valueType = property.Value.Type; + + if (valueType == JTokenType.Object || valueType == JTokenType.Array) + { + TruncateProperties(property.Value); + continue; + } + + var valueAsString = property.Value.ToString(); + var valueLength = valueAsString.Length; + + if (valueLength > _options.MaxResponseLength) + { + property.Value = new JValue(valueAsString.Substring(0, _options.MaxResponseLength) + "..."); + } + } + } + } +} diff --git a/Streetcode/Streetcode.BLL/Middleware/MiddlewareExtension.cs b/Streetcode/Streetcode.BLL/Middleware/MiddlewareExtension.cs new file mode 100644 index 000000000..793faa92c --- /dev/null +++ b/Streetcode/Streetcode.BLL/Middleware/MiddlewareExtension.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; + +namespace Streetcode.BLL.Middleware +{ + public static class MiddlewareExtension + { + public static IApplicationBuilder UseRequestResponseMiddleware(this IApplicationBuilder app) + { + return app.UseMiddleware(); + } + } +} diff --git a/Streetcode/Streetcode.BLL/Middleware/RequestResponseMiddlewareOptions.cs b/Streetcode/Streetcode.BLL/Middleware/RequestResponseMiddlewareOptions.cs new file mode 100644 index 000000000..655444699 --- /dev/null +++ b/Streetcode/Streetcode.BLL/Middleware/RequestResponseMiddlewareOptions.cs @@ -0,0 +1,8 @@ +namespace Streetcode.BLL.Middleware +{ + public class RequestResponseMiddlewareOptions + { + public int MaxResponseLength { get; set; } + public List PropertiesToIgnore { get; set; } + } +} diff --git a/Streetcode/Streetcode.BLL/Services/AudioService/AudioService.cs b/Streetcode/Streetcode.BLL/Services/AudioService/AudioService.cs index e96a8dcd0..a1195a21a 100644 --- a/Streetcode/Streetcode.BLL/Services/AudioService/AudioService.cs +++ b/Streetcode/Streetcode.BLL/Services/AudioService/AudioService.cs @@ -1,9 +1,7 @@ -using Repositories.Interfaces; using Streetcode.BLL.Interfaces.Audio; using Streetcode.BLL.Interfaces.BlobStorage; using Streetcode.BLL.Interfaces.Logging; using Streetcode.DAL.Repositories.Interfaces.Base; -using Streetcode.DAL.Repositories.Interfaces.Streetcode; namespace Streetcode.BLL.Services.AudioService; @@ -27,8 +25,7 @@ public async Task CleanUnusedAudiosAsync() var referencedAudioIds = _repositoryWrapper.StreetcodeRepository .FindAll() .Where(streetcode => streetcode.AudioId.HasValue) - .Select(streetcode => streetcode.AudioId.Value) - .ToList(); + .Select(streetcode => streetcode.AudioId.Value); var unreferencedAudios = _repositoryWrapper.AudioRepository .FindAll(audio => !referencedAudioIds.Contains(audio.Id)) @@ -36,23 +33,19 @@ public async Task CleanUnusedAudiosAsync() _loggerService.LogInformation("Starting deleting this audios:"); - foreach (var audio in unreferencedAudios) - { - _loggerService.LogInformation(audio.BlobName); - } - if (unreferencedAudios.Any()) { foreach (var audio in unreferencedAudios) { - _blobService.DeleteFileInStorage(audio.BlobName); + _loggerService.LogInformation(audio.BlobName!); + _blobService.DeleteFileInStorage(audio.BlobName!); } _repositoryWrapper.AudioRepository.DeleteRange(unreferencedAudios); await _repositoryWrapper.SaveChangesAsync(); } - _loggerService.LogInformation("Deleting completed:"); + _loggerService.LogInformation("Deleting completed."); } catch (Exception e) { diff --git a/Streetcode/Streetcode.BLL/Services/Logging/LoggerService.cs b/Streetcode/Streetcode.BLL/Services/Logging/LoggerService.cs index b3047c7b6..2684d2c61 100644 --- a/Streetcode/Streetcode.BLL/Services/Logging/LoggerService.cs +++ b/Streetcode/Streetcode.BLL/Services/Logging/LoggerService.cs @@ -42,8 +42,8 @@ public void LogError(object request, string erroMsg) } else { - _logger.Error(erroMsg); + _logger.Error(erroMsg); } } } -} +} \ No newline at end of file diff --git a/Streetcode/Streetcode.BLL/Streetcode.BLL.csproj b/Streetcode/Streetcode.BLL/Streetcode.BLL.csproj index f66b7467c..48a256af8 100644 --- a/Streetcode/Streetcode.BLL/Streetcode.BLL.csproj +++ b/Streetcode/Streetcode.BLL/Streetcode.BLL.csproj @@ -26,6 +26,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Streetcode/Streetcode.WebApi/Extensions/ConfigureHostBuilderExtensions.cs b/Streetcode/Streetcode.WebApi/Extensions/ConfigureHostBuilderExtensions.cs index 542357385..1bc9080df 100644 --- a/Streetcode/Streetcode.WebApi/Extensions/ConfigureHostBuilderExtensions.cs +++ b/Streetcode/Streetcode.WebApi/Extensions/ConfigureHostBuilderExtensions.cs @@ -1,5 +1,8 @@ -using AspNetCoreRateLimit; +using System.Runtime; +using Microsoft.Extensions.Configuration; using Serilog; +using Streetcode.BLL.Middleware; +using AspNetCoreRateLimit; using Streetcode.BLL.Services.BlobStorageService; using Streetcode.BLL.Services.Instagram; using Streetcode.BLL.Services.Payment; @@ -35,13 +38,24 @@ public static void ConfigureInstagram(this IServiceCollection services, WebAppli public static void ConfigureSerilog(this IServiceCollection services, WebApplicationBuilder builder) { + var filterExpression = builder.Configuration["Serilog:Filter:ByExcluding"]; + builder.Host.UseSerilog((ctx, services, loggerConfiguration) => { - loggerConfiguration - .ReadFrom.Configuration(builder.Configuration); + loggerConfiguration.ReadFrom.Configuration(builder.Configuration); + + if (!string.IsNullOrEmpty(filterExpression)) + { + loggerConfiguration.Filter.ByExcluding(filterExpression); + } }); } + public static void ConfigureRequestResponseMiddlewareOptions(this IServiceCollection services, WebApplicationBuilder builder) + { + services.Configure(builder.Configuration.GetSection("RequestResponseMiddlewareOptions")); + } + public static void ConfigureRateLimitMiddleware(this IServiceCollection services, WebApplicationBuilder builder) { builder.Services.AddMemoryCache(); diff --git a/Streetcode/Streetcode.WebApi/Extensions/ServiceCollectionExtensions.cs b/Streetcode/Streetcode.WebApi/Extensions/ServiceCollectionExtensions.cs index 9a61405be..82d477128 100644 --- a/Streetcode/Streetcode.WebApi/Extensions/ServiceCollectionExtensions.cs +++ b/Streetcode/Streetcode.WebApi/Extensions/ServiceCollectionExtensions.cs @@ -5,8 +5,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using Streetcode.BLL.Interfaces.Logging; -using Streetcode.BLL.Services.Logging; using Streetcode.DAL.Persistence; using Streetcode.DAL.Repositories.Interfaces.Base; using Streetcode.DAL.Repositories.Realizations.Base; @@ -29,7 +27,9 @@ using Streetcode.BLL.Services.CacheService; using Streetcode.BLL.Interfaces.Cache; using Streetcode.BLL.Interfaces.Image; +using Streetcode.BLL.Interfaces.Logging; using Streetcode.BLL.Services.ImageService; +using Streetcode.BLL.Services.Logging; namespace Streetcode.WebApi.Extensions; @@ -49,12 +49,13 @@ public static void AddCustomServices(this IServiceCollection services) var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies(); services.AddAutoMapper(currentAssemblies); services.AddMediatR(currentAssemblies); + services.AddScoped(); + services.AddSingleton(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -167,4 +168,4 @@ public class CorsConfiguration public List AllowedMethods { get; set; } public int PreflightMaxAge { get; set; } } -} +} \ No newline at end of file diff --git a/Streetcode/Streetcode.WebApi/Program.cs b/Streetcode/Streetcode.WebApi/Program.cs index b36fe685f..b6e759939 100644 --- a/Streetcode/Streetcode.WebApi/Program.cs +++ b/Streetcode/Streetcode.WebApi/Program.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Localization; using Streetcode.BLL.Services.Hangfire; using Microsoft.AspNetCore.HttpOverrides; - +using Streetcode.BLL.Middleware; var builder = WebApplication.CreateBuilder(args); builder.Host.ConfigureApplication(); @@ -18,6 +18,7 @@ builder.Services.ConfigurePayment(builder); builder.Services.ConfigureInstagram(builder); builder.Services.ConfigureSerilog(builder); +builder.Services.ConfigureRequestResponseMiddlewareOptions(builder); builder.Services.ConfigureRateLimitMiddleware(builder); builder.Services.Configure(options => { @@ -57,6 +58,7 @@ app.AddCleanImagesJob(); app.UseCors(); app.UseHttpsRedirection(); +app.UseRequestResponseMiddleware(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); diff --git a/Streetcode/Streetcode.WebApi/Streetcode.WebApi.csproj b/Streetcode/Streetcode.WebApi/Streetcode.WebApi.csproj index c05015e04..dae60bc42 100644 --- a/Streetcode/Streetcode.WebApi/Streetcode.WebApi.csproj +++ b/Streetcode/Streetcode.WebApi/Streetcode.WebApi.csproj @@ -12,6 +12,9 @@ + + + @@ -40,8 +43,10 @@ + + all @@ -71,6 +76,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json b/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json index 53cd46a8b..3d5bd66c6 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json +++ b/Streetcode/Streetcode.WebApi/appsettings.IntegrationTests.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=DESKTOP-I7Q35NQ\\SQLEXPRESS;Database=StreetcodeDbtest;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true;TrustServerCertificate=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 0fe7bd709..14b44479d 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.Local.json +++ b/Streetcode/Streetcode.WebApi/appsettings.Local.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=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.Production.json b/Streetcode/Streetcode.WebApi/appsettings.Production.json index baa45e5c2..5e0310fe3 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.Production.json +++ b/Streetcode/Streetcode.WebApi/appsettings.Production.json @@ -3,7 +3,7 @@ "FrontEnd": "FrontUrl" }, "RecurringJobs": { - "AudioCleaningFrequency": "* * */8 * *", - "ImageCleaningFrequency": "* * */8 * *" + "AudioCleaningFrequency": "0 3 */8 * *", + "ImageCleaningFrequency": "0 3 */8 * *" } } \ No newline at end of file diff --git a/Streetcode/Streetcode.WebApi/appsettings.json b/Streetcode/Streetcode.WebApi/appsettings.json index 73350553e..10253b6c0 100644 --- a/Streetcode/Streetcode.WebApi/appsettings.json +++ b/Streetcode/Streetcode.WebApi/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" + "DefaultConnection": "Server=127.0.0.1;Database=StreetcodeDb;User Id=sa;Password=Admin@1234;MultipleActiveResultSets=true" }, "EmailConfiguration": { "From": "streetcodefordev@gmail.com", @@ -10,6 +10,12 @@ "Username": "streetcodefordev@gmail.com", "Password": "setThroughEnvVar" }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, "Serilog": { "Using": [], "MinimumLevel": { @@ -25,17 +31,42 @@ ], "WriteTo": [ { - "Name": "Console" + "Name": "Console", + "Args": { + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}" + } + } + ], + "Filter": [ + { + "Name": "ByExcluding", + "Args": { + "expression": "EndsWith(RequestPath, '/api/Art/GetAll') or Contains(RequestPath, '/api/Audio/GetById') or Contains(RequestPath, '/api/Audio/GetBaseAudio')" + } } ] }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } + "RequestResponseMiddlewareOptions": { + "MaxResponseLength": 100, + "PropertiesToIgnore": ["token", "password"] }, "AllowedHosts": "*", + "HealthChecksUI": { + "HealthChecks": [ + { + "Name": "StartUpProbe", + "Uri": "https://localhost:5001/healthz" + }, + { + "Name": "ReadinessProbe", + "Uri": "https://localhost:5001/health/ready" + }, + { + "Name": "LivenessProbe", + "Uri": "https://localhost:5001/health/live" + } + ] + }, "Jwt": { "Key": "DhftOS5uphK3vmCJQrexST1RsyjZBjXWRgJMFPU4", "Issuer": "https://localhost:5001/", @@ -73,7 +104,7 @@ ] }, "RecurringJobs": { - "AudioCleaningFrequency": "* 3 * * *", - "ImageCleaningFrequency": "* 3 * * *" + "AudioCleaningFrequency": "0 3 * * *", + "ImageCleaningFrequency": "0 3 * * *" } -} +} \ No newline at end of file diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/CoordinateControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/CoordinateControllerTests.cs index 5f74ab6c9..5986c9ae5 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/CoordinateControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/CoordinateControllerTests.cs @@ -1,10 +1,10 @@ -namespace Streetcode.XIntegrationTest.ControllerTests.AdditionalContent -{ - using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types; - using Streetcode.XIntegrationTest.ControllerTests.Utils; - using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; - using Xunit; +using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types; +using Streetcode.XIntegrationTest.ControllerTests.Utils; +using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; +using Xunit; +namespace Streetcode.XIntegrationTest.ControllerTests.AdditionalContent +{ public class CoordinateControllerTests : BaseControllerTests, IClassFixture> { public CoordinateControllerTests(CustomWebApplicationFactory factory) diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/TagControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/TagControllerTests.cs index e28dfa36b..70515e4f4 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/TagControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/AdditionalContent/TagControllerTests.cs @@ -1,14 +1,14 @@ -namespace Streetcode.XIntegrationTest.ControllerTests.AdditionalContent +using Streetcode.BLL.DTO.AdditionalContent; +using Streetcode.BLL.DTO.AdditionalContent.Tag; +using Streetcode.DAL.Entities.AdditionalContent; +using Streetcode.DAL.Entities.Streetcode.TextContent; +using Streetcode.XIntegrationTest.ControllerTests.Utils; +using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Tag; +using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; +using Xunit; + +namespace Streetcode.XIntegrationTest.ControllerTests.AdditionalContent { - using Streetcode.BLL.DTO.AdditionalContent; - using Streetcode.BLL.DTO.AdditionalContent.Tag; - using Streetcode.DAL.Entities.AdditionalContent; - using Streetcode.DAL.Entities.Streetcode.TextContent; - using Streetcode.XIntegrationTest.ControllerTests.Utils; - using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Tag; - using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; - using Xunit; - public class TagControllerTests : BaseControllerTests, IClassFixture> { public TagControllerTests(CustomWebApplicationFactory factory) diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/BaseControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/BaseControllerTests.cs index b645ddd5a..440bf4017 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/BaseControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/BaseControllerTests.cs @@ -1,10 +1,10 @@ -namespace Streetcode.XIntegrationTest.ControllerTests +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Streetcode.DAL.Persistence; +using Streetcode.XIntegrationTest.ControllerTests.Utils; +using Xunit; +namespace Streetcode.XIntegrationTest.ControllerTests { - using Microsoft.EntityFrameworkCore; - using Microsoft.Extensions.Configuration; - using Streetcode.DAL.Persistence; - using Streetcode.XIntegrationTest.ControllerTests.Utils; - using Xunit; public class BaseControllerTests : IntegrationTestBase, IClassFixture> { diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/AudioControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/AudioControllerTests.cs index 5fc97daec..f19749633 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/AudioControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/AudioControllerTests.cs @@ -2,7 +2,6 @@ using Streetcode.DAL.Entities.Media; using Streetcode.XIntegrationTest.ControllerTests.Utils; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Audio; -using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; using Xunit; namespace Streetcode.XIntegrationTest.ControllerTests.Media diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/Images/StreetcodeArtControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/Images/StreetcodeArtControllerTests.cs index 64a0cf559..b5a5c0698 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/Images/StreetcodeArtControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/Images/StreetcodeArtControllerTests.cs @@ -1,10 +1,9 @@ -namespace Streetcode.XIntegrationTest.ControllerTests.Media.Images +using Streetcode.BLL.DTO.Media.Art; +using Streetcode.XIntegrationTest.ControllerTests.Utils; +using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; +using Xunit; +namespace Streetcode.XIntegrationTest.ControllerTests.Media.Images { - using Streetcode.BLL.DTO.Media.Art; - using Streetcode.XIntegrationTest.ControllerTests.Utils; - using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; - using Xunit; - public class StreetcodeArtControllerTests : BaseControllerTests, IClassFixture> { public StreetcodeArtControllerTests(CustomWebApplicationFactory factory) diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/VideoControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/VideoControllerTests.cs index a59cd3865..fe09ba013 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/VideoControllerTests.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Media/VideoControllerTests.cs @@ -1,10 +1,10 @@ -namespace Streetcode.XIntegrationTest.ControllerTests.Media +using Streetcode.BLL.DTO.Media; +using Streetcode.XIntegrationTest.ControllerTests.Utils; +using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Video; +using Xunit; +namespace Streetcode.XIntegrationTest.ControllerTests.Media { - using Streetcode.BLL.DTO.Media; - using Streetcode.BLL.DTO.Media.Audio; - using Streetcode.XIntegrationTest.ControllerTests.Utils; - using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Video; - using Xunit; + public class VideoControllerTests : BaseControllerTests, IClassFixture> { diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Create/StreetcodeCreateControllerTests.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Create/StreetcodeCreateControllerTests.cs new file mode 100644 index 000000000..931d67bf9 --- /dev/null +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Streetcode/Create/StreetcodeCreateControllerTests.cs @@ -0,0 +1,97 @@ +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.Create +{ + public class StreetcodeCreateControllerTests : BaseControllerTests, IClassFixture> + { + public StreetcodeCreateControllerTests(CustomWebApplicationFactory factory) + : base(factory, "/api/Streetcode") + { + + } + + [Fact] + [ExtractCreateTestStreetcode] + public async Task Create_ReturnsSuccessStatusCode() + { + // Arrange + var streetcodeCreateDTO = ExtractCreateTestStreetcode.StreetcodeForTest; + + // Act + var response = await client.CreateAsync(streetcodeCreateDTO); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + + [Fact] + [ExtractCreateTestStreetcode] + public async Task Create_CreatesNewStreetcode() + { + // Arrange + var streetcodeCreateDTO = ExtractCreateTestStreetcode.StreetcodeForTest; + + // Act + var response = await client.CreateAsync(streetcodeCreateDTO); + var streetcodeId = StreetcodeIndexFetch.GetStreetcodeByIndex(streetcodeCreateDTO.Index); + var getResponse = await client.GetByIdAsync(streetcodeId); + var fetchedStreetcode = CaseIsensitiveJsonDeserializer.Deserialize(getResponse.Content); + + // Assert + Assert.Equal(streetcodeCreateDTO.Title, fetchedStreetcode.Title); + Assert.Equal(streetcodeCreateDTO.TransliterationUrl, fetchedStreetcode.TransliterationUrl); + } + + [Fact] + [ExtractCreateTestStreetcode] + public async Task Create_WithInvalidData_ReturnsBadRequest() + { + // Arrange + var streetcodeCreateDTO = ExtractCreateTestStreetcode.StreetcodeForTest; + streetcodeCreateDTO.Title = null; // Invalid data + + // Act + var response = await client.CreateAsync(streetcodeCreateDTO); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } + + [Fact] + [ExtractTestStreetcode] + [ExtractCreateTestStreetcode] + public async Task Create_WithExistingStreetcode_ReturnsConflict() + { + // Arrange + var streetcodeCreateDTO = ExtractCreateTestStreetcode.StreetcodeForTest; + streetcodeCreateDTO.Index = ExtractTestStreetcode.StreetcodeForTest.Index; + + // Act + var response = await client.CreateAsync(streetcodeCreateDTO); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } + + [Fact] + [ExtractCreateTestStreetcode] + public async Task Create_WithLongTransliterationUrl_ReturnsBadRequest() + { + // Arrange + var transliterationUrlMaxLength = 150; + var streetcodeCreateDTO = ExtractCreateTestStreetcode.StreetcodeForTest; + streetcodeCreateDTO.TransliterationUrl = new string('a', transliterationUrlMaxLength + 1); + + // Act + var response = await client.CreateAsync(streetcodeCreateDTO); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } + } +} \ No newline at end of file diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestStreetcodeCoordinate.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestStreetcodeCoordinate.cs index cb0bc5c9d..c8aa5b104 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestStreetcodeCoordinate.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestStreetcodeCoordinate.cs @@ -19,14 +19,14 @@ public override void Before(MethodInfo methodUnderTest) { StreetcodeContent first = sqlDbHelper.GetExistItem(); first ??= sqlDbHelper.AddNewItem(new StreetcodeContent() - { - Index = 10, - UpdatedAt = DateTime.Now, - CreatedAt = DateTime.Now, - EventStartOrPersonBirthDate = DateTime.Now, - EventEndOrPersonDeathDate = DateTime.Now, - ViewCount = 1, - }); + { + Index = 10, + UpdatedAt = DateTime.Now, + CreatedAt = DateTime.Now, + EventStartOrPersonBirthDate = DateTime.Now, + EventEndOrPersonDeathDate = DateTime.Now, + ViewCount = 1, + }); CoordinateForTest = sqlDbHelper.AddNewItem( new StreetcodeCoordinate() diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestToponymCoordinate.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestToponymCoordinate.cs index eb8a45891..9884bc733 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestToponymCoordinate.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Coordinate/ExtractTestToponymCoordinate.cs @@ -1,17 +1,12 @@ using Streetcode.DAL.Entities.AdditionalContent.Coordinates.Types; using Streetcode.DAL.Entities.Toponyms; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Coordinate { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestToponymCoordinate:BeforeAfterTestAttribute + internal class ExtractTestToponymCoordinate : BeforeAfterTestAttribute { public static ToponymCoordinate ToponymCoordinateForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Subtitle/ExtractTestSubtitle.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Subtitle/ExtractTestSubtitle.cs index 7c577860c..6758057bc 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Subtitle/ExtractTestSubtitle.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Subtitle/ExtractTestSubtitle.cs @@ -1,15 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Streetcode.DAL.Entities; -using Streetcode.DAL.Entities.Streetcode; -using Streetcode.DAL.Persistence; +using Streetcode.DAL.Entities.Streetcode; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; +using System.Reflection; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Subtitle diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/ExtractTestTag.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/ExtractTestTag.cs index 33d3b63b2..25bd4db21 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/ExtractTestTag.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/ExtractTestTag.cs @@ -1,11 +1,10 @@ -using Streetcode.DAL.Entities.AdditionalContent; -using System.Reflection; +using System.Reflection; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Tag { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class ExtractTestTag: BeforeAfterTestAttribute + public class ExtractTestTag : BeforeAfterTestAttribute { public static DAL.Entities.AdditionalContent.Tag TagForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/StreetcodeTagIndexSetup.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/StreetcodeTagIndexSetup.cs index 41f223b91..2dbc8ef87 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/StreetcodeTagIndexSetup.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/AdditionalContent/Tag/StreetcodeTagIndexSetup.cs @@ -1,10 +1,5 @@ using Streetcode.DAL.Entities.AdditionalContent; using Streetcode.DAL.Entities.Streetcode; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Tag { diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Art/ExtractTestArt.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Art/ExtractTestArt.cs index 56f738846..10e339d5f 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Art/ExtractTestArt.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Art/ExtractTestArt.cs @@ -6,7 +6,7 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Images.Art { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestArt: BeforeAfterTestAttribute + internal class ExtractTestArt : BeforeAfterTestAttribute { public static DAL.Entities.Media.Images.Art ArtForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Image/ExtractTestImage.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Image/ExtractTestImage.cs index 0b595a58c..adbe0c84e 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Image/ExtractTestImage.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/Image/ExtractTestImage.cs @@ -7,7 +7,7 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Images.Image { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class ExtractTestImage: BeforeAfterTestAttribute + public class ExtractTestImage : BeforeAfterTestAttribute { public static DAL.Entities.Media.Images.Image ImageForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/StreetcodeArt/ExtractTestStreetcodeArt.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/StreetcodeArt/ExtractTestStreetcodeArt.cs index 06cb3fd95..0486e2f8f 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/StreetcodeArt/ExtractTestStreetcodeArt.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Images/StreetcodeArt/ExtractTestStreetcodeArt.cs @@ -6,7 +6,7 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Images.StreetcodeArt { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestStreetcodeArt:BeforeAfterTestAttribute + internal class ExtractTestStreetcodeArt : BeforeAfterTestAttribute { public static DAL.Entities.Streetcode.StreetcodeArt StreetcodeArtForTest; @@ -14,7 +14,7 @@ public override void Before(MethodInfo methodUnderTest) { var sqlDbHelper = BaseControllerTests.GetSqlDbHelper(); StreetcodeArtForTest = sqlDbHelper.GetExistItem(); - if(StreetcodeArtForTest == null) + if (StreetcodeArtForTest == null) { if (ExtractTestStreetcode.StreetcodeForTest == null) { diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Video/ExtractTestVideo.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Video/ExtractTestVideo.cs index 002b457e3..0cbbb38f8 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Video/ExtractTestVideo.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Media/Video/ExtractTestVideo.cs @@ -6,7 +6,7 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Video { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestVideo: BeforeAfterTestAttribute + internal class ExtractTestVideo : BeforeAfterTestAttribute { public static DAL.Entities.Media.Video VideoForTest; public static StreetcodeContent StreetcodeWithVideo; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Partners/ExtractTestPartners.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Partners/ExtractTestPartners.cs index dd9db72e2..ed7ccf3c3 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Partners/ExtractTestPartners.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Partners/ExtractTestPartners.cs @@ -1,17 +1,12 @@ using Streetcode.DAL.Entities.Partners; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Images.Image; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Partners { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestPartners: BeforeAfterTestAttribute + internal class ExtractTestPartners : BeforeAfterTestAttribute { public static Partner PartnerForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Source/SourceLinkCategories/ExtractTestSourceLinkCategory.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Source/SourceLinkCategories/ExtractTestSourceLinkCategory.cs index c96d6330c..380f3ce65 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Source/SourceLinkCategories/ExtractTestSourceLinkCategory.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Source/SourceLinkCategories/ExtractTestSourceLinkCategory.cs @@ -1,18 +1,12 @@ -using Streetcode.DAL.Entities.Partners; -using Streetcode.DAL.Entities.Sources; +using Streetcode.DAL.Entities.Sources; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Media.Images.Image; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Source.SourceLinkCategories { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestSourceLinkCategory:BeforeAfterTestAttribute + internal class ExtractTestSourceLinkCategory : BeforeAfterTestAttribute { public static SourceLinkCategory SourceLinkCategoryForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractCreateTestStreetCode.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractCreateTestStreetCode.cs new file mode 100644 index 000000000..4c8c3de59 --- /dev/null +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractCreateTestStreetCode.cs @@ -0,0 +1,80 @@ +using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types; +using Streetcode.BLL.DTO.AdditionalContent.Subtitles; +using Streetcode.BLL.DTO.AdditionalContent.Tag; +using Streetcode.BLL.DTO.Analytics; +using Streetcode.BLL.DTO.Media.Art; +using Streetcode.BLL.DTO.Media.Images; +using Streetcode.BLL.DTO.Media.Video; +using Streetcode.BLL.DTO.Partners; +using Streetcode.BLL.DTO.Sources; +using Streetcode.BLL.DTO.Streetcode.Create; +using Streetcode.BLL.DTO.Streetcode.RelatedFigure; +using Streetcode.BLL.DTO.Streetcode.TextContent.Fact; +using Streetcode.BLL.DTO.Streetcode.TextContent.Text; +using Streetcode.BLL.DTO.Timeline.Update; +using Streetcode.BLL.DTO.Toponyms; +using Streetcode.DAL.Entities.Streetcode; +using Streetcode.DAL.Enums; +using System.Reflection; +using Xunit.Sdk; + +namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + class ExtractCreateTestStreetcode : BeforeAfterTestAttribute + { + public static StreetcodeCreateDTO StreetcodeForTest; + + public override void Before(MethodInfo methodUnderTest) + { + StreetcodeForTest = new StreetcodeCreateDTO + { + Index = new Random().Next(0, 1000000), + FirstName = "TestFirstName", + LastName = "TestLastName", + Title = "TestTitle", + DateString = "20 травня 2023", + Alias = "TestAlias", + TransliterationUrl = Guid.NewGuid().ToString(), + ARBlockURL = "test-arblock-url", + StreetcodeType = StreetcodeType.Event, + Status = StreetcodeStatus.Published, + EventStartOrPersonBirthDate = DateTime.Now, + EventEndOrPersonDeathDate = DateTime.Now.AddDays(1), + ViewCount = 1, + Teaser = "Test Teaser", + Text = new TextCreateDTO + { + Title = "TestTextTitle", + TextContent = "TestTextContent", + AdditionalText = "TestAdditionalText", + }, + Toponyms = new List(), + ImagesIds = new List(), + Tags = new List(), + Subtitles = new List(), + Facts = new List(), + Videos = new List(), + Partners = new List(), + StreetcodeArts = new List(), + StatisticRecords = new List(), + StreetcodeCategoryContents = new List(), + Coordinates = new List(), + ImagesDetails = new List(), + TimelineItems = new List(), + RelatedFigures = new List(), + }; + } + + public override void After(MethodInfo methodUnderTest) + { + var sqlDbHelper = BaseControllerTests.GetSqlDbHelper(); + var streetcodeContent = sqlDbHelper.GetExistItem(p => p.Index == StreetcodeForTest.Index); + if (streetcodeContent != null) + { + sqlDbHelper.DeleteItem(streetcodeContent); + sqlDbHelper.SaveChanges(); + } + } + } +} diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestStreetcode.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestStreetcode.cs index 4d7546b39..32f16ad51 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestStreetcode.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/ExtractTestStreetcode.cs @@ -1,5 +1,4 @@ -using Streetcode.DAL.Entities.AdditionalContent; -using Streetcode.DAL.Entities.Streetcode; +using Streetcode.DAL.Entities.Streetcode; using System.Reflection; using Xunit.Sdk; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/RelatedFigure/ExtractTestRelatedFigure.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/RelatedFigure/ExtractTestRelatedFigure.cs index 84d896e4d..ea31620d7 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/RelatedFigure/ExtractTestRelatedFigure.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/RelatedFigure/ExtractTestRelatedFigure.cs @@ -1,16 +1,11 @@ using Streetcode.DAL.Entities.Streetcode; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode.RelatedFigure { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestRelatedFigure: BeforeAfterTestAttribute + internal class ExtractTestRelatedFigure : BeforeAfterTestAttribute { public static DAL.Entities.Streetcode.RelatedFigure RelatedFigureForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/StreetcodeIndexFetch.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/StreetcodeIndexFetch.cs new file mode 100644 index 000000000..80595a412 --- /dev/null +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/StreetcodeIndexFetch.cs @@ -0,0 +1,15 @@ +using Streetcode.DAL.Entities.Streetcode; + +namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode +{ + public class StreetcodeIndexFetch + { + public static int GetStreetcodeByIndex(int index) + { + var sqlDbHelper = BaseControllerTests.GetSqlDbHelper(); + var existingStreetcode = sqlDbHelper.GetExistItem(p => p.Index == index); + var id = existingStreetcode.Id; + return id; + } + } +} diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Facts/ExtractTestFact.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Facts/ExtractTestFact.cs index b0ef66ce9..aa52d8f21 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Facts/ExtractTestFact.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Facts/ExtractTestFact.cs @@ -1,16 +1,11 @@ using Streetcode.DAL.Entities.Streetcode.TextContent; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode.TextContent.Facts { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class ExtractTestFact: BeforeAfterTestAttribute + public class ExtractTestFact : BeforeAfterTestAttribute { public static Fact FactForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Terms/ExstractTestTerm.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Terms/ExstractTestTerm.cs index cc745822f..bd28a9c2d 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Terms/ExstractTestTerm.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Terms/ExstractTestTerm.cs @@ -1,17 +1,11 @@ using Streetcode.DAL.Entities.Streetcode.TextContent; -using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode.TextContent.Facts; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode.TextContent.Terms { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExstractTestTerm: BeforeAfterTestAttribute + internal class ExstractTestTerm : BeforeAfterTestAttribute { public static Term TermForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Texts/ExstractTestText.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Texts/ExstractTestText.cs index 36135d839..42e2bb4e0 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Texts/ExstractTestText.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Streetcode/TextContent/Texts/ExstractTestText.cs @@ -1,16 +1,11 @@ using Streetcode.DAL.Entities.Streetcode.TextContent; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode.TextContent.Texts { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExstractTestText :BeforeAfterTestAttribute + internal class ExstractTestText : BeforeAfterTestAttribute { public static Text TextForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Timelines/ExtractTestTimelineItem.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Timelines/ExtractTestTimelineItem.cs index 4ecaef22b..bed77d9a8 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Timelines/ExtractTestTimelineItem.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Timelines/ExtractTestTimelineItem.cs @@ -1,16 +1,11 @@ using Streetcode.DAL.Entities.Timeline; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Timelines { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestTimelineItem: BeforeAfterTestAttribute + internal class ExtractTestTimelineItem : BeforeAfterTestAttribute { public static TimelineItem TimelineItemForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Toponyms/ExtractTestToponym.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Toponyms/ExtractTestToponym.cs index 97c55ff66..24d6628fe 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Toponyms/ExtractTestToponym.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Toponyms/ExtractTestToponym.cs @@ -1,15 +1,12 @@ using Streetcode.DAL.Entities.Toponyms; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.AdditionalContent.Coordinate; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Toponyms { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - internal class ExtractTestToponym:BeforeAfterTestAttribute + internal class ExtractTestToponym : BeforeAfterTestAttribute { public static Toponym ToponymForTest; diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Transactions/ExtractTestTransactionLink.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Transactions/ExtractTestTransactionLink.cs index 3561a7ddd..6d509064c 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Transactions/ExtractTestTransactionLink.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/BeforeAndAfterTestAtribute/Transactions/ExtractTestTransactionLink.cs @@ -1,13 +1,6 @@ -using Streetcode.DAL.Entities.AdditionalContent.Coordinates.Types; -using Streetcode.DAL.Entities.Transactions; +using Streetcode.DAL.Entities.Transactions; using Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Streetcode; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Transactions; using Xunit.Sdk; namespace Streetcode.XIntegrationTest.ControllerTests.Utils.BeforeAndAfterTestAtribute.Transactions diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/CustomWebApplicationFactory.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/CustomWebApplicationFactory.cs index 8e27ecf3f..db47e2e8d 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/CustomWebApplicationFactory.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/CustomWebApplicationFactory.cs @@ -1,8 +1,8 @@ namespace Streetcode.XIntegrationTest.ControllerTests.Utils { - using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; + using System; public class CustomWebApplicationFactory : WebApplicationFactory where TProgram : class diff --git a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/StreetcodeClient.cs b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/StreetcodeClient.cs index 97e3eee4c..1bcef005a 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/StreetcodeClient.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ControllerTests/Utils/StreetcodeClient.cs @@ -1,18 +1,18 @@ -namespace Streetcode.XIntegrationTest.ControllerTests.Utils +using RestSharp; +using RestSharp.Serializers; +using Streetcode.BLL.DTO.Streetcode.Create; +using Streetcode.BLL.DTO.Streetcode.Update; +namespace Streetcode.XIntegrationTest.ControllerTests.Utils { - using RestSharp; - using RestSharp.Serializers; - using System.Threading.Tasks; - public class StreetcodeClient { protected RestClient Client; public string SecondPartUrl { get; } - public StreetcodeClient(HttpClient client, string secondPartUrl = "") + public StreetcodeClient(HttpClient client, string secondPartUrl = "") { - this.Client = new RestClient(client) { AcceptedContentTypes=ContentType.JsonAccept }; + this.Client = new RestClient(client) { AcceptedContentTypes = ContentType.JsonAccept }; this.SecondPartUrl = secondPartUrl; } @@ -45,5 +45,24 @@ public async Task GetResponse(string requestString) return returns; } + public async Task UpdateAsync(StreetcodeUpdateDTO updateStreetcodeDTO) + { + var request = new RestRequest($"{this.SecondPartUrl}/Update", Method.Put); + request.AddJsonBody(updateStreetcodeDTO); + request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; + request.AddHeader("content-type", "application/json"); + var response = await this.Client.ExecuteAsync(request); + return response; + } + + public async Task CreateAsync(StreetcodeCreateDTO createStreetcodeDTO) + { + var request = new RestRequest($"{this.SecondPartUrl}/Create", Method.Post); + request.AddJsonBody(createStreetcodeDTO); + request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; + request.AddHeader("content-type", "application/json"); + var response = await this.Client.ExecuteAsync(request); + return response; + } } } diff --git a/Streetcode/Streetcode.XIntegrationTest/ServiceTests/BlobServiceTests/Utils/BlobStorageFixture.cs b/Streetcode/Streetcode.XIntegrationTest/ServiceTests/BlobServiceTests/Utils/BlobStorageFixture.cs index 07eb4bc2c..861f735e8 100644 --- a/Streetcode/Streetcode.XIntegrationTest/ServiceTests/BlobServiceTests/Utils/BlobStorageFixture.cs +++ b/Streetcode/Streetcode.XIntegrationTest/ServiceTests/BlobServiceTests/Utils/BlobStorageFixture.cs @@ -5,8 +5,6 @@ using Streetcode.DAL.Entities.Media; using Streetcode.DAL.Entities.Media.Images; using Streetcode.DAL.Persistence; -using Streetcode.DAL.Repositories.Realizations.Base; -using Streetcode.XIntegrationTest.Base; using System.Text; namespace Streetcode.XIntegrationTest.ServiceTests.BlobServiceTests.Utils @@ -28,10 +26,7 @@ public BlobStorageFixture() }); blobPath = environmentVariables.Value.BlobStorePath; blobKey = environmentVariables.Value.BlobStoreKey; - - // TestDbContext = TestDBFixture.CreateContext(Configuration.GetConnectionString("DefaultConnection")); - // RepositoryWrapper repo = new RepositoryWrapper(TestDbContext); - + blobService = new BlobService(environmentVariables); // add repo Directory.CreateDirectory(blobPath); }