Ejemplo n.º 1
0
        public void ctr_should_update_device()
        {
            var obj = ctr.GetDevice("a5123") as OkObjectResult;
            var res = obj?.Value as DeviceViewModel;

            Assert.NotNull(res);
            var device = res;

            device.DeviceId = 1011;
            device.Name     = "Neuer Name";
            ctr.PutDevice(1011, device);

            Assert.NotNull(res);
            var device2 = res;

            Assert.True(device2.Name.Equals("Neuer Name"));
        }
Ejemplo n.º 2
0
        public void PutDeviceTest(
            string no,
            string in_InsertNewDataSqlPath,
            string in_DeleteNewDataSqlPath,
            string in_InputJsonDataPath,
            string in_InitialBlobFilePath,
            string in_DeliveringBlobContainerNameInstallbase,
            string in_DeliveringBlobInstallbaseFilePath,
            string in_SidFormat,
            string in_InvalidDbConnectionString,
            string in_InvalidBlobConnectionString,
            string in_ServiceException,
            string expected_DataJsonPath,
            string expected_LogMessagesPath,
            string expected_UploadedDeliveringBlobPath,
            string expected_DtDevice_TableDataPath,
            string remarks)
        {
            string configContents;

            try
            {
                bool didUploadInitialBlob = CommonPreset(
                    DateTime.Parse("2020/04/30 09:00:00.0000000"),
                    in_InvalidDbConnectionString,
                    in_InvalidBlobConnectionString,
                    in_ServiceException,
                    in_DeliveringBlobContainerNameInstallbase,
                    in_DeliveringBlobInstallbaseFilePath,
                    in_InsertNewDataSqlPath,
                    in_InitialBlobFilePath,
                    out configContents);

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

                // SID, RowVersionの取得
                DataTable inputDataTable = DbTestHelper.SelectTable("SELECT SID, EDGE_ID, EQUIPMENT_UID FROM core.DT_DEVICE");
                long      sid            = 1;
                string    edgeId         = string.Empty;
                string    equipmentUid   = string.Empty;
                if (inputDataTable.Rows.Count > 0)
                {
                    sid          = (long)inputDataTable.Rows[0].ItemArray[0];
                    edgeId       = ((Guid)inputDataTable.Rows[0].ItemArray[1]).ToString();
                    equipmentUid = (string)inputDataTable.Rows[0].ItemArray[2];
                }

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

                // DTO変換できない場合は初期値とする(Azure Functionsと同様の挙動)
                DeviceUpdateRequestDto inputDto;
                try
                {
                    inputDto = JsonConvert.DeserializeObject <DeviceUpdateRequestDto>(inputDtoJson);
                }
                catch (Exception)
                {
                    inputDto = new DeviceUpdateRequestDto();
                }

                // アップロード予定の場所にあるBlobを削除する
                TryFormatDeliveringBlobInstallbaseFilePath(_appSettings.DeliveringBlobInstallbaseFilePath, equipmentUid, out string filePath);
                if (didUploadInitialBlob &&
                    (!_appSettings.DeliveringBlobContainerNameInstallbase.Equals(_initialBlobContainerName) || !filePath.Equals(_initialBlobFilePath)))
                {
                    // 事前Blobがアップロードされている場合は違うパスの時のみ削除する
                    TryDeleteBlob(in_DeliveringBlobContainerNameInstallbase, filePath);
                }

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

                // WebApi実行
                var putResult = _controller.PutDevice(inputDto, inputSid, logger);

                // レスポンスデータをチェックする
                CheckResponseDataEquals(putResult, expected_DataJsonPath, edgeId);

                // ログの出力をチェックする
                CheckLogMessagesContains(expected_LogMessagesPath, actualLogs, edgeId);

                // DB内容をチェックする
                CheckDbDataEquals(expected_DtDevice_TableDataPath);

                // アップロードしたBlobの内容をチェックし、削除する
                CheckBlobsEqualsAndCleanBlobs(
                    didUploadInitialBlob,
                    edgeId,
                    configContents,
                    _appSettings.DeliveringBlobContainerNameInstallbase,
                    filePath,
                    expected_UploadedDeliveringBlobPath);

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