Skip to content

Commit

Permalink
fix(Tests): fix FleetApiTest for handling unsinged commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuehnel committed Jan 14, 2024
1 parent d9fa31e commit d50cdea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using TeslaSolarCharger.Server.Dtos.TeslaFleetApi;
using Xunit;
using Xunit.Abstractions;

namespace TeslaSolarCharger.Tests.Services.Server;

[SuppressMessage("ReSharper", "UseConfigureAwaitFalse")]
public class TeslaFleetApiService(ITestOutputHelper outputHelper) : TestBase(outputHelper)
{
[Fact]
Expand All @@ -14,6 +16,11 @@ public async Task CanHandleUnsignedCommands()
var commandResult = JsonConvert.DeserializeObject<DtoGenericTeslaResponse<DtoVehicleCommandResult>>("{\"response\":{\"result\":false,\"reason\":\"unsigned_cmds_hardlocked\"}}");
Assert.NotNull(commandResult?.Response);
var fleetApiService = Mock.Create<TeslaSolarCharger.Server.Services.TeslaFleetApiService>();
await fleetApiService.HandleUnsignedCommands(commandResult.Response).ConfigureAwait(false);
var fleetApiProxyNeeded = await fleetApiService.IsFleetApiProxyNeededInDatabase();
Assert.False(fleetApiProxyNeeded);
await fleetApiService.HandleUnsignedCommands(commandResult.Response);
fleetApiProxyNeeded = await fleetApiService.IsFleetApiProxyNeededInDatabase();
Assert.True(fleetApiProxyNeeded);

}
}
4 changes: 4 additions & 0 deletions TeslaSolarCharger.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using TeslaSolarCharger.Server.MappingExtensions;
using TeslaSolarCharger.Shared.Contracts;
using TeslaSolarCharger.Shared.TimeProviding;
using TeslaSolarCharger.SharedBackend.Contracts;
using Xunit.Abstractions;
using Constants = TeslaSolarCharger.SharedBackend.Values.Constants;

namespace TeslaSolarCharger.Tests;

Expand Down Expand Up @@ -58,6 +60,7 @@ protected TestBase(

_fake = new AutoFake();
_fake.Provide<IMapperConfigurationFactory, MapperConfigurationFactory>();
_fake.Provide<IConstants, Constants>();
_fake.Provide<IDateTimeProvider>(new FakeDateTimeProvider(currentFakeTime));
_fake.Provide<IConfiguration>(configuration);

Expand All @@ -66,6 +69,7 @@ protected TestBase(
{
b.Register((_, _) => Context);
b.Register((_, _) => _fake.Resolve<IMapperConfigurationFactory>());
b.Register((_, _) => _fake.Resolve<IConstants>());
b.Register((_, _) => _fake.Resolve<IConfiguration>());
b.RegisterType<FakeDateTimeProvider>();
//b.Register((_, _) => _fake.Resolve<IDateTimeProvider>());
Expand Down

0 comments on commit d50cdea

Please sign in to comment.