Skip to content

Commit 65321cd

Browse files
authored
Merge pull request #27 from OpenMediaStation/postgres
Postgres
2 parents cc21db2 + bd9b56e commit 65321cd

141 files changed

Lines changed: 4504 additions & 1879 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,6 @@ __pycache__/
286286
*.btp.cs
287287
*.btm.cs
288288
*.odx.cs
289-
*.xsd.cs
289+
*.xsd.cs
290+
291+
.env

.run/docker-compose.yaml.run.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="docker-compose.yaml" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
3+
<deployment type="docker-compose.yml">
4+
<settings>
5+
<option name="envFilePath" value="$PROJECT_DIR$/.env" />
6+
<option name="commandLineOptions" value="--build" />
7+
<option name="services">
8+
<list>
9+
<option value="openmediaserver" />
10+
</list>
11+
</option>
12+
<option name="sourceFilePath" value="docker-compose.yaml" />
13+
</settings>
14+
</deployment>
15+
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="false" isSslEnabled="false" />
16+
<method v="2" />
17+
</configuration>
18+
</component>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Linq.Expressions;
2+
using System.Text.Json;
3+
using OpenMediaServer.Interfaces.Repositories;
4+
5+
namespace OpenMediaServer.Test.Mocks;
6+
7+
public class DataRepoMock : IDataRepository
8+
{
9+
public List<string?> WrittenObjects { get; set; } = new();
10+
11+
public Task<T?> GetObjectById<T>(Guid? id, Expression<Func<T, bool>>? additionalFilter = null)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
16+
public async Task WriteObject<T>(T item)
17+
{
18+
WrittenObjects.Add(JsonSerializer.Serialize(item, options: Globals.JsonOptions));
19+
}
20+
21+
public async Task WriteObjects<T>(IEnumerable<T>? items)
22+
{
23+
foreach (var item in items ?? [])
24+
{
25+
WrittenObjects.Add(JsonSerializer.Serialize(item, options: Globals.JsonOptions));
26+
}
27+
}
28+
29+
public async Task<IEnumerable<T>> ListObjects<T>(Expression<Func<T, bool>>? filter = null)
30+
{
31+
return [];
32+
}
33+
34+
public async Task DeleteObjectWithFilter<T>(Guid id, Expression<Func<T, bool>>? filter = null)
35+
{
36+
throw new NotImplementedException();
37+
}
38+
39+
public async Task DeleteObjects<T>(IEnumerable<T> items)
40+
{
41+
foreach (var item in items)
42+
{
43+
WrittenObjects.Remove(JsonSerializer.Serialize(item, options: Globals.JsonOptions));
44+
}
45+
}
46+
}

