コード例 #1
0
        public void ctr_should_create_device()
        {
            var vmdl = ControllerHelper.GetValidDeviceViewModel();

            vmdl.InvNum = Guid.NewGuid().ToString();
            var obj = ctr.PostDevice(vmdl) as OkObjectResult;
            var res = obj?.Value as List <DeviceViewModel>;

            Assert.NotNull(res);

            var d = Bl.GetDevices();

            Assert.True(d.Any(i => i.InvNum.Equals(vmdl.InvNum)));
        }
コード例 #2
0
        public void PostDeviceTest(
            string no,
            string in_InsertNewDataSqlPath,
            string in_DeleteNewDataSqlPath,
            string in_InputJsonDataPath,
            string in_InitialBlobFilePath,
            string in_DeliveringBlobContainerNameInstallbase,
            string in_DeliveringBlobInstallbaseFilePath,
            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/01 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) :
                                      "";

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

                // アップロード予定の場所にあるBlobを削除する
                TryFormatDeliveringBlobInstallbaseFilePath(_appSettings.DeliveringBlobInstallbaseFilePath, inputDto.Device?.EquipmentUid, out string filePath);
                TryDeleteBlob(in_DeliveringBlobContainerNameInstallbase, filePath);

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

                // WebApi実行
                string edgeId     = string.Empty;
                var    postResult = _controller.PostDevice(inputDto, logger);
                if (postResult is OkObjectResult)
                {
                    // 結果が流動的になる値は比較できないので固定値を入れる
                    var okDto = ((postResult as OkObjectResult).Value as DeviceResponseDto);
                    Assert.IsNotNull(okDto);
                    edgeId = okDto.EdgeId.ToString();
                }

                // レスポンスデータをチェックする
                CheckResponseDataEquals(postResult, 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;
            }
        }