Skip to content

Commit

Permalink
Run Visual Studio code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
romandykyi committed Mar 12, 2024
1 parent ed89e51 commit b32cf3a
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AdvancedTodoList.Core.Models.Auth;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

Expand Down
4 changes: 2 additions & 2 deletions AdvancedTodoList.Core/Services/Auth/IPermissionsChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface IPermissionsChecker
/// <see langword="true"/> if user is either an owner of the entity and a member of a to-do list,
/// or he/she/they has permission defined by <paramref name="permission"/>; otherwise <see langword="false" />.
/// </returns>
Task<bool> CanTouchEntityAsync<TEntity, TKey>(TodoListContext context, TEntity entity,
Task<bool> CanTouchEntityAsync<TEntity, TKey>(TodoListContext context, TEntity entity,
Func<RolePermissions, bool> permission)
where TEntity : class, IEntity<TKey>
where TKey : IEquatable<TKey>;
Expand All @@ -63,6 +63,6 @@ Task<bool> CanTouchEntityAsync<TEntity, TKey>(TodoListContext context, TEntity e
/// <see langword="true"/> if user has <paramref name="permission"/> and highest role priority than
/// the <paramref name="rolePriority"/>; otherwise <see langword="false" />.
/// </returns>
Task<bool> HasPermissionOverRoleAsync(TodoListContext context, int rolePriority,
Task<bool> HasPermissionOverRoleAsync(TodoListContext context, int rolePriority,
Func<RolePermissions, bool> permission);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Task<ServiceResponse<TOutputDto>> CreateAsync<TInputDto, TOutputDto>(
/// A task representing the asynchronous operation. The task contains
/// a result of the operation.
/// </returns>
public Task<ServiceResponseStatus> UpdateAsync<TDto>(TodoListContext context, TKey entityId,
public Task<ServiceResponseStatus> UpdateAsync<TDto>(TodoListContext context, TKey entityId,
TDto dto, Func<RolePermissions, bool>? permission = null);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion AdvancedTodoList.Core/Services/ServiceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ServiceResponse<T>(ServiceResponseStatus status, T? result = defaul
/// Gets the status of operation.
/// </summary>
public ServiceResponseStatus Status { get; } = status;

/// <summary>
/// Gets the result of the operation.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@

#nullable disable

namespace AdvancedTodoList.Infrastructure.Migrations
namespace AdvancedTodoList.Infrastructure.Migrations;

/// <inheritdoc />
public partial class TodoListMemberUniqueConstraint : Migration
{
/// <inheritdoc />
public partial class TodoListMemberUniqueConstraint : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TodoListsMembers_UserId",
table: "TodoListsMembers");
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TodoListsMembers_UserId",
table: "TodoListsMembers");

migrationBuilder.CreateIndex(
name: "IX_TodoListsMembers_UserId_TodoListId",
table: "TodoListsMembers",
columns: new[] { "UserId", "TodoListId" },
unique: true);
}
migrationBuilder.CreateIndex(
name: "IX_TodoListsMembers_UserId_TodoListId",
table: "TodoListsMembers",
columns: new[] { "UserId", "TodoListId" },
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TodoListsMembers_UserId_TodoListId",
table: "TodoListsMembers");
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TodoListsMembers_UserId_TodoListId",
table: "TodoListsMembers");

migrationBuilder.CreateIndex(
name: "IX_TodoListsMembers_UserId",
table: "TodoListsMembers",
column: "UserId");
}
}
migrationBuilder.CreateIndex(
name: "IX_TodoListsMembers_UserId",
table: "TodoListsMembers",
column: "UserId");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task<bool> HasPermissionOverRoleAsync(TodoListContext context, int
var member = await _membersRepository.GetAggregateAsync<PermissionsAggregate>(specification);

// User is not a member, has no role or permission - return false
if (member == null || member.Role == null || !permission(member.Role.Permissions))
if (member == null || member.Role == null || !permission(member.Role.Permissions))
return false;

// Check if user has a higher priority
Expand Down
5 changes: 1 addition & 4 deletions AdvancedTodoList.Infrastructure/Services/TodoItemsService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using AdvancedTodoList.Core.Dtos;
using AdvancedTodoList.Core.Models.TodoLists;
using AdvancedTodoList.Core.Models.TodoLists.Members;
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Repositories;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.Core.Services.Auth;
using AdvancedTodoList.Infrastructure.Specifications;
using Mapster;
using System.Security;

namespace AdvancedTodoList.Infrastructure.Services;

Expand Down Expand Up @@ -59,7 +56,7 @@ public async Task<ServiceResponse<TodoItemGetByIdDto>> GetByIdAsync(TodoListCont
// Get the aggregate
var dto = await _repository.GetAggregateAsync<TodoItemGetByIdDto>(specification);
// Check if it's valid
if (dto == null || dto.TodoListId != context.TodoListId)
if (dto == null || dto.TodoListId != context.TodoListId)
return new(ServiceResponseStatus.NotFound);

// Retyrb requested DTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ namespace AdvancedTodoList.Infrastructure.Services;
/// <typeparam name="TEntity">Type of the to-do list dependant entity.</typeparam>
/// <typeparam name="TKey">Type of the unique identifier used by the entity.</typeparam>
public sealed class TodoListDependantEntitiesService<TEntity, TKey>(
IRepository<TEntity, TKey> repository,
IRepository<TEntity, TKey> repository,
IEntityExistenceChecker existenceChecker,
IPermissionsChecker permissionsChecker) : ITodoListDependantEntitiesService<TEntity, TKey>
where TEntity : class, IEntity<TKey>, ITodoListDependant
where TKey : IEquatable<TKey>
{
private readonly IRepository<TEntity, TKey> _repository = repository;
private readonly IEntityExistenceChecker _existenceChecker = existenceChecker;
private readonly IPermissionsChecker _permissionsChecker = permissionsChecker;
private readonly IPermissionsChecker _permissionsChecker = permissionsChecker;

/// <summary>
/// Retrieves a page of to-do list dependant entities mapped to <typeparamref name="TDto"/>.
Expand Down Expand Up @@ -78,7 +78,7 @@ public async Task<ServiceResponse<TDto>> GetByIdAsync<TDto>(TodoListContext cont
// Get the model
var entity = await _repository.GetByIdAsync(entityId);
// Return null if model is null or has wrong to-do list ID
if (entity == null || entity.TodoListId != context.TodoListId)
if (entity == null || entity.TodoListId != context.TodoListId)
return new(ServiceResponseStatus.NotFound);

// Map it to DTO and return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using AdvancedTodoList.Core.Dtos;
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists.Members;
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Repositories;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.Core.Services.Auth;
using AdvancedTodoList.Infrastructure.Specifications;
using Mapster;
using System.Security;

namespace AdvancedTodoList.Infrastructure.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using AdvancedTodoList.Core.Dtos;
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists.Members;
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Repositories;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.Core.Services.Auth;
using AdvancedTodoList.Infrastructure.Specifications;
using Mapster;
using System.Security;

namespace AdvancedTodoList.Infrastructure.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using AdvancedTodoList.Core.Services.Auth;
using AdvancedTodoList.Infrastructure.Specifications;
using Mapster;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace AdvancedTodoList.Infrastructure.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.IntegrationTests.Fixtures;
using NUnit.Framework.Interfaces;
using System.Net;
using System.Net.Http.Json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task GetTodoListMembersAsync_ListExists_SucceedsAndReturnsItems()
WebApplicationFactory.TodoListMembersService
.GetMembersAsync(TestContext, parameters)
.Returns(x => new ServiceResponse<Page<TodoListMemberPreviewDto>>(ServiceResponseStatus.Success,
new (members, ((PaginationParameters)x[1]).Page, ((PaginationParameters)x[1]).PageSize, 22)));
new(members, ((PaginationParameters)x[1]).Page, ((PaginationParameters)x[1]).PageSize, 22)));
using HttpClient client = CreateAuthorizedHttpClient();

// Act: send the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using AdvancedTodoList.Core.Repositories;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.Core.Services.Auth;
using AdvancedTodoList.Infrastructure.Services.Auth;
using AdvancedTodoList.IntegrationTests.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists;
using AdvancedTodoList.Core.Models.TodoLists;
using AdvancedTodoList.Core.Models.TodoLists.Members;
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Services;
using AdvancedTodoList.Core.Specifications;
using AdvancedTodoList.IntegrationTests.Fixtures;
using AdvancedTodoList.IntegrationTests.Utils;
using Mapster;
using NSubstitute;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;

namespace AdvancedTodoList.IntegrationTests.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AdvancedTodoList.Core.Dtos;
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists.Members;
using AdvancedTodoList.Core.Pagination;
using AdvancedTodoList.Core.Services;
Expand All @@ -8,7 +7,6 @@
using AdvancedTodoList.IntegrationTests.Fixtures;
using AdvancedTodoList.IntegrationTests.Utils;
using NUnit.Framework.Internal;
using Org.BouncyCastle.Asn1.X509;

namespace AdvancedTodoList.IntegrationTests.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using AdvancedTodoList.Infrastructure.Specifications;
using AdvancedTodoList.IntegrationTests.Fixtures;
using AdvancedTodoList.IntegrationTests.Utils;
using System.Data;

namespace AdvancedTodoList.IntegrationTests.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using AdvancedTodoList.IntegrationTests.Fixtures;
using AdvancedTodoList.IntegrationTests.Utils;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework.Interfaces;
using System;

namespace AdvancedTodoList.IntegrationTests.Services;

Expand Down Expand Up @@ -196,7 +194,7 @@ public async Task EditAsync_UserHasNoPermission_ReturnsForbidden()
.GetByIdAsync(todoList.Id)
.Returns(todoList);
WebApplicationFactory.PermissionsChecker
.CanTouchEntityAsync<TodoList, string>(new(todoList.Id, TestUserId),
.CanTouchEntityAsync<TodoList, string>(new(todoList.Id, TestUserId),
Arg.Any<TodoList>(), Arg.Any<Func<RolePermissions, bool>>())
.Returns(false);

Expand Down

0 comments on commit b32cf3a

Please sign in to comment.