/// <summary> /// デバイスツイン更新イベントを受信して端末テーブルの「リモート接続UID」と「RMSソフトバージョン」を更新する /// </summary> /// <param name="sid">端末SID</param> /// <param name="data">更新データ</param> /// <returns>更新したデータ。テーブルが更新されなかった場合にはnullを返す</returns> public DtDevice UpdateDeviceInfoByTwinChanged(long sid, DtTwinChanged data) { DtDevice model = null; try { _logger.EnterJson("{0}", sid); _dbPolly.Execute(() => { using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings)) { string remoteConnectionUid = data.RemoteConnectionUid; string rmsSoftVersion = data.SoftVersion; // リモート接続UIDとRMSソフトバージョンを更新する DtDevice inData = new DtDevice() { Sid = sid, RemoteConnectUid = remoteConnectionUid, RmsSoftVersion = rmsSoftVersion }; DBAccessor.Models.DtDevice entity = new DBAccessor.Models.DtDevice(inData); db.DtDevice.Attach(entity); // リモート接続UIDとRMSソフトバージョンを更新する db.Entry(entity).Property(x => x.RemoteConnectUid).IsModified = true; db.Entry(entity).Property(x => x.RmsSoftVersion).IsModified = true; if (db.SaveChanges(_timePrivder) > 0) { model = entity.ToModel(); } } }); return(model); } catch (ValidationException e) { throw new RmsParameterException(e.ValidationResult.ErrorMessage, e); } catch (Exception e) { throw new RmsException("DT_DEVICEテーブルのUpdateに失敗しました。", e); } finally { _logger.LeaveJson("{0}", model); } }
public void UpdateDeviceInfoByTwinChangedTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string expected_DataJsonPath, string expected_ExceptionType, string expected_ExceptionMessage, string remarks) { DtDeliveryGroup readDeliveryGroup = new DtDeliveryGroup() { Sid = 0 }; DtTwinChanged twinChangedData = new DtTwinChanged() { RemoteConnectionUid = RepositoryTestHelper.CreateSpecifiedNumberString(64), SoftVersion = RepositoryTestHelper.CreateSpecifiedNumberString(30), }; if (expected_ExceptionType == typeof(RmsParameterException).FullName) { if (expected_ExceptionMessage.Contains("RemoteConnectUid")) { twinChangedData.RemoteConnectionUid = RepositoryTestHelper.CreateSpecifiedNumberString(65); // 上限値+1 } else if (expected_ExceptionMessage.Contains("RmsSoftVersion")) { twinChangedData.SoftVersion = RepositoryTestHelper.CreateSpecifiedNumberString(31); // 上限値+1 } } // 初期データ挿入 RepositoryTestHelper.ExecInsertSql(in_InsertNewDataSqlPath); string exceptionName = ""; string exceptionMessage = ""; try { if (expected_ExceptionType == typeof(ArgumentNullException).FullName) { twinChangedData = null; } // データを取得する(配信結果付き) var readModel = _deviceRepository.UpdateDeviceInfoByTwinChanged(2, twinChangedData); if (readModel != null) { readModel.UpdateDatetime = DateTime.Parse("2020/4/1 0:00:00"); } // データのjson化 string readJson = Utility.ObjectExtensions.ToStringJson(readModel); string expectJson = null; if (File.Exists(expected_DataJsonPath)) { expectJson = File.ReadAllText(expected_DataJsonPath); } // データの比較 Assert.AreEqual(expectJson, readJson); // TODO DBデータ内容をチェックする } catch (RmsParameterException e) { exceptionName = e.GetType().FullName; exceptionMessage = e.Message; } catch (ArgumentNullException e) { exceptionName = e.GetType().FullName; exceptionMessage = typeof(DtDevice).FullName + " is null."; // HACK ←の部分をメッセージから抽出できれば... } // 例外発生チェック Assert.AreEqual(expected_ExceptionType, exceptionName); Assert.AreEqual(expected_ExceptionMessage, exceptionMessage); // 後処理 RepositoryTestHelper.ExecDeleteSql(in_DeleteNewDataSqlPath); }