Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
#27 モックの名前、位置の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Feb 22, 2024
1 parent 2db6811 commit cee38b9
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface ISoundGenerationSelectorService
{
Expand All @@ -9,5 +11,3 @@ public interface ISoundGenerationSelectorService

public ValueTask InitializeAsync(CancellationToken cancellationToken);
}

public record SoundModel(string name, string[] styles);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace KoeBook.Core.Contracts.Services;

internal interface ISoundGeneration
public interface ISoundGenerationService
{
/// <summary>
/// 1文の音声を生成します
Expand Down
2 changes: 1 addition & 1 deletion KoeBook.Core/KoeBook.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>KoeBook.Core</RootNamespace>
Expand Down
5 changes: 5 additions & 0 deletions KoeBook.Core/Models/SoundModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace KoeBook.Core.Models;

public record SoundModel(
string name,
IReadOnlyList<string> styles);
22 changes: 22 additions & 0 deletions KoeBook.Core/Services/Mocks/SoundGenerationSelectorServiceMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Core.Services.Mocks;

internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
{
public IReadOnlyList<SoundModel> Models { get; private set; } = [];

public async ValueTask InitializeAsync(CancellationToken cancellationToken)
{
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
Models = [
new SoundModel("青年1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("青年2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("女性1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("女性2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("ナレーション (男性)", ["narration"]),
new SoundModel("ナレーション (女性)", ["narration"]),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using KoeBook.Core.Models;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Contracts.Services.Mocks;
namespace KoeBook.Core.Services.Mocks;

internal class SoundGenerationMock
public class SoundGenerationServiceMock : ISoundGenerationService
{
public async ValueTask<byte[]> GenerateLineSoundAsync(ScriptLine scriptLine, BookOptions bookOptions, CancellationToken cancellationToken)
{
await Task.Delay(1000, cancellationToken);
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
// 適当なバイト列を返す
var random = new Random();
var buffer = new byte[44100 * 2];
Expand Down
11 changes: 9 additions & 2 deletions KoeBook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using KoeBook.Contracts.Services;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Services;
using KoeBook.Helpers;
using KoeBook.Core.Services.Mocks;
using KoeBook.Models;
using KoeBook.Notifications;
using KoeBook.Services;
using KoeBook.ViewModels;
using KoeBook.Views;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -86,6 +86,13 @@ public App()

// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));

// Core Services Mock
var mockOptions = context.Configuration.GetSection(nameof(MockOptions)).Get<MockOptions>();
if (mockOptions.ISoundGenerationSelectorService.HasValue && mockOptions.ISoundGenerationSelectorService.Value)
services.AddSingleton<ISoundGenerationSelectorService, SoundGenerationSelectorServiceMock>();
if(mockOptions.ISoundGenerationService.HasValue && mockOptions.ISoundGenerationService.Value)
services.AddSingleton<ISoundGenerationService, SoundGenerationServiceMock>();
})
.Build();

Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions KoeBook/KoeBook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\CoreMocks\" />
</ItemGroup>

<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
Expand Down
8 changes: 8 additions & 0 deletions KoeBook/Models/MockOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace KoeBook.Models;

internal class MockOptions
{
public bool? ISoundGenerationSelectorService { get; set; }

public bool? ISoundGenerationService { get; set; }
}
19 changes: 19 additions & 0 deletions KoeBook/Services/CoreMocks/SoundGenerationSelectorServiceMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Core.Services.Mocks;

internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
{
public IReadOnlyList<SoundModel> Models { get; private set; } = [];

public async ValueTask InitializeAsync(CancellationToken cancellationToken)
{
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
Models = [
new SoundModel("青年1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("青年2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
new SoundModel("王", ["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
];
}
}
10 changes: 7 additions & 3 deletions KoeBook/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
{
"LocalSettingsOptions": {
"ApplicationDataFolder": "KoeBook/ApplicationData",
"LocalSettingsFile": "LocalSettings.json"
"ApplicationDataFolder": "KoeBook/ApplicationData",
"LocalSettingsFile": "LocalSettings.json"
},
"MockOptions": {
"ISoundGenerationSelectorService": false,
"ISoundGenerationService": false
}
}

0 comments on commit cee38b9

Please sign in to comment.