Example #1
0
 /// <summary>
 /// 中止フラグ更新リクエストのDtoクラスパラメータをUtilityのパラメータに変換する
 /// </summary>
 /// <param name="dto">Dtoクラスパラメータ</param>
 /// <param name="deliveryFileId">配信ファイルID</param>
 /// <returns>Utilityパラメータ</returns>
 public static DtDeliveryFile ConvertDtoToUtility(this DeliveryFileStatusUpdateRequestDto dto, long deliveryFileId)
 {
     return(new DtDeliveryFile()
     {
         Sid = deliveryFileId,
         IsCanceled = dto.DeliveryStatus.Equals(RequestDeliveryStatus.Stop) ? true : false,
         RowVersion = WebApiHelper.ConvertLongToByteArray(dto.RowVersion.Value)
     });
 }
Example #2
0
        public IActionResult PutDeliveryFileStatus(
            [RequestBodyType(typeof(DeliveryFileStatusUpdateRequestDto), "配信ファイル更新リクエスト")]
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "deliveryfiles/{deliveryFileId}/status")]
            DeliveryFileStatusUpdateRequestDto request,
            long deliveryFileId,
            ILogger log)
        {
            log.EnterJson("Request: {0}", request.ToStringProperties());
            ActionResult response = null;

            try
            {
                // リクエストパラメータチェック
                string message = string.Empty;
                if (RequestValidator.IsBadRequestParameter(request, out message))
                {
                    log.Error(nameof(Resources.CO_API_DSU_002), new object[] { message });
                    return(new BadRequestObjectResult(string.Empty));
                }

                var utilParam   = request.ConvertDtoToUtility(deliveryFileId);
                var resultParam = _service.PutCancelFlag(utilParam);

                // Resultから返却ステータスを作成(レスポンスボディは空)
                response = SqlResultConverter.ConvertToActionResult(resultParam.ResultCode, resultParam.Message);
            }
            catch (Exception e)
            {
                log.Error(e, nameof(Resources.CO_API_DSU_001));
                response = new StatusCodeResult(StatusCodes.Status500InternalServerError);
            }
            finally
            {
                log.LeaveJson("Response: {0}", response);
            }

            return(response);
        }
        public void PutDeliveryFileStatusTest(
            string no,
            string in_InsertNewDataSqlPath,
            string in_DeleteNewDataSqlPath,
            string in_InputJsonDataPath,
            string in_SidFormat,
            string in_AppSettingsInvalid,
            string in_ServiceException,
            string expected_DataJsonPath,
            string expected_LogMessagesPath,
            string expected_DtDeliveryFile_TableDataPath,
            string remarks)
        {
            Dictionary <string, string> dir = null;

            if (bool.TryParse(in_AppSettingsInvalid, out bool isAppSettingsInvalid) && isAppSettingsInvalid)
            {
                // DB接続文字列が不正なAppSettingsとする
                dir = new Dictionary <string, string>()
                {
                    { "ConnectionStrings:PrimaryDbConnectionString", "TestConnectionString" }
                };
            }

            // DI実施
            DependencyInjection(DateTime.Parse("2020/04/30 09:00:00.0000000"), dir, (bool.TryParse(in_ServiceException, out bool isServiceException) && isServiceException));

            // 初期データ挿入
            DbTestHelper.ExecSqlFromFilePath(in_InsertNewDataSqlPath);

            // 投入JSONをDTOに変換する
            string inputDtoJson = (!string.IsNullOrEmpty(in_InputJsonDataPath) && File.Exists(in_InputJsonDataPath)) ?
                                  File.ReadAllText(in_InputJsonDataPath) :
                                  "";

            // SID, RowVersionの取得
            DataTable inputDataTable = DbTestHelper.SelectTable("SELECT SID, ROW_VERSION FROM core.DT_DELIVERY_FILE");
            long      sid            = 1;
            long      rowVersion     = 0;

            if (inputDataTable.Rows.Count > 0)
            {
                sid        = (long)inputDataTable.Rows[0].ItemArray[0];
                rowVersion = WebApiHelper.ConvertByteArrayToLong((byte[])inputDataTable.Rows[0].ItemArray[1]);
            }

            // 投入するSIDを設定
            long inputSid = long.Parse(string.Format(in_SidFormat, sid));

            // JSONにRowVersionを埋め込む(JSONだと中括弧がFormatに影響を与えて面倒なので、Replaceを使用する)
            inputDtoJson = inputDtoJson.Replace("\"rowVersion\": {0}", "\"rowVersion\": " + rowVersion);

            // DTO変換できない場合は初期値とする(Azure Functionsと同様の挙動)
            DeliveryFileStatusUpdateRequestDto inputDto = null;

            try
            {
                inputDto = JsonConvert.DeserializeObject <DeliveryFileStatusUpdateRequestDto>(inputDtoJson);
            }
            catch (Exception)
            {
                inputDto = new DeliveryFileStatusUpdateRequestDto();
            }

            // ログ格納用ロガーの用意
            var actualLogs = new List <TestLog>();
            var logger     = new TestLogger <DeliveryFilesController>(actualLogs);

            // WebApi実行
            var postResult = _controller.PutDeliveryFileStatus(inputDto, inputSid, logger);

            // データのjson化
            string resultJson = Rms.Server.Core.Utility.ObjectExtensions.ToStringJsonIndented(postResult);
            string expectJson = null;

            if (File.Exists(expected_DataJsonPath))
            {
                expectJson = File.ReadAllText(expected_DataJsonPath);

                // 期待値は投入RowVersion値+1(JSONだと中括弧がFormatに影響を与えて面倒なので、Replaceを使用する)
                expectJson = expectJson.Replace("\"rowVersion\": {0}", "\"rowVersion\": " + (rowVersion + 1));
            }

            // データの比較
            Assert.AreEqual(expectJson, resultJson);

            // 期待するログ、実際のログを取得
            List <string> expectedLogMessages = (!string.IsNullOrEmpty(expected_LogMessagesPath) && File.Exists(expected_LogMessagesPath)) ?
                                                File.ReadLines(expected_LogMessagesPath).ToList() :
                                                new List <string>();
            List <string> actualControllerLogMessages = actualLogs.Select(x => x.GetSimpleText()).ToList();
            List <string> actualServiceLogMessages    = _serviceLogs.Select(x => x.GetSimpleText()).ToList();

            // ControllerかServiceで期待するログが出力されたか確認
            foreach (var expectedLogMessage in expectedLogMessages)
            {
                var matchingElementController = actualControllerLogMessages.FirstOrDefault(actual => actual.Contains(expectedLogMessage));
                var matchingElementService    = actualServiceLogMessages.FirstOrDefault(actual => actual.Contains(expectedLogMessage));
                Assert.IsTrue((matchingElementController != null || matchingElementService != null), string.Format("「{0}」に一致する要素が見つかりません", expectedLogMessage));
                actualControllerLogMessages.Remove(matchingElementController);
                actualControllerLogMessages.Remove(matchingElementService);
            }

            // テーブルデータの実際の値・期待値を取得(RowVersion以外)
            DataTable DeliveryFileActualTable = DbTestHelper.SelectTable(
                @"SELECT 
                    SID, DELIVERY_FILE_TYPE_SID, INSTALL_TYPE_SID, FILE_PATH, VERSION, INSTALLABLE_VERSION, DESCRIPTION, INFORMATION_ID, IS_CANCELED, CREATE_DATETIME, UPDATE_DATETIME
                FROM core.DT_DELIVERY_FILE");
            DataTable DeliveryFileExpectedTable = DbTestHelper.SelectCsv(expected_DtDeliveryFile_TableDataPath,
                                                                         @"SELECT 
                    SID, DELIVERY_FILE_TYPE_SID, INSTALL_TYPE_SID, FILE_PATH, VERSION, INSTALLABLE_VERSION, DESCRIPTION, INFORMATION_ID, IS_CANCELED, CREATE_DATETIME, UPDATE_DATETIME
                FROM core.DT_DELIVERY_FILE");

            // テーブルデータの比較
            CheckDataTableEquals(DeliveryFileExpectedTable, DeliveryFileActualTable);

            // 後処理
            DbTestHelper.ExecSqlFromFilePath(in_DeleteNewDataSqlPath);
        }