Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository unit tests #261

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions GloboTicket.TicketManagement.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31321.278
# Visual Studio Version 17
VisualStudioVersion = 17.2.32519.379
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B4CF959C-EBE1-4900-980A-EBAFB84860DF}"
EndProject
Expand Down Expand Up @@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gRPC", "gRPC", "{E2105807-E
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GloboTicket.TicketManagement.gRPC", "src\gRPC\GloboTicket.TicketManagement.gRPC\GloboTicket.TicketManagement.gRPC.csproj", "{B21A5EBE-1856-4E11-B7BC-C84D95584D6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GloboTicket.TicketManagement.Persistence.UnitTests", "test\GloboTicket.TicketManagement.Persistence.UnitTests\GloboTicket.TicketManagement.Persistence.UnitTests.csproj", "{7155436B-0F59-4106-A59E-E1E46F108383}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -99,6 +101,10 @@ Global
{B21A5EBE-1856-4E11-B7BC-C84D95584D6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B21A5EBE-1856-4E11-B7BC-C84D95584D6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B21A5EBE-1856-4E11-B7BC-C84D95584D6A}.Release|Any CPU.Build.0 = Release|Any CPU
{7155436B-0F59-4106-A59E-E1E46F108383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7155436B-0F59-4106-A59E-E1E46F108383}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7155436B-0F59-4106-A59E-E1E46F108383}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7155436B-0F59-4106-A59E-E1E46F108383}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -121,6 +127,7 @@ Global
{4F927D13-8CF2-4039-BA22-E7BB07BC8D93} = {6BF9057E-C82C-4348-9A6A-D6D6FF28CF8D}
{E2105807-EEB6-4A9C-BA97-BE56F11F8D9A} = {B4CF959C-EBE1-4900-980A-EBAFB84860DF}
{B21A5EBE-1856-4E11-B7BC-C84D95584D6A} = {E2105807-EEB6-4A9C-BA97-BE56F11F8D9A}
{7155436B-0F59-4106-A59E-E1E46F108383} = {6BF9057E-C82C-4348-9A6A-D6D6FF28CF8D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F637676C-B7E7-4D66-9BD9-DAEA91A9BBC6}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace GloboTicket.TicketManagement.Persistence.Repositories
{
[ExcludeFromCodeCoverage]
public class BaseRepository<T> : IAsyncRepository<T> where T : class
{
protected readonly GloboTicketDbContext _dbContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace GloboTicket.TicketManagement.Persistence.Repositories
{
[ExcludeFromCodeCoverage]
public class CategoryRepository : BaseRepository<Category>, ICategoryRepository
{

Expand All @@ -24,7 +22,7 @@ public CategoryRepository(GloboTicketDbContext dbContext, ILogger<Category> logg
public async Task<List<Category>> GetCategoriesWithEvents(bool includePassedEvents)
{
_logger.LogInformation("GetCategoriesWithEvents Initiated");
var allCategories = await _dbContext.Categories.Include(x => x.Events).ToListAsync();
var allCategories = await _dbContext.Set<Category>().Include(x => x.Events).ToListAsync();
if(!includePassedEvents)
{
allCategories.ForEach(p => p.Events.ToList().RemoveAll(c => c.Date < DateTime.Today));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace GloboTicket.TicketManagement.Persistence.Repositories
{
[ExcludeFromCodeCoverage]
public class EventRepository : BaseRepository<Event>, IEventRepository
{
private readonly ILogger _logger;
Expand All @@ -21,7 +19,7 @@ public EventRepository(GloboTicketDbContext dbContext, ILogger<Event> logger) :
public Task<bool> IsEventNameAndDateUnique(string name, DateTime eventDate)
{
_logger.LogInformation("GetCategoriesWithEvents Initiated");
var matches = _dbContext.Events.Any(e => e.Name.Equals(name) && e.Date.Date.Equals(eventDate.Date));
var matches = _dbContext.Set<Event>().Any(e => e.Name.Equals(name) && e.Date.Date.Equals(eventDate.Date));
_logger.LogInformation("GetCategoriesWithEvents Completed");
return Task.FromResult(matches);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace GloboTicket.TicketManagement.Persistence.Repositories
{
[ExcludeFromCodeCoverage]
public class MessageRepository : BaseRepository<Message>, IMessageRepository
{
private readonly string cacheKey = $"{typeof(Message)}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace GloboTicket.TicketManagement.Persistence.Repositories
{
[ExcludeFromCodeCoverage]
public class OrderRepository : BaseRepository<Order>, IOrderRepository
{
private readonly ILogger _logger;
Expand All @@ -22,14 +20,14 @@ public OrderRepository(GloboTicketDbContext dbContext, ILogger<Order> logger) :
public async Task<List<Order>> GetPagedOrdersForMonth(DateTime date, int page, int size)
{
_logger.LogInformation("GetPagedOrdersForMonth Initiated");
return await _dbContext.Orders.Where(x => x.OrderPlaced.Month == date.Month && x.OrderPlaced.Year == date.Year)
return await _dbContext.Set<Order>().Where(x => x.OrderPlaced.Month == date.Month && x.OrderPlaced.Year == date.Year)
.Skip((page - 1) * size).Take(size).AsNoTracking().ToListAsync();
}

public async Task<int> GetTotalCountOfOrdersForMonth(DateTime date)
{
_logger.LogInformation("GetPagedOrdersForMonth Initiated");
return await _dbContext.Orders.CountAsync(x => x.OrderPlaced.Month == date.Month && x.OrderPlaced.Year == date.Year);
return await _dbContext.Set<Order>().CountAsync(x => x.OrderPlaced.Month == date.Month && x.OrderPlaced.Year == date.Year);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="EntityFrameworkCore3Mock.Moq" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MockQueryable.Moq" Version="3.1.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Infrastructure\GloboTicket.TicketManagement.Persistence\GloboTicket.TicketManagement.Persistence.csproj" />
</ItemGroup>

</Project>
Loading