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

Rydding i tester #890

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -24,8 +25,13 @@ public async Task<HourRateDto> UpdateHourRate(HourRateDto hourRate)
await _hourRateStorage.UpdateHourRate(hourRate);
return await GetHourRateById(hourRate.Id);
}

public async Task<IEnumerable<HourRateDto>> GetHourRates(HourRateQuerySearch criterias)
{
return await _hourRateStorage.GetHourRates(criterias);
}

private async Task<HourRateDto> GetHourRateById(int hourRateId)
public async Task<HourRateDto> GetHourRateById(int hourRateId)
{
return (await _hourRateStorage.GetHourRates(new HourRateQuerySearch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

namespace AlvTime.Persistence.Repositories;

public class CustomerStorage : ICustomerStorage
public class CustomerService : ICustomerStorage
{
private readonly AlvTime_dbContext _context;

public CustomerStorage(AlvTime_dbContext context)
public CustomerService(AlvTime_dbContext context)
{
_context = context;
}
Expand All @@ -37,7 +37,7 @@
await _context.SaveChangesAsync();
}

public async Task<CustomerAdminDto?> GetCustomerDetailedById(int customerId)

Check warning on line 40 in packages/api/AlvTime.Persistence/Repositories/CustomerService.cs

View workflow job for this annotation

GitHub Actions / build_and_test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
return await _context.Customer
.Where(c => c.Id == customerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace AlvTime.Persistence.Repositories;

public class HourRateStorage : IHourRateStorage
public class HourRateService : IHourRateStorage
{
private readonly AlvTime_dbContext _context;

public HourRateStorage(AlvTime_dbContext context)
public HourRateService(AlvTime_dbContext context)
{
_context = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace AlvTime.Persistence.Repositories;

public class ProjectStorage : IProjectStorage
public class ProjectService : IProjectStorage
{
private readonly AlvTime_dbContext _context;

public ProjectStorage(AlvTime_dbContext context)
public ProjectService(AlvTime_dbContext context)
{
_context = context;
}
Expand Down
15 changes: 9 additions & 6 deletions packages/api/AlvTimeWebApi/ServiceRegistrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using AlvTimeWebApi.Controllers.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using CustomerService = AlvTime.Persistence.Repositories.CustomerService;
using HourRateService = AlvTime.Persistence.Repositories.HourRateService;
using ProjectService = AlvTime.Persistence.Repositories.ProjectService;

namespace AlvTimeWebApi
{
Expand All @@ -30,12 +33,12 @@ public static void AddAlvtimeServices(this IServiceCollection services, IConfigu
services.AddScoped<UserService>();
services.AddScoped<ITaskStorage, TaskStorage>();
services.AddScoped<ITimeRegistrationStorage, TimeRegistrationStorage>();
services.AddScoped<IHourRateStorage, HourRateStorage>();
services.AddScoped<HourRateService>();
services.AddScoped<IProjectStorage, ProjectStorage>();
services.AddScoped<ProjectService>();
services.AddScoped<ICustomerStorage, CustomerStorage>();
services.AddScoped<CustomerService>();
services.AddScoped<IHourRateStorage, HourRateService>();
services.AddScoped<AlvTime.Business.HourRates.HourRateService>();
services.AddScoped<IProjectStorage, ProjectService>();
services.AddScoped<AlvTime.Business.Projects.ProjectService>();
services.AddScoped<ICustomerStorage, CustomerService>();
services.AddScoped<AlvTime.Business.Customers.CustomerService>();
services.AddScoped<IEconomyStorage, EconomyStorage>();
services.AddScoped<IAccessTokenStorage, AccessTokenStorage>();
services.AddScoped<IAssociatedTaskStorage, AssociatedTaskStorage>();
Expand Down
4 changes: 0 additions & 4 deletions packages/api/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="IntegrationTests\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AlvTime.Business\AlvTime.Business.csproj" />
<ProjectReference Include="..\AlvTime.Persistence\AlvTime.Persistence.csproj" />
Expand Down
100 changes: 48 additions & 52 deletions packages/api/Tests/UnitTests/AccessToken/AccessTokenServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,68 @@
using User = AlvTime.Business.Users.User;
using AlvTime.Business.Users;

namespace Tests.UnitTests.AccessToken
namespace Tests.UnitTests.AccessToken;

public class AccessTokenServiceTests
{
public class AccessTokenServiceTests
private readonly AlvTime_dbContext _context;

public AccessTokenServiceTests()
{
[Fact]
public async Task GetActiveAccessTokens_UserSpecified_ActiveTokensForUser()
{
var dbContext = new AlvTimeDbContextBuilder()
.WithUsers()
.CreateDbContext();

var service = CreateAccessTokenService(dbContext);

var tokens = await service.GetActiveTokens();

Assert.Equal(dbContext.AccessTokens.Where(x => x.UserId == 1).ToList().Count, tokens.Count());
}
_context = new AlvTimeDbContextBuilder()
.WithPersonalAccessTokens()
.WithUsers()
.CreateDbContext();
}

[Fact]
public async Task GetActiveAccessTokens_UserSpecified_ActiveTokensForUser()
{
var service = CreateAccessTokenService(_context);

[Fact]
public async Task CreateLifetimeToken_FriendlyNameSpecified_TokenWithFriendlyNameCreated()
{
var dbContext = new AlvTimeDbContextBuilder()
.WithPersonalAccessTokens()
.WithUsers()
.CreateDbContext();
var tokens = await service.GetActiveTokens();

var service = CreateAccessTokenService(dbContext);
Assert.Equal(_context.AccessTokens.Where(x => x.UserId == 1).ToList().Count, tokens.Count());
}

await service.CreateLifeTimeToken("new token");
[Fact]
public async Task CreateLifetimeToken_FriendlyNameSpecified_TokenWithFriendlyNameCreated()
{
var service = CreateAccessTokenService(_context);

var tokens = await service.GetActiveTokens();
await service.CreateLifeTimeToken("new token");

Assert.Equal(dbContext.AccessTokens.Where(x => x.UserId == 1).ToList().Count(), tokens.Count());
}
var tokens = (await service.GetActiveTokens()).ToList();

[Fact]
public async Task DeleteToken_TokenIdSpecified_TokenWithIdDeleted()
{
var dbContext = new AlvTimeDbContextBuilder()
.WithPersonalAccessTokens()
.WithUsers()
.CreateDbContext();
Assert.Equal(2, tokens.Count);
Assert.Equal("new token", tokens.Last().FriendlyName);
}

var service = CreateAccessTokenService(dbContext);
[Fact]
public async Task DeleteToken_TokenIdSpecified_TokenWithIdDeleted()
{
var service = CreateAccessTokenService(_context);

await service.DeleteActiveTokens(new List<int>{1});
await service.DeleteActiveTokens(new List<int>{1});

var tokens = await service.GetActiveTokens();
var tokens = await service.GetActiveTokens();

Assert.Empty(tokens);
}
Assert.Empty(tokens);
}

private static AccessTokenService CreateAccessTokenService(AlvTime_dbContext dbContext)
{
var mockUserContext = new Mock<IUserContext>();

private static AccessTokenService CreateAccessTokenService(AlvTime_dbContext dbContext)
var user = new User
{
var mockUserContext = new Mock<IUserContext>();

var user = new User
{
Id = 1,
Email = "[email protected]",
Name = "Someone"
};
Id = 1,
Email = "[email protected]",
Name = "Someone"
};

mockUserContext.Setup(context => context.GetCurrentUser()).Returns(System.Threading.Tasks.Task.FromResult(user));
mockUserContext.Setup(context => context.GetCurrentUser()).Returns(Task.FromResult(user));

return new AccessTokenService(new AccessTokenStorage(dbContext), mockUserContext.Object);
}
return new AccessTokenService(new AccessTokenStorage(dbContext), mockUserContext.Object);
}
}
}

This file was deleted.

Loading
Loading