Skip to content

Commit 1559c41

Browse files
authored
Merge pull request #77 from hmlendea/refactor
Refactored the code to newer standards
2 parents 1c0e203 + 457c946 commit 1559c41

21 files changed

+349
-523
lines changed

IptvPlaylistAggregator.UnitTests/Service/ChannelMatcherTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
using IptvPlaylistAggregator.Service;
66
using IptvPlaylistAggregator.Service.Models;
77

8-
namespace IptvPlaylistAggregator.UnitTests.Service.Models
8+
namespace IptvPlaylistAggregator.UnitTests.Service
99
{
1010
public sealed class ChannelMatcherTests
1111
{
12-
Mock<ICacheManager> cacheMock;
12+
private Mock<ICacheManager> cacheMock;
1313

14-
IChannelMatcher channelMatcher;
14+
private IChannelMatcher channelMatcher;
1515

1616
[SetUp]
1717
public void SetUp()
@@ -250,7 +250,7 @@ public void NormaliseName_WithoutCountry_ReturnsExpectedValue(string inputValue,
250250
private ChannelName GetChannelName(string definedName, string alias)
251251
=> GetChannelName(definedName, country: null, alias);
252252

253-
private ChannelName GetChannelName(string definedName, string country, string alias)
253+
private static ChannelName GetChannelName(string definedName, string country, string alias)
254254
{
255255
if (alias is null)
256256
{
Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
using NUnit.Framework;
2-
31
using Moq;
2+
using NuciLog.Core;
3+
using NUnit.Framework;
44

55
using IptvPlaylistAggregator.Configuration;
66
using IptvPlaylistAggregator.Service;
77

8-
using NuciLog.Core;
9-
10-
namespace IptvPlaylistAggregator.UnitTests.Service.Models
8+
namespace IptvPlaylistAggregator.UnitTests.Service
119
{
1210
public sealed class MediaSourceCheckerTests
1311
{
14-
Mock<IFileDownloader> fileDownloaderMock;
15-
Mock<IPlaylistFileBuilder> playlistFileBuilderMock;
16-
Mock<ICacheManager> cacheMock;
17-
Mock<ILogger> loggerMock;
18-
ApplicationSettings applicationSettings;
12+
private Mock<IFileDownloader> fileDownloaderMock;
13+
private Mock<IPlaylistFileBuilder> playlistFileBuilderMock;
14+
private Mock<ICacheManager> cacheMock;
15+
private Mock<ILogger> loggerMock;
16+
private ApplicationSettings applicationSettings;
1917

20-
IMediaSourceChecker mediaSourceChecker;
18+
private MediaSourceChecker mediaSourceChecker;
2119

2220
[SetUp]
2321
public void SetUp()
2422
{
25-
fileDownloaderMock = new Mock<IFileDownloader>();
26-
playlistFileBuilderMock = new Mock<IPlaylistFileBuilder>();
27-
cacheMock = new Mock<ICacheManager>();
28-
loggerMock = new Mock<ILogger>();
29-
applicationSettings = new ApplicationSettings();
23+
fileDownloaderMock = new();
24+
playlistFileBuilderMock = new();
25+
cacheMock = new();
26+
loggerMock = new();
27+
applicationSettings = new();
3028

31-
mediaSourceChecker = new MediaSourceChecker(
29+
mediaSourceChecker = new(
3230
fileDownloaderMock.Object,
3331
playlistFileBuilderMock.Object,
3432
cacheMock.Object,
@@ -39,42 +37,31 @@ public void SetUp()
3937
[TestCase("https://www.youtube.com/watch?v=fxFIgBld95E")]
4038
[Test]
4139
public void GivenTheSourceIsYouTubeVideo_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
42-
{
43-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
44-
}
40+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
4541

4642
[TestCase("https://dotto.edvr.ro/dottotv_1603019528.mp4")]
4743
[TestCase("https://iptvcat.com/assets/videos/lazycat-iptvcat.com.mp4?fluxustv.m3u8")]
4844
[TestCase("https://iptvcat.com/assets/videos/lazycat-iptvcat.com.mp4")]
4945
[Test]
5046
public void GivenTheSourceIsShortenedUrl_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
51-
{
52-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
53-
}
47+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
5448

5549
[TestCase("https://tinyurl.com/y9k7rbje")]
5650
[Test]
5751
public void GivenTheSourceIsAnMP4File_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
58-
{
59-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
60-
}
52+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
6153

6254
[TestCase("mms://86.34.169.52:8080/")]
6355
[TestCase("mms://musceltvlive.muscel.ro:8080")]
6456
[Test]
6557
public void GivenTheSourceIsUsingTeMmsProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
66-
{
67-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
68-
}
69-
58+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
7059

7160
[TestCase("mmsh://82.137.6.58:1234/")]
7261
[TestCase("mmsh://musceltvlive.muscel.ro:8080")]
7362
[Test]
7463
public void GivenTheSourceIsUsingTeMmshProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
75-
{
76-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
77-
}
64+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
7865

7966
[TestCase("rtmp://212.0.209.209:1935/live/_definst_mp4:Moldova")]
8067
[TestCase("rtmp://81.18.66.155/live/banat-tv")]
@@ -93,9 +80,7 @@ public void GivenTheSourceIsUsingTeMmshProtocol_WhenCheckingThatItIsPlayable_The
9380
[TestCase("rtmp://v1.arya.ro:1935/live/ptv1.flv")]
9481
[Test]
9582
public void GivenTheSourceIsUsingTeRtmpProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
96-
{
97-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
98-
}
83+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
9984

10085
[TestCase("rtsp://195.64.178.23/somax")]
10186
[TestCase("rtsp://195.64.178.23/telem")]
@@ -104,17 +89,9 @@ public void GivenTheSourceIsUsingTeRtmpProtocol_WhenCheckingThatItIsPlayable_The
10489
[TestCase("rtsp://live.trm.md:1935/live/M1Mlive")]
10590
[Test]
10691
public void GivenTheSourceIsUsingTeRtspProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl)
107-
{
108-
AssertThatSourceUrlIsNotPlayable(sourceUrl);
109-
}
92+
=> AssertThatSourceUrlIsNotPlayable(sourceUrl);
11093

111-
void AssertThatSourceUrlIsNotPlayable(string sourceUrl)
112-
{
113-
// Act
114-
bool sourceIsPlayale = mediaSourceChecker.IsSourcePlayableAsync(sourceUrl).Result;
115-
116-
// Assert
117-
Assert.That(sourceIsPlayale, Is.False);
118-
}
94+
private void AssertThatSourceUrlIsNotPlayable(string sourceUrl)
95+
=> Assert.That(!mediaSourceChecker.IsSourcePlayableAsync(sourceUrl).Result);
11996
}
12097
}

IptvPlaylistAggregator/DataAccess/DataObjects/ChannelDefinitionEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace IptvPlaylistAggregator.DataAccess.DataObjects
66
{
77
public sealed class ChannelDefinitionEntity : EntityBase
88
{
9-
const string UnknownGroupPlaceholder = "unknown";
9+
private const string UnknownGroupPlaceholder = "unknown";
1010

1111
public bool IsEnabled { get; set; }
1212

IptvPlaylistAggregator/DataAccess/DataObjects/GroupEntity.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ public class GroupEntity : EntityBase
99
public string Name { get; set; }
1010

1111
public int Priority { get; set; }
12-
13-
public GroupEntity()
14-
{
15-
Priority = int.MaxValue;
16-
}
12+
13+
public GroupEntity() => Priority = int.MaxValue;
1714
}
1815
}

IptvPlaylistAggregator/Logging/MyLogInfoKey.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ namespace IptvPlaylistAggregator.Logging
44
{
55
public sealed class MyLogInfoKey : LogInfoKey
66
{
7-
MyLogInfoKey(string name)
8-
: base(name)
9-
{
10-
11-
}
7+
private MyLogInfoKey(string name) : base(name) { }
128

139
public static LogInfoKey Channel => new MyLogInfoKey(nameof(Channel));
1410

IptvPlaylistAggregator/Logging/MyOperation.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ namespace IptvPlaylistAggregator.Logging
44
{
55
public sealed class MyOperation : Operation
66
{
7-
MyOperation(string name)
8-
: base(name)
9-
{
10-
11-
}
7+
private MyOperation(string name) : base(name) { }
128

139
public static Operation PlaylistFetching => new MyOperation(nameof(PlaylistFetching));
1410

IptvPlaylistAggregator/Program.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ namespace IptvPlaylistAggregator
1818
{
1919
public class Program
2020
{
21-
static ApplicationSettings applicationSettings;
22-
static CacheSettings cacheSettings;
23-
static DataStoreSettings dataStoreSettings;
24-
static NuciLoggerSettings nuciLoggerSettings;
21+
private static ApplicationSettings applicationSettings;
22+
private static CacheSettings cacheSettings;
23+
private static DataStoreSettings dataStoreSettings;
24+
private static NuciLoggerSettings nuciLoggerSettings;
2525

26-
static ILogger logger;
27-
static ICacheManager cacheManager;
26+
private static ILogger logger;
27+
private static ICacheManager cacheManager;
2828

2929
public static void Main(string[] args)
3030
{
@@ -58,7 +58,7 @@ public static void Main(string[] args)
5858
.AddSingleton<ILogger, NuciLogger>()
5959
.BuildServiceProvider();
6060

61-
61+
6262
logger = serviceProvider.GetService<ILogger>();
6363
cacheManager = serviceProvider.GetService<ICacheManager>();
6464

@@ -84,21 +84,17 @@ public static void Main(string[] args)
8484

8585
logger.Info(Operation.ShutDown, OperationStatus.Success);
8686
}
87-
88-
static IConfiguration LoadConfiguration()
89-
{
90-
return new ConfigurationBuilder()
87+
88+
private static IConfiguration LoadConfiguration()
89+
=> new ConfigurationBuilder()
9190
.AddJsonFile("appsettings.json", true, true)
9291
.Build();
93-
}
9492

95-
static void LogInnerExceptions(AggregateException exception)
93+
private static void LogInnerExceptions(AggregateException exception)
9694
{
9795
foreach (Exception innerException in exception.InnerExceptions)
9896
{
99-
AggregateException innerAggregateException = innerException as AggregateException;
100-
101-
if (innerAggregateException is null)
97+
if (innerException is not AggregateException)
10298
{
10399
logger.Fatal(Operation.Unknown, OperationStatus.Failure, innerException);
104100
}
@@ -109,7 +105,7 @@ static void LogInnerExceptions(AggregateException exception)
109105
}
110106
}
111107

112-
static void SaveCacheToDisk()
108+
private static void SaveCacheToDisk()
113109
{
114110
logger.Info(MyOperation.CacheSaving, OperationStatus.Started);
115111
cacheManager.SaveCacheToDisk();

0 commit comments

Comments
 (0)