-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 #105 from pkuehnel/develop
Develop
- Loading branch information
Showing
17 changed files
with
379 additions
and
60 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
107 changes: 107 additions & 0 deletions
107
SmartTeslaAmpSetter.Tests/Wrappers/ConfigurationWrapper.cs
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,107 @@ | ||
using System; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SmartTeslaAmpSetter.Tests.Wrappers; | ||
|
||
public class ConfigurationWrapper : TestBase | ||
{ | ||
public ConfigurationWrapper(ITestOutputHelper outputHelper) | ||
: base(outputHelper) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Get_Not_Nullable_String() | ||
{ | ||
var configurationService = Mock.Create<Server.Wrappers.ConfigurationWrapper>(); | ||
|
||
var existingConfigValue = "TeslaMateApiBaseUrl"; | ||
var teslaMateApiBaseUrl = | ||
configurationService.GetNotNullableConfigurationValue(existingConfigValue); | ||
|
||
Assert.Equal("http://192.168.1.50:8097", teslaMateApiBaseUrl); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("notExisiting")] | ||
public void Throw_Exception_On_Null_String(string notExisitingConfigValue) | ||
{ | ||
var configurationService = Mock.Create<Server.Wrappers.ConfigurationWrapper>(); | ||
Assert.Throws<NullReferenceException>( | ||
() => configurationService.GetNotNullableConfigurationValue(notExisitingConfigValue)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("notExisiting")] | ||
public void Returns_Null_On_Non_Exisiting_Values(string notExisitingConfigValue) | ||
{ | ||
var configurationService = Mock.Create<Server.Wrappers.ConfigurationWrapper>(); | ||
var value = configurationService.GetNullableConfigurationValue(notExisitingConfigValue); | ||
|
||
Assert.Null(value); | ||
} | ||
|
||
[Theory] | ||
[InlineData("ten")] | ||
[InlineData("one")] | ||
[InlineData("zero")] | ||
[InlineData("notExisiting")] | ||
public void Get_TimeSpan_From_Minutes(string configName) | ||
{ | ||
var configurationService = Mock.Create<Server.Wrappers.ConfigurationWrapper>(); | ||
var timespan = | ||
configurationService.GetMinutesConfigurationValueIfGreaterThanMinumum(configName, TimeSpan.FromMinutes(1)); | ||
|
||
switch (configName) | ||
{ | ||
case "ten": | ||
Assert.Equal(TimeSpan.FromMinutes(10), timespan); | ||
break; | ||
case "one": | ||
Assert.Equal(TimeSpan.FromMinutes(1), timespan); | ||
break; | ||
case "zero": | ||
Assert.Equal(TimeSpan.FromMinutes(1), timespan); | ||
break; | ||
case "notExisiting": | ||
Assert.Equal(TimeSpan.FromMinutes(1), timespan); | ||
break; | ||
default: | ||
throw new NotImplementedException("Config name not converd in this test"); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("ten")] | ||
[InlineData("one")] | ||
[InlineData("zero")] | ||
[InlineData("notExisiting")] | ||
public void Get_TimeSpan_From_Seconds(string configName) | ||
{ | ||
var configurationService = Mock.Create<Server.Wrappers.ConfigurationWrapper>(); | ||
var minimum = TimeSpan.FromSeconds(1); | ||
var timespan = | ||
configurationService.GetSecondsConfigurationValueIfGreaterThanMinumum(configName, minimum); | ||
|
||
switch (configName) | ||
{ | ||
case "ten": | ||
Assert.Equal(TimeSpan.FromSeconds(10), timespan); | ||
break; | ||
case "one": | ||
Assert.Equal(TimeSpan.FromSeconds(1), timespan); | ||
break; | ||
case "zero": | ||
Assert.Equal(TimeSpan.FromSeconds(1), timespan); | ||
break; | ||
case "notExisiting": | ||
Assert.Equal(TimeSpan.FromSeconds(1), timespan); | ||
break; | ||
default: | ||
throw new NotImplementedException("Config name not converd in this test"); | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
SmartTeslaAmpSetter/Server/Contracts/IConfigurationWrapper.cs
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,21 @@ | ||
namespace SmartTeslaAmpSetter.Server.Contracts; | ||
|
||
public interface IConfigurationWrapper | ||
{ | ||
string ConfigFileLocation(); | ||
TimeSpan UpdateIntervall(); | ||
string MqqtClientId(); | ||
string MosquitoServer(); | ||
string CurrentPowerToGridUrl(); | ||
string? CurrentInverterPowerUrl(); | ||
string? CurrentPowerToGridJsonPattern(); | ||
bool CurrentPowerToGridInvertValue(); | ||
string TeslaMateApiBaseUrl(); | ||
List<int> CarPriorities(); | ||
string GeoFence(); | ||
TimeSpan TimeUntilSwitchOn(); | ||
TimeSpan TimespanUntilSwitchOff(); | ||
int PowerBuffer(); | ||
string? TelegramBotKey(); | ||
string? TelegramChannelId(); | ||
} |
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,6 @@ | ||
namespace SmartTeslaAmpSetter.Server.Contracts; | ||
|
||
public interface IMqttService | ||
{ | ||
Task ConfigureMqttClient(); | ||
} |
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.