public void NoChangeInRepositoryIfNoSettings() { // 設定値が空 var diBuilder = new TestDiProviderBuilder(); diBuilder.ServiceCollection.AddTransient <ITimeProvider>(x => UnitTestHelper.CreateTimeProvider(new DateTime(2020, 3, 1))); diBuilder.ServiceCollection.AddSingleton <IPrimaryRepository, PrimaryRepositoryMock>(); diBuilder.ServiceCollection.AddSingleton <IDtDeviceFileRepository, DtDeviceFileRepositoryMock>(); var provider = diBuilder.Build(); // テスト対象 var target = provider.GetService <ICleanBlobService>(); target.Clean(); // 結果確認のため、状態を持つリポジトリを取得する。このために上記の設定でシングルトンにしている。 var primaryRepositoryMock = provider.GetService <IPrimaryRepository>() as PrimaryRepositoryMock; var deviceFileRepositoryMock = provider.GetService <IDtDeviceFileRepository>() as DtDeviceFileRepositoryMock; // Delete が特に変更ないことを確認。 var list = PrimaryRepositoryMock.GetDefaultList(); Assert.AreEqual( PrimaryRepositoryMock.GetDefaultList().ToStringJson(), primaryRepositoryMock.ArchiveFiles.ToStringJson()); Assert.AreEqual( DtDeviceFileRepositoryMock.GetDefaultList().ToStringJson(), deviceFileRepositoryMock.files.ToStringJson()); }
public void ExceptionTest( bool IsFailed_CreateDtDeviceFile, bool IsFailed_GetFileDatasBelowFilePath, bool IsFailed_DeleteDtDeviceFile, bool IsThrowEx_CreateDtDeviceFile, bool IsThrowEx_GetFileDatasBelowFilePath, bool IsThrowEx_DeleteDtDeviceFile) { // 設定値 var diBuilder = new TestDiProviderBuilder(); diBuilder.AddConfigure("BlobCleanTarget_container_path/folder1", "1"); // DI設定 diBuilder.ServiceCollection.AddTransient <ITimeProvider>(x => UnitTestHelper.CreateTimeProvider(new DateTime(2020, 3, 1))); var primaryRepository = new PrimaryRepositoryMock(); diBuilder.ServiceCollection.AddSingleton <IPrimaryRepository>(x => primaryRepository); // 失敗設定する var dtDeviceFileRepository = new DtDeviceFileRepositoryMock() .FailedIfCallCreateDtDeviceFile(IsFailed_CreateDtDeviceFile) .FailedIfCallDeleteDtDeviceFile(IsFailed_DeleteDtDeviceFile) .FailedIfCallGetFileDatasBelowFilePath(IsFailed_GetFileDatasBelowFilePath) .ThrowIfCallCreateDtDeviceFile(IsThrowEx_CreateDtDeviceFile) .ThrowIfCallDeleteDtDeviceFile(IsThrowEx_DeleteDtDeviceFile) .ThrowIfCallGetFileDatasBelowFilePath(IsThrowEx_GetFileDatasBelowFilePath); diBuilder.ServiceCollection.AddSingleton <IDtDeviceFileRepository>(x => dtDeviceFileRepository); var provider = diBuilder.Build(); // テスト対象実行 var target = provider.GetService <ICleanBlobService>(); target.Clean(); var expected = GetExpected("CreateAllData"); Assert.AreEqual( expected.Item1.ToStringJson(), dtDeviceFileRepository.files.ToStringJson()); Assert.AreEqual( expected.Item2.ToStringJson(), primaryRepository.ArchiveFiles.ToStringJson()); }