Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Aug 13, 2023
1 parent e06e41e commit 1e3b069
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 43 deletions.
1 change: 0 additions & 1 deletion Application/Usecases/CreateGameUsecase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Application.Common;
using Domain;
using Domain.Common;
using Domain.Events;

namespace Application.Usecases;

Expand Down
2 changes: 1 addition & 1 deletion Client/Options/BackendApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class BackendApiOptions
public string BaseUrl { get; set; } = default!;
public BackendApiOptions()
{

}
}
2 changes: 1 addition & 1 deletion Client/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override async Task OnInitializedAsync()
return;
}

foreach(var token in tokens)
foreach (var token in tokens)
{
AddUser(token);
}
Expand Down
12 changes: 6 additions & 6 deletions Domain/Block.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Domain.Events;
using Domain.Common;
using Domain.Events;

namespace Domain;

Expand Down Expand Up @@ -142,7 +142,7 @@ public override void UpdateOwner(Player Owner)

public virtual DomainEvent BuildHouse(Player player)
{
if(GetOwner() == player)
if (GetOwner() == player)
{
if (house == MAX_HOUSE) return new HouseMaxEvent(player.Monopoly.Id, player.Id, Id, house);

Expand All @@ -156,13 +156,13 @@ public virtual DomainEvent BuildHouse(Player player)
{
return new PlayerTooPoorToBuildHouseEvent(player.Monopoly.Id, player.Id, Id, player.Money, UpgradePrice);
}

}
else
{
return new PlayerCannotBuildHouseEvent(player.Monopoly.Id, player.Id, Id);
}

}
}

Expand All @@ -189,7 +189,7 @@ public ParkingLot(string id) : base(id)

public class Station : Land
{
public Station(string id, decimal price = 1000, string lot = "S") : base(id, price,lot)
public Station(string id, decimal price = 1000, string lot = "S") : base(id, price, lot)
{
}

Expand All @@ -205,7 +205,7 @@ public override decimal CalcullateToll(Player payee)
return _price * lotCount;
}

public override decimal GetMortgagePrice() => _price*(decimal)0.7;
public override decimal GetMortgagePrice() => _price * (decimal)0.7;

public override decimal GetRedeemPrice() => _price;

Expand Down
4 changes: 2 additions & 2 deletions Domain/Events/PlayerMortgageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Domain.Events;

public record PlayerMortgageEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId, int DeadLine)
public record PlayerMortgageEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId, int DeadLine)
: DomainEvent(GameId);

public record PlayerCannotMortgageEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId)
public record PlayerCannotMortgageEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId)
: DomainEvent(GameId);
8 changes: 4 additions & 4 deletions Domain/Events/PlayerPayTollEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Domain.Events;

public record PlayerNeedsToPayTollEvent(string GameId, string PlayerId, string ownerId, decimal toll)
public record PlayerNeedsToPayTollEvent(string GameId, string PlayerId, string ownerId, decimal toll)
: DomainEvent(GameId);

public record PlayerPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney, string ownerId, decimal ownerMoney)
public record PlayerPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney, string ownerId, decimal ownerMoney)
: DomainEvent(GameId);

public record PlayerDoesntNeedToPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney)
public record PlayerDoesntNeedToPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney)
: DomainEvent(GameId);

public record PlayerTooPoorToPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney, decimal toll)
public record PlayerTooPoorToPayTollEvent(string GameId, string PlayerId, decimal PlayerMoney, decimal toll)
: DomainEvent(GameId);
6 changes: 3 additions & 3 deletions Domain/Events/PlayerRedeemEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Domain.Events;

public record PlayerRedeemEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId)
public record PlayerRedeemEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId)
: DomainEvent(GameId);

public record PlayerTooPoorToRedeemEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId, decimal RedeemPrice)
public record PlayerTooPoorToRedeemEvent(string GameId, string PlayerId, decimal PlayerMoney, string BlockId, decimal RedeemPrice)
: DomainEvent(GameId);

