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

Commit

Permalink
#5 モックを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Feb 22, 2024
1 parent f6b55e6 commit 29f213f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 8 deletions.
10 changes: 10 additions & 0 deletions KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace KoeBook.Core.Contracts.Services;

public interface ISoundGenerationSelectorService
{
public SoundModel[] Models { get; }

public ValueTask InitializeAsync(CancellationToken cancellationToken);
}

public record SoundModel(string name, string[] styles);
32 changes: 32 additions & 0 deletions KoeBook.Core/Helpers/IDisplayStateChangeEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Core.Helpers;

public static class IDisplayStateChangeEx
{
public static DisplayStateChanging ResetProgress(
this IDisplayStateChangeService service,
BookProperties bookProperties,
GenerationState state,
int maximum)
{
service.UpdateProgress(bookProperties, 0, maximum);
service.UpdateState(bookProperties, state);
return new(service, bookProperties, maximum);
}

public class DisplayStateChanging(IDisplayStateChangeService displayStateChangeService, BookProperties bookProperties, int maximum)
{
private readonly IDisplayStateChangeService _displayStateChangeService = displayStateChangeService;

private readonly BookProperties _bookProperties = bookProperties;

private readonly int _maximum = maximum;

public void UpdateProgress(int progress)
{
_displayStateChangeService.UpdateProgress(_bookProperties, progress, _maximum);
}
}
}
10 changes: 9 additions & 1 deletion KoeBook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
using KoeBook.Models;
using KoeBook.Notifications;
using KoeBook.Services;
using KoeBook.Services.CoreMocks;
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 +87,13 @@ public App()

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

// Core Services Mock
var mockOptions = context.Configuration.GetValue<MockOptions>(nameof(MockOptions));
if (mockOptions.IAnalyzerService.HasValue && mockOptions.IAnalyzerService.Value)
services.AddSingleton<IAnalyzerService, AnalyzerServiceMock>();
if (mockOptions.IEpubGenerateService.HasValue && mockOptions.IEpubGenerateService.Value)
services.AddSingleton<IEpubGenerateService, EpubGenerateServiceMock>();
})
.Build();

Expand Down
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? IAnalyzerService { get; set; }

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

namespace KoeBook.Services.CoreMocks;

public class AnalyzerServiceMock(IDisplayStateChangeService stateService) : IAnalyzerService
{
private readonly IDisplayStateChangeService _stateService = stateService;

public async ValueTask<BookScripts> AnalyzeAsync(BookProperties bookProperties, CancellationToken cancellationToken)
{
var stateChanging = _stateService.ResetProgress(bookProperties, GenerationState.Downloading, 300);
await Task.Delay(5000, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(30);
await Task.Delay(500, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(100);
await Task.Delay(500, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(300);

stateChanging = _stateService.ResetProgress(bookProperties, GenerationState.Downloading, 400);
await Task.Delay(500, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(240);
await Task.Delay(500, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(400);

var characterMapping = new Dictionary<string, string>()
{
["Hoge"] = "男性1",
["Fuga"] = "女性1",
["Narration"] = "ナレーション (男性)",
};
return new(bookProperties, new(characterMapping))
{
ScriptLines = [
new("a", "読み上げテキスト1", "Hoge", "Angry"),
new("b", "読み上げテキスト2", "Fuga", "Sad"),
new("c", "読み上げテキスト3", "Narration", "Narration"),
],
};
}
}
33 changes: 33 additions & 0 deletions KoeBook/Services/CoreMocks/EpubGenerateServiceMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Helpers;
using KoeBook.Core.Models;

namespace KoeBook.Services.CoreMocks;

public class EpubGenerateServiceMock(IDisplayStateChangeService displayStateChangeService) : IEpubGenerateService
{
private readonly IDisplayStateChangeService _displayStateChangeService = displayStateChangeService;

public async ValueTask<string> GenerateEpubAsync(BookScripts bookScripts, string tempDirectory, CancellationToken cancellationToken)
{
var stateChanging = _displayStateChangeService.ResetProgress(bookScripts.BookProperties, GenerationState.SoundProducing, 4000);
await Task.Delay(200, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(200);
await Task.Delay(2000, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(2000);
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(3000);
await Task.Delay(200, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(4000);

stateChanging = _displayStateChangeService.ResetProgress(bookScripts.BookProperties, GenerationState.Publishing, 200);
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(50);
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(120);
var resultPath = Path.Combine(tempDirectory, "mock.epub");
await File.WriteAllTextAsync(resultPath, "sample", cancellationToken).ConfigureAwait(false);
stateChanging.UpdateProgress(200);
return resultPath;
}
}
16 changes: 16 additions & 0 deletions KoeBook/Views/EditDetailsTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@
Text="{x:Bind ViewModel.Task.ProgressText, Mode=OneWay}" />
</Grid>
</StackPanel>

<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="{StaticResource MediumTopMargin}"
Text="モデル設定"/>

<StackPanel
Background="{ThemeResource CardBackgroundFillColorDefault}"
BorderBrush="{ThemeResource CardStrokeColorDefault}"
BorderThickness="1"
Padding="12,8,12,8"
CornerRadius="12"
Margin="{StaticResource SmallTopMargin}">
<TextBlock
Text="キャラクターごとにどのモデルを使用するか設定します。"/>
</StackPanel>
</StackPanel>
</ScrollView>
</Grid>
Expand Down
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": {
"IAnalyzerService": true,
"IEpubGenerateService": true
}
}

0 comments on commit 29f213f

Please sign in to comment.