Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serialize Tests] DCSBIOSActionBinding - OSCommandBinding #481

Merged
merged 13 commits into from
Feb 18, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.DCSBIOSBindings
{
[Serializable]
[SerializeCriticalCustom]
public class DCSBIOSActionBindingFarmingPanel : DCSBIOSActionBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.DCSBIOSBindings
{
[Serializable]
[SerializeCriticalCustom]
public class DCSBIOSActionBindingPZ55 : DCSBIOSActionBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.DCSBIOSBindings
{
[Serializable]
[SerializeCriticalCustom]
public class DCSBIOSActionBindingPZ69 : DCSBIOSActionBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using ClassLibraryCommon;
using MEF;
using NonVisuals.Panels.Saitek.Panels;

namespace NonVisuals.BindingClasses.DCSBIOSBindings
{
[Serializable]
[SerializeCriticalCustom]
public class DCSBIOSActionBindingPZ70 : DCSBIOSActionBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.DCSBIOSBindings
{
[Serializable]
[SerializeCriticalCustom]
public class DCSBIOSActionBindingTPM : DCSBIOSActionBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingFarmingPanel : OSCommandBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using ClassLibraryCommon;
using MEF;
using NonVisuals.Panels.Saitek;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingPZ55 : OSCommandBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingPZ69Emulator : OSCommandBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingPZ69FullEmulator : OSCommandBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using ClassLibraryCommon;
using MEF;
using NonVisuals.Panels.Saitek.Panels;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingPZ70 : OSCommandBindingBase
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using ClassLibraryCommon;
using MEF;

namespace NonVisuals.BindingClasses.OSCommand
{
[Serializable]
[SerializeCriticalCustom]
public class OSCommandBindingTPM : OSCommandBindingBase
{
/*
Expand Down
3 changes: 3 additions & 0 deletions src/Tests/Serialization/Common/RepositorySerialized.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal string GetSerializedObjectString(Type objectType)
return File.ReadAllText(GetFile(objectType));
}

/// <summary>
/// Even if this function has 0 references, do not delete this, used in tests
/// </summary>
internal void SaveSerializedObjectToFile(Type objectType, string serialized)
{
string mockFolderPath = GetMockFolderPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DCSFPTests.Serialization.Common;
using Newtonsoft.Json;
using NonVisuals.BindingClasses.DCSBIOSBindings;
using Xunit;

namespace DCSFPTests.Serialization {
public class DCSBIOSActionBindingFarmingPanel_SerializeTests {
[Fact]
public static void DCSBIOSActionBindingFarmingPanel_ShouldBeSerializable() {
DCSBIOSActionBindingFarmingPanel s = GetObject();

string serializedObj = JsonConvert.SerializeObject(s, Formatting.Indented, JSonSettings.JsonDefaultSettings);
DCSBIOSActionBindingFarmingPanel d = JsonConvert.DeserializeObject<DCSBIOSActionBindingFarmingPanel>(serializedObj, JSonSettings.JsonDefaultSettings);

Assert.Equal(s.FarmingPanelKey, d.FarmingPanelKey);
Assert.Equal(s.WhenTurnedOn, d.WhenTurnedOn);
Assert.Equal(s.Description, d.Description);
Assert.Equal(s.IsSequenced, d.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, d.DCSBIOSInputs);


RepositorySerialized repo = new();
//Save sample file in project (use it only once)
//repo.SaveSerializedObjectToFile(s.GetType(), serializedObj);

DCSBIOSActionBindingFarmingPanel deseralizedObjFromFile = JsonConvert.DeserializeObject<DCSBIOSActionBindingFarmingPanel>(repo.GetSerializedObjectString(s.GetType()), JSonSettings.JsonDefaultSettings);

Assert.Equal(s.FarmingPanelKey, deseralizedObjFromFile.FarmingPanelKey);
Assert.Equal(s.WhenTurnedOn, deseralizedObjFromFile.WhenTurnedOn);
Assert.Equal(s.Description, deseralizedObjFromFile.Description);
Assert.Equal(s.IsSequenced, deseralizedObjFromFile.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, deseralizedObjFromFile.DCSBIOSInputs);
}

private static DCSBIOSActionBindingFarmingPanel GetObject(int instanceNbr = 1) {
return new()
{
FarmingPanelKey = KeyBindingFarmingPanel_SerializeTests.GetFarmingPanelMKKeysFromInstance(instanceNbr + 9),
WhenTurnedOn = true,
Description = $"dkk aqk {instanceNbr}",
IsSequenced = true,
DCSBIOSInputs = new(){
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 7),
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 8)
}
};
}
}
}
49 changes: 49 additions & 0 deletions src/Tests/Serialization/DCSBIOSActionBindingPZ55_SerializeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DCSFPTests.Serialization.Common;
using Newtonsoft.Json;
using NonVisuals.BindingClasses.DCSBIOSBindings;
using Xunit;

namespace DCSFPTests.Serialization {
public class DCSBIOSActionBindingPZ55_SerializeTests {
[Fact]
public static void DCSBIOSActionBindingPZ55_ShouldBeSerializable() {
DCSBIOSActionBindingPZ55 s = GetObject();

string serializedObj = JsonConvert.SerializeObject(s, Formatting.Indented, JSonSettings.JsonDefaultSettings);
DCSBIOSActionBindingPZ55 d = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ55>(serializedObj, JSonSettings.JsonDefaultSettings);

Assert.Equal(s.SwitchPanelPZ55Key, d.SwitchPanelPZ55Key);
Assert.Equal(s.WhenTurnedOn, d.WhenTurnedOn);
Assert.Equal(s.Description, d.Description);
Assert.Equal(s.IsSequenced, d.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, d.DCSBIOSInputs);


RepositorySerialized repo = new();
//Save sample file in project (use it only once)
//repo.SaveSerializedObjectToFile(s.GetType(), serializedObj);

DCSBIOSActionBindingPZ55 deseralizedObjFromFile = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ55>(repo.GetSerializedObjectString(s.GetType()), JSonSettings.JsonDefaultSettings);

Assert.Equal(s.SwitchPanelPZ55Key, deseralizedObjFromFile.SwitchPanelPZ55Key);
Assert.Equal(s.WhenTurnedOn, deseralizedObjFromFile.WhenTurnedOn);
Assert.Equal(s.Description, deseralizedObjFromFile.Description);
Assert.Equal(s.IsSequenced, deseralizedObjFromFile.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, deseralizedObjFromFile.DCSBIOSInputs);
}

private static DCSBIOSActionBindingPZ55 GetObject(int instanceNbr = 1) {
return new()
{
SwitchPanelPZ55Key = KeyBindingPZ55_SerializeTests.GetSwitchPanelPZ55KeysFromInstance(instanceNbr + 4),
WhenTurnedOn = true,
Description = $"iiu kkh {instanceNbr}",
IsSequenced = true,
DCSBIOSInputs = new(){
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 2),
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 3)
}
};
}
}
}
52 changes: 52 additions & 0 deletions src/Tests/Serialization/DCSBIOSActionBindingPZ69_SerializeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using DCSFPTests.Serialization.Common;
using Newtonsoft.Json;
using NonVisuals.BindingClasses.DCSBIOSBindings;
using Xunit;

namespace DCSFPTests.Serialization {
public class DCSBIOSActionBindingPZ69_SerializeTests {
[Fact]
public static void DCSBIOSActionBindingPZ69_ShouldBeSerializable() {
DCSBIOSActionBindingPZ69 s = GetObject();

string serializedObj = JsonConvert.SerializeObject(s, Formatting.Indented, JSonSettings.JsonDefaultSettings);
DCSBIOSActionBindingPZ69 d = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ69>(serializedObj, JSonSettings.JsonDefaultSettings);

Assert.Equal(s.DialPosition, d.DialPosition);
Assert.Equal(s.RadioPanelPZ69Knob, d.RadioPanelPZ69Knob);
Assert.Equal(s.WhenTurnedOn, d.WhenTurnedOn);
Assert.Equal(s.Description, d.Description);
Assert.Equal(s.IsSequenced, d.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, d.DCSBIOSInputs);


RepositorySerialized repo = new();
//Save sample file in project (use it only once)
//repo.SaveSerializedObjectToFile(s.GetType(), serializedObj);

DCSBIOSActionBindingPZ69 deseralizedObjFromFile = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ69>(repo.GetSerializedObjectString(s.GetType()), JSonSettings.JsonDefaultSettings);

Assert.Equal(s.DialPosition, deseralizedObjFromFile.DialPosition);
Assert.Equal(s.RadioPanelPZ69Knob, deseralizedObjFromFile.RadioPanelPZ69Knob);
Assert.Equal(s.WhenTurnedOn, deseralizedObjFromFile.WhenTurnedOn);
Assert.Equal(s.Description, deseralizedObjFromFile.Description);
Assert.Equal(s.IsSequenced, deseralizedObjFromFile.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, deseralizedObjFromFile.DCSBIOSInputs);
}

private static DCSBIOSActionBindingPZ69 GetObject(int instanceNbr = 1) {
return new()
{
DialPosition = KeyBindingPZ69DialPosition_SerializeTests.GetPZ69DialPositionFromInstance(instanceNbr+7),
RadioPanelPZ69Knob = KeyBindingPZ69_SerializeTests.GetRadioPanelPZ69KnobsEmulatorFromInstance(instanceNbr + 3),
WhenTurnedOn = true,
Description = $"dds ola {instanceNbr}",
IsSequenced = true,
DCSBIOSInputs = new(){
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 3),
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 4)
}
};
}
}
}
52 changes: 52 additions & 0 deletions src/Tests/Serialization/DCSBIOSActionBindingPZ70_SerializeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using DCSFPTests.Serialization.Common;
using Newtonsoft.Json;
using NonVisuals.BindingClasses.DCSBIOSBindings;
using Xunit;

namespace DCSFPTests.Serialization {
public class DCSBIOSActionBindingPZ70_SerializeTests {
[Fact]
public static void DCSBIOSActionBindingPZ70_ShouldBeSerializable() {
DCSBIOSActionBindingPZ70 s = GetObject();

string serializedObj = JsonConvert.SerializeObject(s, Formatting.Indented, JSonSettings.JsonDefaultSettings);
DCSBIOSActionBindingPZ70 d = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ70>(serializedObj, JSonSettings.JsonDefaultSettings);

Assert.Equal(s.DialPosition, d.DialPosition);
Assert.Equal(s.MultiPanelPZ70Knob, d.MultiPanelPZ70Knob);
Assert.Equal(s.WhenTurnedOn, d.WhenTurnedOn);
Assert.Equal(s.Description, d.Description);
Assert.Equal(s.IsSequenced, d.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, d.DCSBIOSInputs);


RepositorySerialized repo = new();
//Save sample file in project (use it only once)
//repo.SaveSerializedObjectToFile(s.GetType(), serializedObj);

DCSBIOSActionBindingPZ70 deseralizedObjFromFile = JsonConvert.DeserializeObject<DCSBIOSActionBindingPZ70>(repo.GetSerializedObjectString(s.GetType()), JSonSettings.JsonDefaultSettings);

Assert.Equal(s.DialPosition, deseralizedObjFromFile.DialPosition);
Assert.Equal(s.MultiPanelPZ70Knob, deseralizedObjFromFile.MultiPanelPZ70Knob);
Assert.Equal(s.WhenTurnedOn, deseralizedObjFromFile.WhenTurnedOn);
Assert.Equal(s.Description, deseralizedObjFromFile.Description);
Assert.Equal(s.IsSequenced, deseralizedObjFromFile.IsSequenced);
DeepAssert.Equal(s.DCSBIOSInputs, deseralizedObjFromFile.DCSBIOSInputs);
}

private static DCSBIOSActionBindingPZ70 GetObject(int instanceNbr = 1) {
return new()
{
DialPosition = KeyBindingPZ70_SerializeTests.GetPZ70DialPositionFromInstance(instanceNbr + 4),
MultiPanelPZ70Knob = KeyBindingPZ70_SerializeTests.GetMultiPanelPZ70KnobsFromInstance(instanceNbr + 5),
WhenTurnedOn = true,
Description = $"ecs ivt {instanceNbr}",
IsSequenced = true,
DCSBIOSInputs = new(){
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 5),
DCSBIOSInput_SerializeTests.GetObject(instanceNbr + 6)
}
};
}
}
}
Loading
Loading