OpenMediaServer.Test/Mocks/FileSystemRepoMock.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Linq.Expressions;
2+
using OpenMediaServer.Interfaces.Services;
3+
using OpenMediaServer.Models.Inventory;
4+
5+
namespace OpenMediaServer.Test.Mocks;
6+
7+
using System;
8+
using System.Collections.Concurrent;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Linq.Expressions;
12+
using System.Threading.Tasks;
13+
14+
public class VersionServiceMock : IVersionService
15+
{
16+
private readonly ConcurrentDictionary<Guid, InventoryItemVersion> _store = new();
17+
18+
public Task<InventoryItemVersion?> Get(Guid? id)
19+
{
20+
if (id is null) return Task.FromResult<InventoryItemVersion?>(null);
21+
_store.TryGetValue(id.Value, out var item);
22+
return Task.FromResult(item);
23+
}
24+
25+
public Task UpdateOrInsert(InventoryItemVersion item)
26+
{
27+
if (item is null) throw new ArgumentNullException(nameof(item));
28+
29+
// Ensure the item has an Id
30+
if (item.Id == Guid.Empty)
31+
{
32+
item.Id = Guid.NewGuid();
33+
}
34+
35+
_store.AddOrUpdate(item.Id, item, (_, __) => item);
36+
return Task.CompletedTask;
37+
}
38+
39+
public Task<IEnumerable<InventoryItemVersion>?> List(Expression<Func<InventoryItemVersion, bool>>? filter = null)
40+
{
41+
IEnumerable<InventoryItemVersion> result = _store.Values;
42+
43+
if (filter != null)
44+
{
45+
result = result.AsQueryable().Where(filter);
46+
}
47+
48+
return Task.FromResult<IEnumerable<InventoryItemVersion>?>(result);
49+
}
50+
51+
public Task Delete(Guid id)
52+
{
53+
_store.TryRemove(id, out _);
54+
return Task.CompletedTask;
55+
}
56+
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -10,16 +10,16 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1414
<PackageReference Include="Moq" Version="4.20.72" />
15-
<PackageReference Include="NSubstitute" Version="5.1.0" />
16-
<PackageReference Include="Shouldly" Version="4.2.1" />
17-
<PackageReference Include="xunit" Version="2.4.2" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
15+
<PackageReference Include="NSubstitute" Version="5.3.0" />
16+
<PackageReference Include="Shouldly" Version="4.3.0" />
17+
<PackageReference Include="xunit" Version="2.9.3" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Include="coverlet.collector" Version="6.0.0">
22+
<PackageReference Include="coverlet.collector" Version="6.0.4">
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>
@@ -35,8 +35,8 @@
3535
</Content>
3636
</ItemGroup>
3737

38-
<ItemGroup>
39-
<None Remove="Assets/.gitkeep" />
38+
<ItemGroup>
39+
<None Remove="Assets/.gitkeep" />
4040
</ItemGroup>
4141

4242
</Project>

OpenMediaServer.Test/Services/DiscoveryAudiobookServiceShould.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using Moq;
55
using NSubstitute;
66
using OpenMediaServer.Interfaces.Services;
7+
using OpenMediaServer.Interfaces.Services.Metadata;
78
using OpenMediaServer.Models;
89
using OpenMediaServer.Services;
910
using OpenMediaServer.Services.Discovery;
11+
using OpenMediaServer.Services.Metadata;
1012
using OpenMediaServer.Test.Mocks;
1113
using Shouldly;
1214

@@ -15,20 +17,26 @@ namespace OpenMediaServer.Test.Services;
1517
public class DiscoveryAudiobookServiceShould
1618
{
1719
private readonly ILogger<DiscoveryAudiobookService> _logger;
18-
private readonly FileSystemRepoMock _storageRepository;
20+
private readonly DataRepoMock _storageRepository;
1921
private readonly IFileInfoService _fileInfoService;
2022
private readonly DiscoveryAudiobookService _inventoryBookService;
2123
private readonly IInventoryService _inventoryService;
24+
private readonly IVersionService _versionService;
25+
private readonly IPartService _partService;
26+
private readonly IAudioBookMetadataService _audioBookMetadataService;
2227

2328
public DiscoveryAudiobookServiceShould()
2429
{
2530
Setup.Configure();
2631

2732
_logger = Substitute.For<ILogger<DiscoveryAudiobookService>>();
28-
_storageRepository = new FileSystemRepoMock();
33+
_storageRepository = new DataRepoMock();
2934
_fileInfoService = Substitute.For<IFileInfoService>();
35+
_partService = Substitute.For<IPartService>();
36+
_audioBookMetadataService = Substitute.For<IAudioBookMetadataService>();
37+
_versionService = new VersionServiceMock();
3038
_inventoryService = new InventoryService(Substitute.For<ILogger<InventoryService>>(), _storageRepository, Mock.Of<IImageService>());
31-
_inventoryBookService = new DiscoveryAudiobookService(_logger, _fileInfoService, _inventoryService, Substitute.For<IMetadataService>());
39+
_inventoryBookService = new DiscoveryAudiobookService(_logger, _fileInfoService, _inventoryService, Substitute.For<IMetadataService>(), _versionService, _partService, _audioBookMetadataService);
3240
}
3341

3442
[Theory]
@@ -45,18 +53,18 @@ public async Task Create_FirstItemBook(string path, string title, string? folder
4553
// Act
4654
await _inventoryBookService.CreateAudiobook(path);
4755
var resultJson = _storageRepository.WrittenObjects.First();
48-
var result = JsonSerializer.Deserialize<IEnumerable<Audiobook>>(resultJson);
56+
var resultItem = JsonSerializer.Deserialize<InventoryItem>(resultJson, Globals.JsonOptions);
57+
var versions = await _versionService.List();
4958

5059
// Assert
51-
var resultItem = result.First();
5260
resultItem.Id.ShouldNotBe(Guid.Empty);
5361
resultItem.Title.ShouldBe(title);
5462
resultItem.Category.ShouldBe("Audiobook");
5563
resultItem.MetadataId.ShouldNotBe(Guid.Empty);
56-
resultItem.Versions.ShouldNotBeNull();
57-
resultItem.Versions.Count().ShouldBe(1);
58-
resultItem.Versions.First().Id.ShouldNotBe(Guid.Empty);
59-
resultItem.Versions.First().Path.ShouldBe(path);
64+
versions.ShouldNotBeNull();
65+
versions.Count().ShouldBe(1);
66+
versions.First().Id.ShouldNotBe(Guid.Empty);
67+
versions.First().Path.ShouldBe(path);
6068
resultItem.FolderPath.ShouldBe(folderPath);
6169
}
6270
}

OpenMediaServer.Test/Services/DiscoveryBookServiceShould.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using Moq;
44
using NSubstitute;
55
using OpenMediaServer.Interfaces.Services;
6+
using OpenMediaServer.Interfaces.Services.Metadata;
67
using OpenMediaServer.Models;
78
using OpenMediaServer.Services;
9+
using OpenMediaServer.Services.Discovery;
810
using OpenMediaServer.Test.Mocks;
911
using Shouldly;
1012

@@ -13,20 +15,24 @@ namespace OpenMediaServer.Test.Services;
1315
public class DiscoveryBookServiceShould
1416
{
1517
private readonly ILogger<DiscoveryBookService> _logger;
16-
private readonly FileSystemRepoMock _storageRepository;
18+
private readonly DataRepoMock _storageRepository;
1719
private readonly IFileInfoService _fileInfoService;
1820
private readonly IDiscoveryBookService _inventoryBookService;
1921
private readonly IInventoryService _inventoryService;
20-
22+
private readonly IVersionService _versionService;
23+
private readonly IBookMetadataService _bookMetadataService;
24+
2125
public DiscoveryBookServiceShould()
2226
{
2327
Setup.Configure();
2428

2529
_logger = Substitute.For<ILogger<DiscoveryBookService>>();
26-
_storageRepository = new FileSystemRepoMock();
30+
_storageRepository = new DataRepoMock();
2731
_fileInfoService = Substitute.For<IFileInfoService>();
32+
_bookMetadataService = Substitute.For<IBookMetadataService>();
33+
_versionService = new VersionServiceMock();
2834
_inventoryService = new InventoryService(Substitute.For<ILogger<InventoryService>>(), _storageRepository, Mock.Of<IImageService>());
29-
_inventoryBookService = new DiscoveryBookService(_logger, _fileInfoService, _inventoryService, Substitute.For<IMetadataService>());
35+
_inventoryBookService = new DiscoveryBookService(_logger, _fileInfoService, _inventoryService, Substitute.For<IMetadataService>(), _versionService, _bookMetadataService);
3036
}
3137

3238
[Theory]
@@ -47,18 +53,18 @@ public async Task Create_FirstItemBook(string path, string title, string? folder
4753
// Act
4854
await _inventoryBookService.CreateBook(path);
4955
var resultJson = _storageRepository.WrittenObjects.First();
50-
var result = JsonSerializer.Deserialize<IEnumerable<Book>>(resultJson);
56+
var resultItem = JsonSerializer.Deserialize<InventoryItem>(resultJson, Globals.JsonOptions);
57+
var versions = await _versionService.List();
5158

5259
// Assert
53-
var resultItem = result.First();
5460
resultItem.Id.ShouldNotBe(Guid.Empty);
5561
resultItem.Title.ShouldBe(title);
5662
resultItem.Category.ShouldBe("Book");
5763
resultItem.MetadataId.ShouldNotBe(Guid.Empty);
58-
resultItem.Versions.ShouldNotBeNull();
59-
resultItem.Versions.Count().ShouldBe(1);
60-
resultItem.Versions.First().Id.ShouldNotBe(Guid.Empty);
61-
resultItem.Versions.First().Path.ShouldBe(path);
64+
versions.ShouldNotBeNull();
65+
versions.Count().ShouldBe(1);
66+
versions.First().Id.ShouldNotBe(Guid.Empty);
67+
versions.First().Path.ShouldBe(path);
6268
resultItem.FolderPath.ShouldBe(folderPath);
6369
}
6470
}

0 commit comments

Comments
 (0)