Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,6 @@ healthchecksdb

# BlobStorage
BlobStorageFolder/
BlobStorageTestFolder/
BlobStorageTestFolder/
/Streetcode/Streetcode.WebApi/appsettings.json
/Streetcode/Streetcode.WebApi/appsettings.Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("HistoricalContextId");

b.ToTable("HistoricalContextsTimelines");
b.ToTable("HistoricalContextsTimelines", (string)null);
});

modelBuilder.Entity("Streetcode.DAL.Entities.Timeline.TimelineItem", b =>
Expand Down
2 changes: 1 addition & 1 deletion Streetcode/Streetcode.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

await app.ApplyMigrations();

// await app.SeedDataAsync(); // uncomment for seeding data in local
await app.SeedDataAsync(); // uncomment for seeding data in local
app.UseCors();
app.UseHttpsRedirection();
app.UseRouting();
Expand Down
11 changes: 0 additions & 11 deletions Streetcode/Streetcode.WebApi/appsettings.Local.json

This file was deleted.

55 changes: 0 additions & 55 deletions Streetcode/Streetcode.WebApi/appsettings.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using AutoMapper;

Check warning on line 1 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW4&open=AZ4ftojzXsppU-LMSnW4&pullRequest=52
using FluentResults;

Check warning on line 2 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW5&open=AZ4ftojzXsppU-LMSnW5&pullRequest=52
using Microsoft.EntityFrameworkCore.Query;

Check warning on line 3 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW6&open=AZ4ftojzXsppU-LMSnW6&pullRequest=52
using Moq;
using Repositories.Interfaces;

Check warning on line 5 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW8&open=AZ4ftojzXsppU-LMSnW8&pullRequest=52
using Streetcode.BLL.DTO.Media.Art;

Check warning on line 6 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW9&open=AZ4ftojzXsppU-LMSnW9&pullRequest=52
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.BLL.MediatR.Media.Art.GetAll;

Check warning on line 8 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnW_&open=AZ4ftojzXsppU-LMSnW_&pullRequest=52
using Streetcode.DAL.Entities.Media.Images;
using Streetcode.DAL.Repositories.Interfaces.Base;

Check warning on line 10 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnXB&open=AZ4ftojzXsppU-LMSnXB&pullRequest=52
using System.Linq.Expressions;

Check warning on line 11 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System.Linq.Expressions' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnXE&open=AZ4ftojzXsppU-LMSnXE&pullRequest=52
using Xunit;

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetAll/GetAllArtsHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftojzXsppU-LMSnXD&open=AZ4ftojzXsppU-LMSnXD&pullRequest=52

namespace Streetcode.XUnitTest.BLL.MediatR.Media.Art.GetAll;

/// <summary>
/// Tests for GetAllArtsHandler.
/// </summary>
public class GetAllArtsHandlerTests
{
private GetAllArtsHandler handler;

private Mock<IMapper> mockMapper;
private Mock<IRepositoryWrapper> mockRepository;
private Mock<IArtRepository> mockArtRepository;
private Mock<ILoggerService> mockLoggerService;

private IMapper mapper;

/// <summary>
/// Initializes a new instance of the <see cref="GetAllArtsHandlerTests"/> class.
/// </summary>
public GetAllArtsHandlerTests()
{
this.mockMapper = new Mock<IMapper>();
this.mockRepository = new Mock<IRepositoryWrapper>();
this.mockArtRepository = new Mock<IArtRepository>();
this.mockLoggerService = new Mock<ILoggerService>();

this.mockRepository
.Setup(r => r.ArtRepository)
.Returns(this.mockArtRepository.Object);

this.mapper = new MapperConfiguration(cfg =>
{
cfg.CreateMap<DAL.Entities.Media.Images.Art, ArtDTO>();
}).CreateMapper();

this.handler = new GetAllArtsHandler(
this.mockRepository.Object,
this.mapper,
this.mockLoggerService.Object);
}

/// <summary>
/// Method Handel returns all Arts, if they are.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task Handle_ArtsNotEmpty_ReturnAllArts()
{
var query = new GetAllArtsQuery();

int expectedCount = 1;

var arts = new List<DAL.Entities.Media.Images.Art>()
{
new DAL.Entities.Media.Images.Art()
{
Id = 1,
Description = "Description art 1",
ImageId = 1,
Title = "Title art 1",
},
};

this.mockArtRepository
.Setup(r => r.GetAllAsync(
It.IsAny<Expression<Func<DAL.Entities.Media.Images.Art, bool>>>(),
It.IsAny<Func<IQueryable<DAL.Entities.Media.Images.Art>,
IIncludableQueryable<DAL.Entities.Media.Images.Art, object>>>()))
.ReturnsAsync(arts);

var result = await this.handler.Handle(query, CancellationToken.None);

Assert.Equal(expectedCount, result.Value.Count());
}

/// <summary>
/// Method Handle return error message, if Arts do not exist.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task Handle_ArtsIsEmpty_ReturnErrorMessage()
{
var query = new GetAllArtsQuery();

var expectedError = new Error($"Cannot find any arts");

this.mockArtRepository
.Setup(r => r.GetAllAsync(
It.IsAny<Expression<Func<DAL.Entities.Media.Images.Art, bool>>>(),
It.IsAny<Func<IQueryable<DAL.Entities.Media.Images.Art>,
IIncludableQueryable<DAL.Entities.Media.Images.Art, object>>>()))
.ReturnsAsync((List<DAL.Entities.Media.Images.Art>?)null);

var result = await this.handler.Handle(query, CancellationToken.None);

Assert.Equal(expectedError.Message, result.Errors.First().Message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using AutoMapper;

Check warning on line 1 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXF&open=AZ4ftoj8XsppU-LMSnXF&pullRequest=52
using Microsoft.EntityFrameworkCore.Query;

Check warning on line 2 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXG&open=AZ4ftoj8XsppU-LMSnXG&pullRequest=52
using Moq;

Check warning on line 3 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXH&open=AZ4ftoj8XsppU-LMSnXH&pullRequest=52
using Org.BouncyCastle.Asn1.Ocsp;

Check warning on line 4 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXI&open=AZ4ftoj8XsppU-LMSnXI&pullRequest=52
using Repositories.Interfaces;

Check warning on line 5 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXJ&open=AZ4ftoj8XsppU-LMSnXJ&pullRequest=52
using Streetcode.BLL.DTO.Media.Art;

Check warning on line 6 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXK&open=AZ4ftoj8XsppU-LMSnXK&pullRequest=52
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.BLL.MediatR.Media.Art.GetById;
using Streetcode.DAL.Repositories.Interfaces.Base;

Check warning on line 9 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXN&open=AZ4ftoj8XsppU-LMSnXN&pullRequest=52
using System;

Check warning on line 10 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXV&open=AZ4ftoj8XsppU-LMSnXV&pullRequest=52

Check warning on line 10 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXO&open=AZ4ftoj8XsppU-LMSnXO&pullRequest=52
using System.Collections.Generic;

Check warning on line 11 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System.Collections.Generic' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXW&open=AZ4ftoj8XsppU-LMSnXW&pullRequest=52
using System.Linq;

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXQ&open=AZ4ftoj8XsppU-LMSnXQ&pullRequest=52

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System.Linq' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXX&open=AZ4ftoj8XsppU-LMSnXX&pullRequest=52
using System.Linq.Expressions;

Check warning on line 13 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System.Linq.Expressions' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXY&open=AZ4ftoj8XsppU-LMSnXY&pullRequest=52

Check warning on line 13 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXR&open=AZ4ftoj8XsppU-LMSnXR&pullRequest=52
using System.Text;

Check warning on line 14 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive for 'System.Text' should appear before directive for 'Streetcode.DAL.Repositories.Interfaces.Base'

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXZ&open=AZ4ftoj8XsppU-LMSnXZ&pullRequest=52

Check warning on line 14 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXS&open=AZ4ftoj8XsppU-LMSnXS&pullRequest=52
using System.Threading.Tasks;

Check warning on line 15 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXT&open=AZ4ftoj8XsppU-LMSnXT&pullRequest=52
using Xunit;

Check warning on line 16 in Streetcode/Streetcode.XUnitTest/BLL/MediatR/Media/Art/GetById/GetArtByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=ita-social-projects_StreetCode&issues=AZ4ftoj8XsppU-LMSnXU&open=AZ4ftoj8XsppU-LMSnXU&pullRequest=52

namespace Streetcode.XUnitTest.BLL.MediatR.Media.Art.GetById
{
/// <summary>
/// Checking class GetArtByIdHandler.
/// </summary>
public class GetArtByIdHandlerTests
{
private GetArtByIdHandler handler;

private Mock<IMapper> mockMapper;
private Mock<IRepositoryWrapper> mockRepository;
private Mock<IArtRepository> mockArtRepository;
private Mock<ILoggerService> mockLoggerService;

/// <summary>
/// Initializes a new instance of the <see cref="GetArtByIdHandlerTests"/> class.
/// </summary>
public GetArtByIdHandlerTests()
{
this.mockMapper = new Mock<IMapper>();
this.mockArtRepository = new Mock<IArtRepository>();
this.mockRepository = new Mock<IRepositoryWrapper>();
this.mockLoggerService = new Mock<ILoggerService>();

this.mockRepository
.Setup(r => r.ArtRepository)
.Returns(this.mockArtRepository.Object);

this.handler = new GetArtByIdHandler(
this.mockRepository.Object,
this.mockMapper.Object,
this.mockLoggerService.Object);
}

/// <summary>
/// Method returns correct art, if entered valid id.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task Handle_ValidId_ReturnArt()
{
var query = new GetArtByIdQuery(1);

var art = new DAL.Entities.Media.Images.Art()
{
Id = 1,
Description = "Description art 1",
ImageId = 1,
Title = "Title art 1",
};

var artDTO = new ArtDTO()
{
Id = 1,
Description = "Description art 1",
ImageId = 1,
Title = "Title art 1",
};

this.mockArtRepository
.Setup(r => r.GetFirstOrDefaultAsync(
It.IsAny<Expression<Func<DAL.Entities.Media.Images.Art, bool>>>(),
It.IsAny<Func<IQueryable<DAL.Entities.Media.Images.Art>,
IIncludableQueryable<DAL.Entities.Media.Images.Art, object>>>()))
.ReturnsAsync(art);

this.mockMapper
.Setup(m => m.Map<ArtDTO>(
It.IsAny<DAL.Entities.Media.Images.Art>()))
.Returns(artDTO);

var result = await this.handler.Handle(query, CancellationToken.None);

Assert.Equal(artDTO.Id, result.Value.Id);
}

/// <summary>
/// Method returns error message, if entered not valid id.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task Handle_NotValidId_ReturnError()
{
var query = new GetArtByIdQuery(2);

string expectedErrorMsg = $"Cannot find an art with corresponding id: {query.Id}";

this.mockArtRepository
.Setup(r => r.GetFirstOrDefaultAsync(
It.IsAny<Expression<Func<DAL.Entities.Media.Images.Art, bool>>>(),
It.IsAny<Func<IQueryable<DAL.Entities.Media.Images.Art>,
IIncludableQueryable<DAL.Entities.Media.Images.Art, object>>>()))
.ReturnsAsync((DAL.Entities.Media.Images.Art?)null);

var result = await this.handler.Handle(query, CancellationToken.None);

Assert.Equal(expectedErrorMsg, result.Errors.First().Message);
}
}
}
Loading
Loading