public record LandNotInMortgageEvent(string GameId, string PlayerId, string BlockId)
public record LandNotInMortgageEvent(string GameId, string PlayerId, string BlockId)
: DomainEvent(GameId);
17 changes: 9 additions & 8 deletions Domain/Player.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Domain.Common;
using Domain.Events;
using System.Numerics;
using Domain.Interfaces;
using Domain.Common;

namespace Domain;

Expand Down Expand Up @@ -96,11 +95,12 @@ internal void SelectDirection(Map.Direction direction)

internal DomainEvent MortgageLandContract(string landId)
{
if(mortgages.Exists(m => m.LandContract.Land.Id == landId))
if (mortgages.Exists(m => m.LandContract.Land.Id == landId))
{
return new PlayerCannotMortgageEvent(Monopoly.Id, Id, Money, landId);
}
else{
else
{
var landContract = _landContractList.First(l => l.Land.Id == landId);
mortgages.Add(new Mortgage(this, landContract));
Money += landContract.Land.GetMortgagePrice();
Expand All @@ -112,10 +112,10 @@ internal DomainEvent MortgageLandContract(string landId)

internal DomainEvent RedeemLandContract(string landId)
{
if(mortgages.Exists(m => m.LandContract.Land.Id == landId))
if (mortgages.Exists(m => m.LandContract.Land.Id == landId))
{
var landContract = _landContractList.First(l => l.Land.Id == landId);
if(Money >= landContract.Land.GetRedeemPrice())
if (Money >= landContract.Land.GetRedeemPrice())
{
Money -= landContract.Land.GetRedeemPrice();
mortgages.RemoveAll(m => m.LandContract.Land.Id == landId);
Expand All @@ -126,7 +126,8 @@ internal DomainEvent RedeemLandContract(string landId)
return new PlayerTooPoorToRedeemEvent(Monopoly.Id, Id, Money, landId, landContract.Land.GetRedeemPrice());
}
}
else{
else
{
return new LandNotInMortgageEvent(Monopoly.Id, Id, landId);
}
}
Expand All @@ -150,7 +151,7 @@ public DomainEvent BuildHouse()
{
Block block = Chess.CurrentBlock;

if(block is Land land)
if (block is Land land)
{
return land.BuildHouse(this);
}
Expand Down
2 changes: 1 addition & 1 deletion Server/Hubs/WhoAmIHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Server.Hubs;

[Authorize]
public class WhoAmIHub: Hub
public class WhoAmIHub : Hub
{
public async Task WhoAmI()
{
Expand Down
6 changes: 3 additions & 3 deletions Server/MonopolyEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public async Task PublishAsync(IEnumerable<DomainEvent> events)
{
await _hubContext.Clients.All.PlayerBuyBlockInsufficientFundsEvent(pbbife.PlayerId, pbbife.BlockId, pbbife.landMoney);
}
else if(e is PlayerPayTollEvent ppte)
else if (e is PlayerPayTollEvent ppte)
{
await _hubContext.Clients.All.PlayerPayTollEvent(ppte.PlayerId, ppte.PlayerMoney, ppte.ownerId, ppte.ownerMoney);
}
else if(e is PlayerDoesntNeedToPayTollEvent pdnpte)
else if (e is PlayerDoesntNeedToPayTollEvent pdnpte)
{
await _hubContext.Clients.All.PlayerDoesntNeedToPayTollEvent(pdnpte.PlayerId, pdnpte.PlayerMoney);
}
else if(e is PlayerTooPoorToPayTollEvent ptppte)
else if (e is PlayerTooPoorToPayTollEvent ptppte)
{
await _hubContext.Clients.All.PlayerTooPoorToPayTollEvent(ptppte.PlayerId, ptppte.PlayerMoney, ptppte.toll);
}
Expand Down
2 changes: 1 addition & 1 deletion Server/PlatformJwtEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public PlatformJwtEvents()
{
var queryToken = context.Request.Query["access_token"].ToString();
var headerToken = context.HttpContext.Request.Headers.Authorization.FirstOrDefault()?.Replace("Bearer ", "");
var token = string.IsNullOrEmpty(queryToken) ? headerToken : queryToken;
var path = context.HttpContext.Request.Path;
Expand Down
2 changes: 1 addition & 1 deletion Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
{
string projectDirectory = AppDomain.CurrentDomain.BaseDirectory;
string jsonFilePath = Path.Combine(projectDirectory, "Maps", $"{mapId}.json");
if (File.Exists(jsonFilePath))
{
// read json file
Expand Down
2 changes: 0 additions & 2 deletions Test/ServerTests/AcceptanceTests/CreateGameTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Application.Common;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Server.DataModels;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Security.Claims;

namespace ServerTests.AcceptanceTests;

Expand Down
8 changes: 4 additions & 4 deletions Test/ServerTests/AcceptanceTests/PayTollTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task 玩家在別人的土地上付過路費()
// A 付過路費
hub.Verify<string, decimal, string, decimal>(
nameof(IMonopolyResponses.PlayerPayTollEvent),
(playerId, playerMoney, ownerId, ownerMoney)
(playerId, playerMoney, ownerId, ownerMoney)
=> playerId == "A" && playerMoney == 950 && ownerId == "B" && ownerMoney == 1050);
hub.VerifyNoElseEvent();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public async Task 地主在監獄中玩家無須付過路費()
// A 付過路費
hub.Verify<string, decimal>(
nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent),
(playerId, playerMoney)
(playerId, playerMoney)
=> playerId == "A" && playerMoney == 1000);
hub.VerifyNoElseEvent();
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public async Task 地主在停車場玩家無須付過路費()
// A 付過路費
hub.Verify<string, decimal>(
nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent),
(playerId, playerMoney)
(playerId, playerMoney)
=> playerId == "A" && playerMoney == 1000);
hub.VerifyNoElseEvent();
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public async Task 玩家在別人的土地上但餘額不足以付過路費()
// A 付過路費
hub.Verify<string, decimal, decimal>(
nameof(IMonopolyResponses.PlayerTooPoorToPayTollEvent),
(playerId, playerMoney, toll)
(playerId, playerMoney, toll)
=> playerId == "A" && playerMoney == 30 && toll == 50);
hub.VerifyNoElseEvent();
}
Expand Down
1 change: 0 additions & 1 deletion Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Server.DataModels;
using Server.Repositories;
using SharedLibrary;
using System.Net.Http.Headers;
using System.Net.Http.Json;
Expand Down
8 changes: 4 additions & 4 deletions Test/ServerTests/MonopolyTestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public async Task<VerificationHub> CreateHubConnectionAsync(string gameId, strin
opt.AccessTokenProvider = async () =>
{
var options = GetRequiredService<IOptionsMonitor<JwtBearerOptions>>();
var jwtToken = GetRequiredService<MockJwtTokenService>()
.GenerateJwtToken(options.Get("Bearer").Audience, playerId);
return await Task.FromResult(jwtToken);
};
opt.HttpMessageHandlerFactory = _ => Server.CreateHandler();
opt.HttpMessageHandlerFactory = _ => Server.CreateHandler();
})
.Build();
VerificationHub verificationHub = new(hub);
Expand Down Expand Up @@ -146,7 +146,7 @@ private void Verify(string methodName, Func<object[], bool> verify, int timeout)
// 如果已經斷開連線測試失敗
if (Connection.State == HubConnectionState.Disconnected)
{
if(Queues[nameof(IMonopolyResponses.PlayerJoinGameFailedEvent)].TryPeek(out var errorMessages))
if (Queues[nameof(IMonopolyResponses.PlayerJoinGameFailedEvent)].TryPeek(out var errorMessages))
Assert.Fail(
$"""
已經斷開連線
Expand All @@ -158,7 +158,7 @@ private void Verify(string methodName, Func<object[], bool> verify, int timeout)
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (elapsedMilliseconds >= timeout)
{
Assert.Fail(
Assert.Fail(
$"""
超出預期時間 {timeout} ms,預期得到 Event【{methodName}
可以嘗試檢查下面的問題:
Expand Down

0 comments on commit 1e3b069

Please sign in to comment.