Example #1
0
        public void Onepass()
        {
            // 準備
            var diBuilder = new TestDiProviderBuilder();

            diBuilder.AddConfigure("BlobCleanTarget_container_filepath", "30");

            // init
            // DBにファイルパス、データを追加

            // コンテナがなければ作成
            // Blobにそれと同じファイルを追加
            var file = new ArchiveFile()
            {
                ContainerName = "",
                FilePath      = ""
            };

            // プロバイダ生成
            var provider = diBuilder.Build();

            // ■テストの本筋
            var actual = provider.GetService <CleanBlobService>();

            actual.Clean();

            // 削除対象がGetできばOK
            // 非削除対象がGetできなければNG

            // 後始末
        }
Example #2
0
        private DpsPolly CreateTestTarget(int?retry = null, int?delaySeconds = null)
        {
            // DI設定
            var builder = new TestDiProviderBuilder();

            if (null != retry)
            {
                builder.AddConfigure("DpsMaxRetryAttempts", retry.ToString());
            }
            if (null != delaySeconds)
            {
                builder.AddConfigure("DpsDelayDeltaSeconds", delaySeconds.ToString());
            }
            var provider = builder.Build();

            return(provider.GetService <DpsPolly>());
        }
Example #3
0
        public void NormarizeTest(
            string SettingKey1, string SettingValue1,
            string SettingKey2, string SettingValue2,
            int nowMonth,
            string expectedGetterName)
        {
            // 設定値
            var diBuilder = new TestDiProviderBuilder();

            diBuilder.AddConfigure(SettingKey1, SettingValue1);
            diBuilder.AddConfigure(SettingKey2, SettingValue2);

            // DI設定
            diBuilder.ServiceCollection.AddTransient <ITimeProvider>(x => UnitTestHelper.CreateTimeProvider(new DateTime(2020, nowMonth, 1)));
            diBuilder.ServiceCollection.AddSingleton <IPrimaryRepository, PrimaryRepositoryMock>();
            diBuilder.ServiceCollection.AddSingleton <IDtDeviceFileRepository, DtDeviceFileRepositoryMock>();
            var provider = diBuilder.Build();

            // テスト対象実行
            var target = provider.GetService <ICleanBlobService>();

            target.Clean();

            var expected = GetExpected(expectedGetterName);

            // 結果確認のため、状態を持つリポジトリを取得する。このために上記の設定でシングルトンにしている。
            var primaryRepository      = provider.GetService <IPrimaryRepository>() as PrimaryRepositoryMock;
            var dtDeviceFileRepository = provider.GetService <IDtDeviceFileRepository>() as DtDeviceFileRepositoryMock;

            Assert.AreEqual(
                expected.Item1.ToStringJson(),
                dtDeviceFileRepository.files.ToStringJson());
            Assert.AreEqual(
                expected.Item2.ToStringJson(),
                primaryRepository.ArchiveFiles.ToStringJson());
        }
Example #4
0
        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());
        }
Example #5
0
        public void GetIntValueTest(string targetPropertyName, string actualValue, int expected)
        {
            // テスト対象の準備
            //NULLか空欄ではなかったら
            var diBuilder = new TestDiProviderBuilder();

            if (int.TryParse(actualValue, out int result) == true)
            {
                diBuilder.AddConfigure(targetPropertyName, actualValue);
            }
            var         provider   = diBuilder.Build();
            AppSettings testTarget = provider.GetService(typeof(AppSettings)) as AppSettings;

            // テスト
            var property = typeof(AppSettings).GetProperty(targetPropertyName);
            int?actual   = property.GetValue(testTarget) as int?;

            //結果
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        private void DependencyInjection(Dictionary <string, string> appSettings = null)
        {
            TestDiProviderBuilder builder = new TestDiProviderBuilder();

            builder.ServiceCollection.AddTransient <PrimaryBlob>();

            if (appSettings != null)
            {
                foreach (KeyValuePair <string, string> pair in appSettings)
                {
                    builder.AddConfigure(pair.Key, pair.Value);
                }
            }

            builder.ServiceCollection.AddSingleton <ITimeProvider>(UnitTestHelper.CreateTimeProvider(new DateTime(2030, 1, 1)));
            ServiceProvider provider = builder.Build();

            primaryBlob = provider.GetService <PrimaryBlob>();
            target      = provider.GetService <IPrimaryRepository>();
        }
Example #7
0
        public void GetStringValueTest(string targetPropertyName, string actualValue, string expected)
        {
            // テスト対象の準備
            //NULLか空欄ではなかったら
            var diBuilder = new TestDiProviderBuilder();

            if (!string.IsNullOrEmpty(actualValue))
            {
                ///keyと値の追加
                diBuilder.AddConfigure(targetPropertyName, actualValue);
            }
            var         provider   = diBuilder.Build();
            AppSettings testTarget = provider.GetService(typeof(AppSettings)) as AppSettings;

            // テスト
            //プロパティを取ってくる
            //actual 取ってきた値
            var    property = typeof(AppSettings).GetProperty(targetPropertyName);
            string actual   = property.GetValue(testTarget) as string;

            //結果
            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void Onepass()
        {
            // DbSetup
            DbTestHelper.DeleteAll();
            var dataOnDb = DbTestHelper.CreateMasterTables();

            dataOnDb = DbTestHelper.CreateDeliveries(dataOnDb);
            dataOnDb = DbTestHelper.CreateDevices(dataOnDb);

            // Target Create
            var builder = new TestDiProviderBuilder();

            builder.ServiceCollection.AddTransient <CleanDbService>();
            var provider = builder.Build();
            var service  = provider.GetService <CleanDbService>();

            // 削除対象Insert
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("DeviceSid", dataOnDb.GetDtDeviceSid());
            dic.Add("CreateDatetime", "2019/12/31 23:59:59");
            dic.Add("IsLatest", true);
            DbTestHelper.ExecuteInsertSqlCommand("DtInventory", dic);

            /* SSMSなどで登録されているかチェック */

            // DbCleaner削除対象設定
            var diBuilder = new TestDiProviderBuilder();

            diBuilder.AddConfigure("DbCleanTarget_DtInventory", "1");

            // DbCleaner実行
            service.Clean();

            /* SSMSなどで削除されているかチェック */
        }