示例#1
0
 /// <summary>
 /// FailureBlobのファイルを削除する
 /// <param name="failureBlob">FailureBlob</param>
 /// <param name="containerName">コンテナ名</param>
 /// </summary>
 public static void DeleteFailureBlobFile(FailureBlob failureBlob, string containerName)
 {
     foreach (CloudBlockBlob blockBlob in failureBlob.Client.GetBlockBlobs(containerName))
     {
         blockBlob.DeleteIfExistsAsync().Wait();
     }
 }
示例#2
0
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        /// <param name="testLogs">ログの格納先</param>
        /// <param name="testMails">送信したメール情報を格納するリスト</param>
        /// <param name="mockResponseCode">SendMailメソッドが返却するHTTPステータスコード</param>
        /// <param name="mockResponseException">SendMailメソッドが返却するException</param>
        private void DependencyInjection(Dictionary <string, string> appSettings = null, List <TestLog> testLogs = null, List <MailInfo> testMails = null, HttpStatusCode mockResponseCode = HttpStatusCode.Accepted, Exception mockResponseException = null)
        {
            var builder = new TestDiProviderBuilder <OperationAppSettings>(FunctionsHostBuilderExtend.AddUtility);

            builder.ServiceCollection.AddTransient <MailSenderController>();
            builder.ServiceCollection.AddTransient <FailureBlob>();
            builder.AddConfigures(appSettings);

            Mock <DateTimeProvider> timeProviderMock = new Mock <DateTimeProvider>();

            timeProviderMock.SetupGet(tp => tp.UtcNow).Returns(TestTime);
            builder.ServiceCollection.AddSingleton <ITimeProvider>(timeProviderMock.Object);

            if (testLogs != null)
            {
                builder.ServiceCollection.AddSingleton <ILogger <MailSenderService> >(new TestLogger <MailSenderService>(testLogs));
            }

            if (testMails != null)
            {
                builder.ServiceCollection.AddTransient <IMailRepository>(x => new TestMailRepository(testMails, mockResponseCode, mockResponseException));
            }

            ServiceProvider provider = builder.Build();

            failureBlob = provider.GetService <FailureBlob>();
            settings    = provider.GetService <AppSettings>() as OperationAppSettings;
            target      = provider.GetService <MailSenderController>();
        }
示例#3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">AppSettings</param>
        /// <param name="failureBlob">FailureBlob</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">Logger</param>
        public FailureBlobRepository(
            AppSettings settings,
            FailureBlob failureBlob,
            BlobPolly polly,
            ILogger <FailureBlobRepository> logger)
        {
            Assert.IfNull(settings);
            Assert.IfNull(failureBlob);
            Assert.IfNull(logger);
            Assert.IfNull(polly);

            _settings    = settings;
            _failureBlob = failureBlob;
            _log         = logger;
            _polly       = polly;
        }
示例#4
0
        public static void ClassCleanup()
        {
            FailureBlob failureBlob;

            // DI
            {
                TestDiProviderBuilder builder = new TestDiProviderBuilder();
                builder.ServiceCollection.AddTransient <FailureBlob>();

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

            var container1 = failureBlob.Client.GetContainerReference(TargetContainerName1);

            container1.DeleteIfExistsAsync().Wait();
        }
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        /// <param name="testLogs">ログの格納先</param>
        /// <param name="exceptionMethodName">例外を発生させるサービスのメソッド名</param>
        private void DependencyInjection(Dictionary <string, string> appSettings = null, List <TestLog> testLogs = null, string exceptionMethodName = null)
        {
            // DI前のFailureBlobを取得
            var locaSettingsBuilder  = new TestDiProviderBuilder();
            var locaSettingsProvider = locaSettingsBuilder.Build();

            _failureBlob = locaSettingsProvider.GetService <FailureBlob>();

            var builder = new TestDiProviderBuilder <AppSettings>(FunctionsHostBuilderExtend.AddUtility);

            builder.ServiceCollection.AddTransient <DispatchController>();
            builder.ServiceCollection.AddTransient <FailureBlob>();

            if (appSettings != null)
            {
                builder.AddConfigures(appSettings);
            }

            Mock <DateTimeProvider> timeProviderMock = new Mock <DateTimeProvider>();

            timeProviderMock.SetupGet(tp => tp.UtcNow).Returns(TestTime);
            builder.ServiceCollection.AddSingleton <ITimeProvider>(timeProviderMock.Object);

            if (testLogs != null)
            {
                builder.ServiceCollection.AddSingleton <ILogger <DispatchService> >(new TestLogger <DispatchService>(testLogs));
            }

            if (!string.IsNullOrEmpty(exceptionMethodName))
            {
                builder.ServiceCollection.AddTransient <IDispatchService, DispatchServiceMock>();
            }

            ServiceProvider provider = builder.Build();

            _diAppSettings = provider.GetService <AppSettings>();
            _target        = provider.GetService <DispatchController>();

            var dispatchServiceMock = provider.GetService <IDispatchService>() as DispatchServiceMock;

            dispatchServiceMock?.Init(exceptionMethodName);
        }
示例#6
0
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        private void DependencyInjection(Dictionary <string, string> appSettings = null)
        {
            TestDiProviderBuilder builder = new TestDiProviderBuilder();

            builder.ServiceCollection.AddTransient <FailureBlob>();

            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();

            failureBlob = provider.GetService <FailureBlob>();
            target      = provider.GetService <IFailureRepository>();
        }
示例#7
0
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="appSettings">アプリケーション設定を上書きする場合は指定する</param>
        /// <param name="testLogs">ログの格納先</param>
        private void DependencyInjection(Dictionary <string, string> appSettings = null, List <TestLog> testLogs = null)
        {
            var builder = new TestDiProviderBuilder <UtilityAppSettings>(FunctionsHostBuilderExtend.AddUtility);

            builder.ServiceCollection.AddTransient <DirectoryUsageMonitorController>();
            builder.ServiceCollection.AddTransient <FailureBlob>();
            builder.AddConfigures(appSettings);

            Mock <DateTimeProvider> timeProviderMock = new Mock <DateTimeProvider>();

            timeProviderMock.SetupGet(tp => tp.UtcNow).Returns(TestTime);
            builder.ServiceCollection.AddSingleton <ITimeProvider>(timeProviderMock.Object);

            if (testLogs != null)
            {
                builder.ServiceCollection.AddSingleton <ILogger <DirectoryUsageMonitorService> >(new TestLogger <DirectoryUsageMonitorService>(testLogs));
            }

            ServiceProvider provider = builder.Build();

            failureBlob = provider.GetService <FailureBlob>();
            settings    = provider.GetService <AppSettings>() as UtilityAppSettings;
            target      = provider.GetService <DirectoryUsageMonitorController>();
        }