2021-01-09 12:06:32 +01:00
using System.Linq ;
2019-08-29 16:57:20 +02:00
using ChanSort.Api ;
2021-01-09 12:06:32 +01:00
using ChanSort.Loader.Philips ;
2019-08-29 16:57:20 +02:00
using Microsoft.VisualStudio.TestTools.UnitTesting ;
2021-01-09 12:06:32 +01:00
namespace Test.Loader.Philips
2019-08-29 16:57:20 +02:00
{
[TestClass]
public class PhilipsXmlTest
{
2021-08-31 22:13:28 +02:00
#region TestRepairFormatCableChannelsAddedToCorrectLists
2019-08-29 16:57:20 +02:00
[TestMethod]
2021-08-31 22:13:28 +02:00
public void TestRepairFormatCableChannelsAddedToCorrectLists ( )
2019-08-29 16:57:20 +02:00
{
2021-08-31 22:13:28 +02:00
// this file format doesn't provide any information whether a channel is TV/radio/data or analog/digital. It only contains the "medium" for antenna/cable/sat
var file = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles" ) + "\\Repair\\CM_TPM1013E_LA_CK.xml" ;
this . TestChannelsAddedToCorrectLists ( file , SignalSource . DvbC , 483 , 0 , 0 ) ;
2019-08-29 16:57:20 +02:00
}
#endregion
2021-08-31 22:13:28 +02:00
#region TestChannelMapFormatSatChannelsAddedToCorrectLists
2019-08-29 16:57:20 +02:00
[TestMethod]
2021-08-31 22:13:28 +02:00
public void TestChannelMapFormatSatChannelsAddedToCorrectLists ( )
2019-08-29 16:57:20 +02:00
{
2021-01-09 12:06:32 +01:00
var file = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles" ) + "\\ChannelMap_100\\ChannelList\\chanLst.bin" ;
2021-08-31 22:13:28 +02:00
this . TestChannelsAddedToCorrectLists ( file , SignalSource . DvbS , 502 , 350 , 152 ) ;
2019-08-29 16:57:20 +02:00
}
#endregion
2021-08-31 22:13:28 +02:00
#region TestChannelMapFormatCableChannelsAddedToCorrectLists
2019-08-29 16:57:20 +02:00
[TestMethod]
2021-08-31 22:13:28 +02:00
public void TestChannelMapFormatCableChannelsAddedToCorrectLists ( )
2019-08-29 16:57:20 +02:00
{
2021-08-31 22:13:28 +02:00
var file = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles" ) + "\\ChannelMap_100\\ChannelList\\chanLst.bin" ;
this . TestChannelsAddedToCorrectLists ( file , SignalSource . DvbC , 459 , 358 , 101 ) ;
2019-08-29 16:57:20 +02:00
}
#endregion
#region TestChannelsAddedToCorrectList
2021-01-09 12:06:32 +01:00
private void TestChannelsAddedToCorrectLists ( string filePath , SignalSource signalSource , int expectedTotal , int expectedTv , int expectedRadio )
2019-08-29 16:57:20 +02:00
{
2021-01-23 14:22:18 +01:00
var plugin = new PhilipsPlugin ( ) ;
2021-01-09 12:06:32 +01:00
var ser = plugin . CreateSerializer ( filePath ) ;
2019-08-29 16:57:20 +02:00
ser . Load ( ) ;
var root = ser . DataRoot ;
var list = root . GetChannelList ( signalSource ) ;
Assert . IsNotNull ( list ) ;
Assert . AreEqual ( expectedTotal , list . Channels . Count ) ;
Assert . AreEqual ( expectedTv , list . Channels . Count ( ch = > ( ch . SignalSource & SignalSource . Tv ) ! = 0 ) ) ;
Assert . AreEqual ( expectedRadio , list . Channels . Count ( ch = > ( ch . SignalSource & SignalSource . Radio ) ! = 0 ) ) ;
// no data channels found in any of the Philips channel lists available to me
}
#endregion
2019-11-08 02:31:44 +01:00
#region TestDeletingChannel
[TestMethod]
public void TestDeletingChannel ( )
{
2021-01-09 12:06:32 +01:00
var tempFile = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles" ) + "\\ChannelMap_100\\ChannelList\\chanLst.bin" ;
2021-01-23 14:22:18 +01:00
var plugin = new PhilipsPlugin ( ) ;
2019-11-08 02:31:44 +01:00
var ser = plugin . CreateSerializer ( tempFile ) ;
ser . Load ( ) ;
var data = ser . DataRoot ;
data . ValidateAfterLoad ( ) ;
data . ApplyCurrentProgramNumbers ( ) ;
// Pr# 42 = NTV HD
var dvbs = data . GetChannelList ( SignalSource . DvbS ) ;
var ntvHd = dvbs . Channels . FirstOrDefault ( ch = > ch . Name = = "NTV HD" ) ;
Assert . IsNotNull ( ntvHd ) ;
Assert . AreEqual ( 42 , ntvHd . OldProgramNr ) ;
Assert . AreEqual ( 42 , ntvHd . NewProgramNr ) ;
Assert . IsFalse ( ntvHd . IsDeleted ) ;
ntvHd . NewProgramNr = - 1 ;
2019-11-08 19:35:59 +01:00
data . AssignNumbersToUnsortedAndDeletedChannels ( UnsortedChannelMode . Delete ) ;
2019-11-08 02:31:44 +01:00
Assert . IsTrue ( ntvHd . IsDeleted ) ;
Assert . IsTrue ( ntvHd . NewProgramNr = = 0 ) ;
Assert . AreEqual ( 1 , dvbs . Channels . Count ( ch = > ch . NewProgramNr < = 0 ) ) ;
// save and reload
2022-11-29 22:00:16 +01:00
ser . Save ( ) ;
2019-11-08 02:31:44 +01:00
ser = plugin . CreateSerializer ( tempFile ) ;
ser . Load ( ) ;
data = ser . DataRoot ;
data . ValidateAfterLoad ( ) ;
data . ApplyCurrentProgramNumbers ( ) ;
// channel was deleted from database
dvbs = data . GetChannelList ( SignalSource . DvbS ) ;
ntvHd = dvbs . Channels . FirstOrDefault ( ch = > ch . Name = = "NTV HD" ) ;
Assert . IsNull ( ntvHd ) ;
}
#endregion
2021-03-14 22:13:22 +01:00
#region TestChannelAndFavListEditing_100
[TestMethod]
public void TestChannelAndFavListEditing_100 ( )
{
var tempFile = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles\\ChannelMap_100\\ChannelList" ) + "\\chanLst.bin" ;
RoundtripTest . TestChannelAndFavListEditing ( tempFile , new PhilipsPlugin ( ) ) ;
}
#endregion
#region TestChannelAndFavListEditing_Legacy
[TestMethod]
public void TestChannelAndFavListEditing_Legacy ( )
{
var tempFile = TestUtils . DeploymentItem ( "Test.Loader.Philips\\TestFiles\\Repair" ) + "\\CM_TPM1013E_LA_CK.xml" ;
RoundtripTest . TestChannelAndFavListEditing ( tempFile , new PhilipsPlugin ( ) ) ;
}
#endregion
2019-08-29 16:57:20 +02:00
}
}