-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Team-Wilhelm/final-tweaks
Small changes
- Loading branch information
Showing
27 changed files
with
234 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Shared.Models; | ||
|
||
public class Stats | ||
{ | ||
public int TotalPlants { get; set; } | ||
public int HappyPlants { get; set; } | ||
public int Collections { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Text.Json; | ||
using api.Events.Global; | ||
using lib; | ||
using Websocket.Client; | ||
|
||
namespace Tests | ||
{ | ||
public class WebSocketTestClient | ||
{ | ||
public readonly WebsocketClient Client; | ||
public readonly List<BaseDto> ReceivedMessages = []; | ||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}; | ||
|
||
public WebSocketTestClient(string? url = null) | ||
{ | ||
Client = url == null ? new WebsocketClient(new Uri("ws://localhost:" + (Environment.GetEnvironmentVariable("FULLSTACK_API_PORT") ?? "8181"))) : new WebsocketClient(new Uri(url)); | ||
Client.MessageReceived.Subscribe(msg => | ||
{ | ||
BaseDto baseDto = JsonSerializer.Deserialize<BaseDto>(msg.Text, JsonSerializerOptions); | ||
|
||
if (baseDto.eventType == "ServerSendsErrorMessage" || baseDto.eventType.Contains("ServerResponds") || | ||
baseDto.eventType.Contains("ServerRejects")) | ||
{ | ||
var error = JsonSerializer.Deserialize<ServerSendsErrorMessage>(msg.Text, JsonSerializerOptions); | ||
Console.WriteLine("Error: " + error!.Error); | ||
} | ||
|
||
lock (ReceivedMessages) | ||
ReceivedMessages.Add(baseDto); | ||
}); | ||
} | ||
|
||
public async Task<WebSocketTestClient> ConnectAsync() | ||
{ | ||
await Client.Start(); | ||
if (!Client.IsRunning) | ||
throw new Exception("Could not start client!"); | ||
return this; | ||
} | ||
|
||
public void Send<T>(T dto) where T : BaseDto | ||
{ | ||
Client.Send(JsonSerializer.Serialize(dto)); | ||
} | ||
|
||
public async Task DoAndAssert<T>(T? action = null, Func<List<BaseDto>, bool>? condition = null) where T : BaseDto | ||
{ | ||
if ((object) (T) action != null) | ||
Send(action); | ||
if (condition != null) | ||
{ | ||
DateTime startTime = DateTime.UtcNow; | ||
while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(5.0)) | ||
{ | ||
lock (ReceivedMessages) | ||
{ | ||
if (condition(ReceivedMessages)) | ||
return; | ||
} | ||
await Task.Delay(100); | ||
} | ||
throw new TimeoutException("Condition not met: "); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Infrastructure.Repositories; | ||
using Shared.Dtos; | ||
using Shared.Models; | ||
|
||
namespace api.Core.Services; | ||
|
||
public class StatsService(PlantRepository plantRepository) | ||
{ | ||
public async Task<Stats> GetStats(string email) | ||
{ | ||
return await plantRepository.GetStats(email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace api; | ||
|
||
public static class EnvironmentHelper | ||
{ | ||
private static readonly List<string?> NonProdEnvironments = ["Development", "Testing"]; | ||
|
||
public static bool IsTesting() | ||
{ | ||
return Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Testing"; | ||
} | ||
|
||
public static bool IsDevelopment() | ||
{ | ||
return Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"; | ||
} | ||
|
||
public static bool IsNonProd() | ||
{ | ||
return NonProdEnvironments.Contains(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")); | ||
} | ||
|
||
public static bool IsCi() | ||
{ | ||
return Environment.GetEnvironmentVariable("CI") == "true"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.