Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #553 from amay077/feature/issue-539
Browse files Browse the repository at this point in the history
[Android/iOS]アプリの通信処理の Mock 化
  • Loading branch information
runceel committed Jun 22, 2020
2 parents fe48c02 + 2410020 commit 6835f25
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 17 deletions.
28 changes: 28 additions & 0 deletions Covid19Radar.sln
Expand Up @@ -23,6 +23,9 @@ Global
AppStore|Any CPU = AppStore|Any CPU
AppStore|iPhone = AppStore|iPhone
AppStore|iPhoneSimulator = AppStore|iPhoneSimulator
Debug_Mock|Any CPU = Debug_Mock|Any CPU
Debug_Mock|iPhone = Debug_Mock|iPhone
Debug_Mock|iPhoneSimulator = Debug_Mock|iPhoneSimulator
Debug|Any CPU = Debug|Any CPU
Debug|iPhone = Debug|iPhone
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Expand All @@ -43,6 +46,12 @@ Global
{554EE1AB-B447-480C-90E5-C4F040891DE6}.AppStore|iPhone.Build.0 = Debug|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|Any CPU.ActiveCfg = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|Any CPU.Build.0 = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|iPhone.ActiveCfg = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|iPhone.Build.0 = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|iPhoneSimulator.ActiveCfg = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug_Mock|iPhoneSimulator.Build.0 = Debug_Mock|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{554EE1AB-B447-480C-90E5-C4F040891DE6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
Expand All @@ -69,6 +78,15 @@ Global
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.AppStore|iPhoneSimulator.Deploy.0 = Release|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|Any CPU.ActiveCfg = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|Any CPU.Build.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|Any CPU.Deploy.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhone.ActiveCfg = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhone.Build.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhone.Deploy.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhoneSimulator.ActiveCfg = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhoneSimulator.Build.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug_Mock|iPhoneSimulator.Deploy.0 = Debug_Mock|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92B1EC8F-ECF4-403A-B6F4-5EC80F43A69A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
Expand Down Expand Up @@ -103,6 +121,11 @@ Global
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.AppStore|iPhone.Deploy.0 = AppStore|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug_Mock|Any CPU.ActiveCfg = Debug_Mock|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug_Mock|iPhone.ActiveCfg = Debug_Mock|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug_Mock|iPhone.Build.0 = Debug_Mock|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug_Mock|iPhoneSimulator.ActiveCfg = Debug_Mock|iPhoneSimulator
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug_Mock|iPhoneSimulator.Build.0 = Debug_Mock|iPhoneSimulator
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug|Any CPU.ActiveCfg = Debug|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug|Any CPU.Build.0 = Debug|iPhone
{3104A081-8DF8-4EDB-A40A-38DE78AA63AC}.Debug|Any CPU.Deploy.0 = Debug|iPhone
Expand All @@ -127,6 +150,11 @@ Global
{4223EE63-A661-4465-BBB0-08DD80DB2256}.AppStore|iPhone.Build.0 = Release|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug_Mock|Any CPU.ActiveCfg = Debug_Mock|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug_Mock|iPhone.ActiveCfg = Debug_Mock|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug_Mock|iPhone.Build.0 = Debug_Mock|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug_Mock|iPhoneSimulator.ActiveCfg = Debug_Mock|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug_Mock|iPhoneSimulator.Build.0 = Debug_Mock|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{4223EE63-A661-4465-BBB0-08DD80DB2256}.Debug|iPhone.Build.0 = Debug|Any CPU
Expand Down
17 changes: 17 additions & 0 deletions Covid19Radar/Covid19Radar.Android/Covid19Radar.Android.csproj
Expand Up @@ -91,6 +91,23 @@
<AndroidHttpClientHandlerType>
</AndroidHttpClientHandlerType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Mock|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug_Mock\</OutputPath>
<DefineConstants>DEBUG;USE_MOCK</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AndroidUseSharedRuntime>true</AndroidUseSharedRuntime>
<EmbedAssembliesIntoApk>false</EmbedAssembliesIntoApk>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<MandroidI18n>CJK</MandroidI18n>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.Export" />
Expand Down
38 changes: 32 additions & 6 deletions Covid19Radar/Covid19Radar.iOS/Covid19Radar.iOS.csproj
Expand Up @@ -66,8 +66,6 @@
<IOSDebugOverWiFi>true</IOSDebugOverWiFi>
<CodesignProvision>Covid19radar</CodesignProvision>
<MtouchExtraArgs>--optimize=experimental-xforms-product-type --weak-framework=ExposureNotification</MtouchExtraArgs>
<MtouchSdkVersion>
</MtouchSdkVersion>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchI18n>cjk</MtouchI18n>
Expand All @@ -84,8 +82,7 @@
<MtouchInterpreter>-all</MtouchInterpreter>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DefineConstants>
</DefineConstants>
<DefineConstants>DEBUG;__IOS__;__MOBILE__;__UNIFIED__;</DefineConstants>
<DefineConstants>DEBUG;__IOS__;__MOBILE__;__UNIFIED__;</DefineConstants>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
Expand Down Expand Up @@ -125,8 +122,6 @@
<MtouchI18n>cjk</MtouchI18n>
<LangVersion>latest</LangVersion>
<MtouchExtraArgs>--optimize=experimental-xforms-product-type --weak-framework=ExposureNotification</MtouchExtraArgs>
<MtouchSdkVersion>
</MtouchSdkVersion>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<MtouchNoSymbolStrip>
Expand Down Expand Up @@ -173,6 +168,37 @@
<AppExtensionDebugBundleId />
<LaunchForBackgroundFetch>true</LaunchForBackgroundFetch>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Mock|iPhoneSimulator'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\iPhoneSimulator\Debug_Mock\</OutputPath>
<DefineConstants>DEBUG;__IOS__;__MOBILE__;__UNIFIED__;ENABLE_TEST_CLOUD;USE_MOCK;</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodesignKey>iPhone Developer</CodesignKey>
<DeviceSpecificBuild>true</DeviceSpecificBuild>
<MtouchDebug>true</MtouchDebug>
<MtouchFastDev>true</MtouchFastDev>
<MtouchExtraArgs>--optimize=experimental-xforms-product-type --weak-framework=ExposureNotification --weak-framework=ExposureNotification</MtouchExtraArgs>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<MtouchArch>x86_64</MtouchArch>
<OptimizePNGs>false</OptimizePNGs>
<MtouchLink>SdkOnly</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Mock|iPhone'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\iPhone\Debug_Mock\</OutputPath>
<DefineConstants>__IOS__;__MOBILE__;__UNIFIED__;DEBUG;USE_MOCK;</DefineConstants>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<MtouchArch>ARM64</MtouchArch>
</PropertyGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
Expand Down
12 changes: 8 additions & 4 deletions Covid19Radar/Covid19Radar/App.xaml.cs
@@ -1,4 +1,4 @@
using System;
using System;
using Prism;
using Prism.DryIoc;
using Prism.Ioc;
Expand Down Expand Up @@ -49,10 +49,10 @@ protected override async void OnInitialized()
{
InitializeComponent();

#if DEBUG
#if USE_MOCK
// For debug mode, set the mock api provider to interact
// with some fake data
//Xamarin.ExposureNotifications.ExposureNotification.OverrideNativeImplementation(new Services.TestNativeImplementation());
Xamarin.ExposureNotifications.ExposureNotification.OverrideNativeImplementation(new Services.TestNativeImplementation());
#endif
Xamarin.ExposureNotifications.ExposureNotification.Init();

Expand Down Expand Up @@ -142,7 +142,11 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
// Services
containerRegistry.RegisterSingleton<UserDataService>();
containerRegistry.RegisterSingleton<ExposureNotificationService>();
containerRegistry.RegisterSingleton<HttpDataService>();
#if USE_MOCK
containerRegistry.RegisterSingleton<IHttpDataService, HttpDataServiceMock>();
#else
containerRegistry.RegisterSingleton<IHttpDataService, HttpDataService>();
#endif
}

protected override void OnStart()
Expand Down
5 changes: 5 additions & 0 deletions Covid19Radar/Covid19Radar/Covid19Radar.csproj
Expand Up @@ -5,6 +5,8 @@
<MultilingualFallbackLanguage>en-US</MultilingualFallbackLanguage>
<TranslationReport Condition="'$(Configuration)' == 'Release'">true</TranslationReport>
<SuppressPseudoWarning Condition="'$(Configuration)' == 'Debug'">true</SuppressPseudoWarning>
<SuppressPseudoWarning Condition="'$(Configuration)'=='Debug_Mock'">true</SuppressPseudoWarning>
<Configurations>Debug;Release;Debug_Mock</Configurations>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
Expand All @@ -20,6 +22,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Mock|AnyCPU'">
<DefineConstants>TRACE;DEBUG;USE_MOCK</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Multilingual App Toolkit\Microsoft.Multilingual.ResxResources.targets" Label="MultilingualAppToolkit" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\Multilingual App Toolkit\v$(MultilingualAppToolkitVersion)\Microsoft.Multilingual.ResxResources.targets')" />
<Target Name="MATPrerequisite" BeforeTargets="PrepareForBuild" Condition="!Exists('$(MSBuildExtensionsPath)\Microsoft\Multilingual App Toolkit\Microsoft.Multilingual.ResxResources.targets')" Label="MultilingualAppToolkit">
<Warning Text="$(MSBuildProjectFile) is Multilingual build enabled, but the Multilingual App Toolkit is unavailable during the build. If building with Visual Studio, please check to ensure that toolkit is properly installed." />
Expand Down
Expand Up @@ -20,14 +20,14 @@ namespace Covid19Radar.Services
[Xamarin.Forms.Internals.Preserve] // Ensure this isn't linked out
public class ExposureNotificationHandler : IExposureNotificationHandler
{
private readonly HttpDataService httpDataService;
private readonly IHttpDataService httpDataService;
private readonly UserDataService userDataService;
private UserDataModel userData;
private Configuration configuration;

public ExposureNotificationHandler()
{
this.httpDataService = Xamarin.Forms.DependencyService.Resolve<HttpDataService>();
this.httpDataService = Xamarin.Forms.DependencyService.Resolve<IHttpDataService>();
this.userDataService = Xamarin.Forms.DependencyService.Resolve<UserDataService>();
userData = this.userDataService.Get();
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ namespace Covid19Radar.Services
{
public class ExposureNotificationService
{
private readonly HttpDataService httpDataService;
private readonly IHttpDataService httpDataService;
private readonly UserDataService userDataService;
private readonly INavigationService navigationService;
public string CurrentStatusMessage { get; set; } = "初期状態";
Expand All @@ -26,7 +26,7 @@ public class ExposureNotificationService
private SecondsTimer _downloadTimer;
private UserDataModel userData;

public ExposureNotificationService(INavigationService navigationService, UserDataService userDataService, HttpDataService httpDataService)
public ExposureNotificationService(INavigationService navigationService, UserDataService userDataService, IHttpDataService httpDataService)
{
this.httpDataService = httpDataService;
this.navigationService = navigationService;
Expand Down
2 changes: 1 addition & 1 deletion Covid19Radar/Covid19Radar/Services/HttpDataService.cs
Expand Up @@ -13,7 +13,7 @@

namespace Covid19Radar.Services
{
public class HttpDataService
public class HttpDataService: IHttpDataService
{
private readonly HttpClient httpClient;
private readonly HttpClient downloadClient;
Expand Down
55 changes: 55 additions & 0 deletions Covid19Radar/Covid19Radar/Services/HttpDataServiceMock.cs
@@ -0,0 +1,55 @@
using Covid19Radar.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Covid19Radar.Services
{
class HttpDataServiceMock : IHttpDataService
{
Task<Stream> IHttpDataService.GetTemporaryExposureKey(string url, CancellationToken cancellationToken)
{
return Task.Factory.StartNew<Stream>(() => {
Debug.WriteLine("HttpDataServiceMock::GetTemporaryExposureKey called");
return new MemoryStream();
});
}

Task<List<TemporaryExposureKeyExportFileModel>> IHttpDataService.GetTemporaryExposureKeyList(string region, CancellationToken cancellationToken)
{
return Task.Factory.StartNew<List<TemporaryExposureKeyExportFileModel>>(() => {
Debug.WriteLine("HttpDataServiceMock::GetTemporaryExposureKeyList called");
return new List<TemporaryExposureKeyExportFileModel>();
});
}

async Task<UserDataModel> IHttpDataService.PostRegisterUserAsync()
{
Debug.WriteLine("HttpDataServiceMock::PostRegisterUserAsync called");

UserDataModel userData = new UserDataModel();
userData.Secret = "dummy secret";
userData.UserUuid = "dummy uuid";
userData.JumpConsistentSeed = 999;
userData.IsOptined = true;
Application.Current.Properties["Secret"] = userData.Secret;
await Application.Current.SavePropertiesAsync();
return userData;
}

Task<HttpStatusCode> IHttpDataService.PutSelfExposureKeysAsync(DiagnosisSubmissionParameter request)
{
return Task.Factory.StartNew<HttpStatusCode>(() =>
{
Debug.WriteLine("HttpDataServiceMock::PutSelfExposureKeysAsync called");
return HttpStatusCode.OK;
});
}
}
}
22 changes: 22 additions & 0 deletions Covid19Radar/Covid19Radar/Services/IHttpDataService.cs
@@ -0,0 +1,22 @@
using Covid19Radar.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Covid19Radar.Services
{
public interface IHttpDataService
{
Task<UserDataModel> PostRegisterUserAsync();

Task<HttpStatusCode> PutSelfExposureKeysAsync(DiagnosisSubmissionParameter request);

Task<List<TemporaryExposureKeyExportFileModel>> GetTemporaryExposureKeyList(string region, CancellationToken cancellationToken);

Task<Stream> GetTemporaryExposureKey(string url, CancellationToken cancellationToken);
}
}
4 changes: 2 additions & 2 deletions Covid19Radar/Covid19Radar/Services/UserDataService.cs
Expand Up @@ -11,11 +11,11 @@ namespace Covid19Radar.Services
/// </summary>
public class UserDataService
{
private readonly HttpDataService httpDataService;
private readonly IHttpDataService httpDataService;
private UserDataModel current;
public event EventHandler<UserDataModel> UserDataChanged;

public UserDataService(HttpDataService httpDataService)
public UserDataService(IHttpDataService httpDataService)
{
this.httpDataService = httpDataService;
current = Get();
Expand Down
10 changes: 10 additions & 0 deletions Covid19Radar/Tests/Covid19Radar.UITest/Covid19Radar.UITest.csproj
Expand Up @@ -34,6 +34,16 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_Mock|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug_Mock\</OutputPath>
<DefineConstants>DEBUG;USE_MOCK;</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
Expand Down

0 comments on commit 6835f25

Please sign in to comment.