private void Port_OnCall(CallInfo callInfo) { ISubscriber subscriber = _billingSystem.GetSubscriberBy(callInfo.SourcePhoneNumber); ISubscriber targetSubscriber = _billingSystem.GetSubscriberBy(callInfo.TargetPhoneNumber); if (subscriber == null) { throw new NullReferenceException($"Subscriber with phoneNumber {callInfo.SourcePhoneNumber} not found!"); } if (targetSubscriber == null) { throw new NullReferenceException($"Subscriber with phoneNumber {callInfo.TargetPhoneNumber} not found!"); } if (subscriber.State == SubscriberState.Blocked) { subscriber.Port.CallResponce("Your phone number is bloked."); return; } if (targetSubscriber.State == SubscriberState.Blocked) { subscriber.Port.CallResponce("The subscriber you are calling is temporarily blocked."); return; } if (CallController.CheckStatePortsSubscribers(subscriber, targetSubscriber)) { callInfo.LimitCallDuraction = _billingSystem.GetLimitCallDuraction(subscriber); targetSubscriber.Port.InComingCall(callInfo); } }
public async void BulkInsert_No_Errors() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiCallServerResponseModel> .CreateResponse(null as ApiCallServerResponseModel); mockResponse.SetRecord(new ApiCallServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCallServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCallServerResponseModel> >(mockResponse)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiCallServerRequestModel>(); records.Add(new ApiCallServerRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var result = (response as OkObjectResult).Value as CreateResponse <List <ApiCallServerResponseModel> >; result.Success.Should().BeTrue(); result.Record.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCallServerRequestModel>())); }
/// <summary>非同期</summary> /// <param name="param">引数</param> /// <returns>結果</returns> /// <remarks> /// ここは副スレッドから実行されるので注意。 /// 非同期処理クラスに非同期処理を定義すると、 /// メンバ変数を引数として利用できる。 /// </remarks> public object btn6_Exec(object param) { // 戻り値(キャスト) TestParameterValue testParameterValue = (TestParameterValue)param; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品(スレッドセーフでないため副スレッド内で作る) CallController callCtrl = new CallController(""); // Invoke testReturnValue = (TestReturnValue)callCtrl.Invoke( "testWebService", testParameterValue); //// 進捗表示のテスト //this.ChangeProgress = delegate(object o) //{ // MessageBox.Show(o.ToString()); //}; //this.ExecChangeProgress("進捗表示"); //// 非同期メッセージボックス表示のテスト //DialogResult dr = this.ShowAsyncMessageBoxWin( // "メッセージ", "タイトル", MessageBoxButtons.YesNo, MessageBoxIcon.Information); //// 非同期メッセージボックス表示のテスト(エラー) //System.Windows.MessageBoxResult mr = this.ShowAsyncMessageBoxWPF("メッセージ", "タイトル", // System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Information); // 結果表示 return(testReturnValue); }
public async void Patch_No_Errors() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiCallServerResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(true); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCallServerRequestModel>())) .Callback <int, ApiCallServerRequestModel>( (id, model) => model.AddressId.Should().Be(1) ) .Returns(Task.FromResult <UpdateResponse <ApiCallServerResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCallServerResponseModel>(new ApiCallServerResponseModel())); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCallServerModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiCallServerRequestModel>(); patch.Replace(x => x.AddressId, 1); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCallServerRequestModel>())); }
// Método para lançar o evento que envia o test case para o controller protected virtual void OnCallController(TestCase testCase) { CallController?.Invoke(this, new TestCaseEventArgs() { TestCase = testCase }); }
private void Port_OnDrop(CallInfo callInfo) { ISubscriber subscriber = _billingSystem.GetSubscriberBy(callInfo.SourcePhoneNumber); ISubscriber targetSubscriber = _billingSystem.GetSubscriberBy(callInfo.TargetPhoneNumber); CallController.CallCommit(callInfo, _billingSystem); subscriber.Port.CallResponce($"{targetSubscriber.FullName} droped the call..."); }
private void Port_OnReject(CallInfo callInfo) { ISubscriber subscriber = _billingSystem.GetSubscriberBy(callInfo.SourcePhoneNumber); ISubscriber targetSubscriber = _billingSystem.GetSubscriberBy(callInfo.TargetPhoneNumber); subscriber.Port.CallResponce($"{subscriber.FullName}: call rejected with {targetSubscriber.FullName}"); targetSubscriber.Port.CallResponce($"{targetSubscriber.FullName}: call rejected with {subscriber.FullName}"); CallController.CallCommit(callInfo, _billingSystem); }
public void GivenACallConnectRequest_WhenAPhoneNumberIsNotPresent_ThenDialsToClientSupportAgent() { var controller = new CallController(); var result = controller.Connect(null); result.ExecuteResult(MockControllerContext.Object); var document = LoadXml(Result.ToString()); Assert.That(document.SelectSingleNode("Response/Dial/Client").InnerText, Is.EqualTo("support_agent")); }
private void Disconnect() { CallController?.Disconnect(); CallController = null; PipScreenRenderer?.Release(); PipScreenRenderer = null; FullScreenRenderer?.Release(); FullScreenRenderer = null; CallPageActivity?.Finish(); }
public void Incoming_RespondsWithWelcomeMessage() { var controller = new CallController(); controller.WithCallTo(c => c.Incoming()) .ShouldReturnTwiMLResult(data => { StringAssert.Contains( "For Programmable SMS", data.XPathSelectElement("Response/Gather/Say").Value); }); }
public bool OnToggleMic() { if (CallController == null) { return(IsMicEnabled); } IsMicEnabled = !IsMicEnabled; CallController.SetAudioEnabled(IsMicEnabled); return(IsMicEnabled); }
public void Enqueue_EnqueuesTheSelectedProduct(string digits, string selectedProduct) { var controller = new CallController(); controller.WithCallTo(c => c.Enqueue(digits)) .ShouldReturnTwiMLResult(data => { StringAssert.Contains( selectedProduct, data.XPathSelectElement("Response/Enqueue").Value); }); }
public void ShouldRespondUnauthorizedOnInvalidRequest() { _mockValidatorService .Setup(service => service.IsValidRequest(It.IsAny <HttpContext>(), It.IsAny <string>())) .Returns(false); var controller = new CallController(_mockValidatorService.Object); controller .WithCallTo(c => c.Connect("sales-number")) .ShouldGiveHttpStatus(HttpStatusCode.Unauthorized); }
public async void ReadyToStart() { var permission = await Permissions.RequestAsync <Permissions.Camera>(); if (permission == PermissionStatus.Granted) { CallController.StartVideoCall(LocalVideoRenderer, RemoteVideoRenderer); } else { Toast.MakeText(CallPageActivity, "No Video permission was granted.", ToastLength.Long).Show(); } }
static void Main(string[] args) { LogManager.Configuration ??= new NLog.Config.LoggingConfiguration(); var tcpProvider = new TcpProvider(NetworkSocket.Create); var udpProvider = new UdpProvider(NetworkSocket.Create); var watcher = new ActivityWatcher(tcpProvider) { Interval = 15000, }; // TODO Impl udp transport layer. var provider = new AudioProvider(udpProvider); var calls = new CallController(new KeyContainer(), () => new BridgeRouter(provider)); var authorization = new AuthorizationController(); var core = new CoreApi(tcpProvider, new MessageFactory(true)); new AuthApi(core, authorization); new TextApi(core, authorization); new CallApi(core, authorization, calls); // TODO Impl ping message. //watcher.Start(); // TODO Add network interfaces. _ = tcpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010)); _ = udpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010)); Console.WriteLine("Press key:\r\n S - stop\r\n Q - exit"); while (true) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.Q: return; case ConsoleKey.S: tcpProvider.Stop(); udpProvider.Stop(); break; default: break; } } }
/// <summary> /// btnMButton8のクリックイベント(更新処理) /// </summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleScreen_btnMButton8_Click(FxEventArgs fxEventArgs) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "Update", this.ddlDap.SelectedValue + "%" + this.ddlMode1.SelectedValue + "%" + this.ddlMode2.SelectedValue + "%" + this.ddlExRollback.SelectedValue, this.UserInfo); // 情報の設定 testParameterValue.ShipperID = int.Parse(this.TextBox1.Text); testParameterValue.CompanyName = this.TextBox2.Text; testParameterValue.Phone = this.TextBox3.Text; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品 CallController cctrl = new CallController(this.UserInfo); // Invoke testReturnValue = (TestReturnValue)cctrl.Invoke( this.ddlCmctCtrl.SelectedValue, testParameterValue); // 結果表示するメッセージ エリア Label label = (Label)this.GetMasterWebControl("Label1"); label.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) label.Text = testReturnValue.Obj.ToString() + "件更新"; } // 画面遷移しないポストバックの場合は、urlを空文字列に設定する return(""); }
/// <summary> /// btnMButton5のクリックイベント(一覧取得(動的sql)) /// </summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleScreen_btnMButton5_Click(FxEventArgs fxEventArgs) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "SelectAll_DSQL", this.ddlDap.SelectedValue + "%" + this.ddlMode1.SelectedValue + "%" + this.ddlMode2.SelectedValue + "%" + this.ddlExRollback.SelectedValue, this.UserInfo); // 動的SQLの要素を設定 testParameterValue.OrderColumn = this.ddlOrderColumn.SelectedValue; testParameterValue.OrderSequence = this.ddlOrderSequence.SelectedValue; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品 CallController cctrl = new CallController(this.UserInfo); // Invoke testReturnValue = (TestReturnValue)cctrl.Invoke( this.ddlCmctCtrl.SelectedValue, testParameterValue); // 結果表示するメッセージ エリア Label label = (Label)this.GetMasterWebControl("Label1"); label.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) this.GridView1.DataSource = testReturnValue.Obj; this.GridView1.DataBind(); } // 画面遷移しないポストバックの場合は、urlを空文字列に設定する return(""); }
public async void Get_Not_Exists() { CallControllerMockFacade mock = new CallControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCallServerResponseModel>(null)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public void ShouldRespondWithTwiMLOnValidRequest() { _mockValidatorService .Setup(service => service.IsValidRequest(It.IsAny <HttpContext>(), It.IsAny <string>())) .Returns(true); var controller = new CallController(_mockValidatorService.Object); controller .WithCallTo(c => c.Connect("sales-number")) .ShouldReturnTwiMLResult(data => { StringAssert.Contains( "Thanks for contacting", data.XPathSelectElement("Response/Say").Value); Assert.That(data.XPathSelectElement("Response/Dial").Value, Is.EqualTo("sales-number")); }); }
public void GivenACallConnectRequest_WhenAPhoneNumberIsPresent_ThenDialsToThatPhoneNumber() { var mockCredentials = new Mock <ICredentials>(); const string twilioPhoneNumber = "+13035550142"; mockCredentials.Setup(c => c.PhoneNumber).Returns(twilioPhoneNumber); var controller = new CallController(mockCredentials.Object); const string phoneNumber = "+12025550165"; var result = controller.Connect(phoneNumber); result.ExecuteResult(MockControllerContext.Object); var document = LoadXml(Result.ToString()); Assert.That(document.SelectSingleNode("Response/Dial").Attributes["callerId"].Value, Is.EqualTo(twilioPhoneNumber)); Assert.That(document.SelectSingleNode("Response/Dial/Number").InnerText, Is.EqualTo(phoneNumber)); }
public async void Delete_Errors() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
/// <summary> /// btnMButton1のClickイベント(件数取得) /// </summary> /// <param name="fxEventArgs">Event Handlerの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleScreen_btnMButton1_Click(FxEventArgs fxEventArgs) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "SelectCount", this.ddlDap.SelectedValue + "%" + this.ddlMode1.SelectedValue + "%" + this.ddlMode2.SelectedValue + "%" + this.ddlExRollback.SelectedValue, this.UserInfo); // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品 CallController cctrl = new CallController(this.UserInfo); // Invoke testReturnValue = (TestReturnValue)cctrl.Invoke( this.ddlCmctCtrl.SelectedValue, testParameterValue); // 結果表示するMessage エリア Label label = (Label)this.GetMasterWebControl("Label1"); label.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) label.Text = testReturnValue.Obj.ToString() + "件のデータがあります"; } // 画面遷移しないPost Backの場合は、urlを空文字列に設定する return(""); }
public async void Update_NotFound() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiCallServerResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCallServerRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiCallServerResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCallServerResponseModel>(null)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCallServerModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Update(default(int), new ApiCallServerRequestModel()); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void All_Not_Exists() { CallControllerMockFacade mock = new CallControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult <List <ApiCallServerResponseModel> >(new List <ApiCallServerResponseModel>())); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCallServerResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public async void SaveCall_Should_Return_Bad_Result_If_Invalid_Input() { var mediatorMock = new Mock <IMediator>(); var loggerMock = new Mock <ILogger>(); mediatorMock .Setup(x => x.Send(It.IsAny <CreateCallCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new CommandResult <bool>() { Type = CommandResultTypeEnum.InvalidInput }); var controller = new CallController( loggerMock.Object, mediatorMock.Object ); var response = await controller.SaveCall(new Call()); Assert.IsType <BadRequestResult>(response.Result); }
public async void GetCallMetrics_Should_Return_Not_Found_Result_If_Data_Not_Found() { var mediatorMock = new Mock <IMediator>(); var loggerMock = new Mock <ILogger>(); mediatorMock .Setup(x => x.Send(It.IsAny <GetCallMetricsByPeriodSelectionQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new QueryResult <CallMetrics>() { Type = QueryResultTypeEnum.NotFound }); var controller = new CallController( loggerMock.Object, mediatorMock.Object ); var response = await controller.GetCallMetrics(PeriodSelectionEnum.AllTime); Assert.IsType <NotFoundResult>(response.Result); }
public async void GetCallMetrics_Should_Return_Ok_Result() { var mediatorMock = new Mock <IMediator>(); var loggerMock = new Mock <ILogger>(); mediatorMock .Setup(x => x.Send(It.IsAny <GetCallMetricsByPeriodSelectionQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new QueryResult <CallMetrics>() { Type = QueryResultTypeEnum.Success }); var controller = new CallController( loggerMock.Object, mediatorMock.Object ); var response = await controller.GetCallMetrics(PeriodSelectionEnum.AllTime); Assert.IsType <OkObjectResult>(response.Result); mediatorMock.Verify(x => x.Send(It.IsAny <GetCallMetricsByPeriodSelectionQuery>(), It.IsAny <CancellationToken>()), Times.Once()); }
public async void SaveCall_Should_Return_Ok_Result() { var mediatorMock = new Mock <IMediator>(); var loggerMock = new Mock <ILogger>(); mediatorMock .Setup(x => x.Send(It.IsAny <CreateCallCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new CommandResult <bool>() { Type = CommandResultTypeEnum.Success }); var controller = new CallController( loggerMock.Object, mediatorMock.Object ); var response = await controller.SaveCall(new Call()); Assert.IsType <OkObjectResult>(response.Result); mediatorMock.Verify(x => x.Send(It.IsAny <CreateCallCommand>(), It.IsAny <CancellationToken>()), Times.Once()); }
public async void Patch_Record_Not_Found() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCallServerResponseModel>(null)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiCallServerRequestModel>(); patch.Replace(x => x.AddressId, 1); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void BulkInsert_Errors() { CallControllerMockFacade mock = new CallControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCallServerResponseModel> >(null as ApiCallServerResponseModel); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCallServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCallServerResponseModel> >(mockResponse.Object)); CallController controller = new CallController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiCallServerRequestModel>(); records.Add(new ApiCallServerRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCallServerRequestModel>())); }
/// <summary>件数取得</summary> /// <param name="rcFxEventArgs">イベントハンドラの共通引数</param> /// <remarks> /// 非同期フレームワークを使用してB層の呼び出し処理を非同期化 /// (非同期実行、結果表示の双方に匿名デリゲードを使用するパターン) /// </remarks> protected void UOC_btnButton1_Click(RcFxEventArgs rcFxEventArgs) { // 非同期処理クラスを生成 // 匿名デリゲードの場合は、ベース2で良い。 MyBaseAsyncFunc af = new MyBaseAsyncFunc(this); // 引数を纏める af.Parameter = (object)new TestParameterValue( this.Name, rcFxEventArgs.ControlName, "SelectCount", ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%" + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%" + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%" + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value, MyBaseControllerWin.UserInfo); // 非同期実行するメソッドを指定(匿名デリゲード) // ここは副スレッドから実行されるので注意 // (画面上のメンバに触らないこと!)。 af.AsyncFunc = delegate(object param) { // 引数クラス(キャスト) TestParameterValue testParameterValue = (TestParameterValue)param; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品(スレッドセーフでないため副スレッド内で作る) CallController callCtrl = new CallController(""); // Invoke testReturnValue = (TestReturnValue)callCtrl.Invoke( "testWebService", testParameterValue); //// 進捗表示のテスト //af.ChangeProgress = delegate(object o) //{ // MessageBox.Show(o.ToString()); //}; //af.ExecChangeProgress("進捗表示"); //// 非同期メッセージボックス表示のテスト //DialogResult dr = af.ShowAsyncMessageBoxWin( // "メッセージ", "タイトル", MessageBoxButtons.YesNo, MessageBoxIcon.Information); //// 非同期メッセージボックス表示のテスト(エラー) //System.Windows.MessageBoxResult mr = af.ShowAsyncMessageBoxWPF("メッセージ", "タイトル", // System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Information); // 結果表示 return testReturnValue; }; // 結果表示のメソッドを指定(匿名デリゲード) // このメソッドは必ず主スレッドで実行される。 // (画面上のメンバを更新できる!)。 af.SetResult = delegate(object retVal) { if (retVal is Exception) { // 例外発生時 MessageBox.Show(retVal.ToString(), "非同期処理で例外発生!"); } else { // 正常時 // 戻り値(キャスト) TestReturnValue testReturnValue = (TestReturnValue)retVal; // 結果表示するメッセージ エリア this.labelMessage.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) this.labelMessage.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; this.labelMessage.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; this.labelMessage.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) this.labelMessage.Text = testReturnValue.Obj.ToString() + "件のデータがあります"; } } }; // 非同期実行する。 if (!af.Start()) { MessageBox.Show("別の非同期処理が実行中です。"); } }
/// <summary> /// btnMButton5のクリックイベント(一覧取得(動的sql)) /// </summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleScreen_btnMButton5_Click(FxEventArgs fxEventArgs) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "SelectAll_DSQL", this.ddlDap.SelectedValue + "%" + this.ddlMode1.SelectedValue + "%" + this.ddlMode2.SelectedValue + "%" + this.ddlExRollback.SelectedValue, this.UserInfo); // 動的SQLの要素を設定 testParameterValue.OrderColumn = this.ddlOrderColumn.SelectedValue; testParameterValue.OrderSequence = this.ddlOrderSequence.SelectedValue; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品 CallController cctrl = new CallController(this.UserInfo); // Invoke testReturnValue = (TestReturnValue)cctrl.Invoke( this.ddlCmctCtrl.SelectedValue, testParameterValue); // 結果表示するメッセージ エリア Label label = (Label)this.GetMasterWebControl("Label1"); label.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) this.GridView1.DataSource = testReturnValue.Obj; this.GridView1.DataBind(); } // 画面遷移しないポストバックの場合は、urlを空文字列に設定する return ""; }
/// <summary> /// btnMButton1のクリックイベント(件数取得) /// </summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleScreen_btnMButton1_Click(FxEventArgs fxEventArgs) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "SelectCount", this.ddlDap.SelectedValue + "%" + this.ddlMode1.SelectedValue + "%" + this.ddlMode2.SelectedValue + "%" + this.ddlExRollback.SelectedValue, this.UserInfo); // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品 CallController cctrl = new CallController(this.UserInfo); // Invoke testReturnValue = (TestReturnValue)cctrl.Invoke( this.ddlCmctCtrl.SelectedValue, testParameterValue); // 結果表示するメッセージ エリア Label label = (Label)this.GetMasterWebControl("Label1"); label.Text = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n"; label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n"; label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n"; } else { // 結果(正常系) label.Text = testReturnValue.Obj.ToString() + "件のデータがあります"; } // 画面遷移しないポストバックの場合は、urlを空文字列に設定する return ""; }
/// <summary>ロード イベント</summary> private void Window_Loaded(object sender, RoutedEventArgs e) { // ddlDap this.ddlDap.Items.Add(new ComboBoxItem("SQL Server / SQL Client", "SQL")); this.ddlDap.Items.Add(new ComboBoxItem("Multi-DB / OLEDB.NET", "OLE")); this.ddlDap.Items.Add(new ComboBoxItem("Multi-DB / ODCB.NET", "ODB")); this.ddlDap.Items.Add(new ComboBoxItem("Oracle / ODP.NET", "ODP")); this.ddlDap.Items.Add(new ComboBoxItem("DB2 / DB2.NET", "DB2")); this.ddlDap.Items.Add(new ComboBoxItem("HiRDB / HiRDB-DP", "HIR")); this.ddlDap.Items.Add(new ComboBoxItem("MySQL Cnn/NET", "MCN")); this.ddlDap.Items.Add(new ComboBoxItem("PostgreSQL / Npgsql", "NPS")); this.ddlDap.SelectedIndex = 0; // ddlMode1 this.ddlMode1.Items.Add(new ComboBoxItem("個別Dao", "individual")); this.ddlMode1.Items.Add(new ComboBoxItem("共通Dao", "common")); this.ddlMode1.Items.Add(new ComboBoxItem("自動生成Dao(更新のみ)", "generate")); this.ddlMode1.SelectedIndex = 0; // ddlMode2 this.ddlMode2.Items.Add(new ComboBoxItem("静的クエリ", "static")); this.ddlMode2.Items.Add(new ComboBoxItem("動的クエリ", "dynamic")); this.ddlMode2.SelectedIndex = 0; // ddlIso this.ddlIso.Items.Add(new ComboBoxItem("ノットコネクト", "NC")); this.ddlIso.Items.Add(new ComboBoxItem("ノートランザクション", "NT")); this.ddlIso.Items.Add(new ComboBoxItem("ダーティリード", "RU")); this.ddlIso.Items.Add(new ComboBoxItem("リードコミット", "RC")); this.ddlIso.Items.Add(new ComboBoxItem("リピータブルリード", "RR")); this.ddlIso.Items.Add(new ComboBoxItem("シリアライザブル", "SZ")); this.ddlIso.Items.Add(new ComboBoxItem("スナップショット", "SS")); this.ddlIso.Items.Add(new ComboBoxItem("デフォルト", "DF")); this.ddlIso.SelectedIndex = 1; // WSでは使用しない(設定できないので)。 this.ddlIso.IsEnabled = false; // ddlExRollback this.ddlExRollback.Items.Add(new ComboBoxItem("正常時", "-")); this.ddlExRollback.Items.Add(new ComboBoxItem("業務例外", "Business")); this.ddlExRollback.Items.Add(new ComboBoxItem("システム例外", "System")); this.ddlExRollback.Items.Add(new ComboBoxItem("その他、一般的な例外", "Other")); this.ddlExRollback.Items.Add(new ComboBoxItem("業務例外への振替", "Other-Business")); this.ddlExRollback.Items.Add(new ComboBoxItem("システム例外への振替", "Other-System")); this.ddlExRollback.SelectedIndex = 0; // ddlTransmission this.ddlTransmission.Items.Add(new ComboBoxItem("Webサービス呼出", "testWebService")); this.ddlTransmission.Items.Add(new ComboBoxItem("インプロセス呼出", "testInProcess")); this.ddlTransmission.SelectedIndex = 0; // ddlOrderColumn this.ddlOrderColumn.Items.Add(new ComboBoxItem("c1", "c1")); this.ddlOrderColumn.Items.Add(new ComboBoxItem("c2", "c2")); this.ddlOrderColumn.Items.Add(new ComboBoxItem("c3", "c3")); this.ddlOrderColumn.SelectedIndex = 0; // ddlOrderSequence this.ddlOrderSequence.Items.Add(new ComboBoxItem("ASC", "A")); this.ddlOrderSequence.Items.Add(new ComboBoxItem("DESC", "D")); this.ddlOrderSequence.SelectedIndex = 0; // ユーザ情報 this.myUserInfo = new MyUserInfo("userName", Environment.MachineName); // 呼出し制御部品 this.CallCtrl = new CallController(""); // スレッドプール ThreadPool.SetMinThreads(10, 10); // 待機状態スレッド数 ThreadPool.SetMaxThreads(10, 10); // 最大スレッド起動数 }
/// <summary> /// Maintains the single worker thread functionalities. /// </summary> /// <param name="asyncTask">Selected Asynchronous Task</param> private void WorkerThreadCallBack(object asyncTask) { AsyncProcessingServiceReturnValue selectedAsyncTask = (AsyncProcessingServiceReturnValue)asyncTask; // A new worker thread started an Async task this._workerThreadCount++; try { // To handle unstable "Register" state, when you invoke [Abort] at this state if (selectedAsyncTask.CommandId == (int)AsyncProcessingServiceParameterValue.AsyncCommand.Abort) { throw new BusinessSystemException("APSAbortCommand", GetMessage.GetMessageDescription("CTE0004")); } // Call User Program to execute by using communication control function AsyncProcessingServiceParameterValue asyncParameterValue = new AsyncProcessingServiceParameterValue("AsyncProcessingService", "StartCopyFromBlob", "StartCopyFromBlob", "SQL", new MyUserInfo(selectedAsyncTask.UserId, selectedAsyncTask.TaskId.ToString())); asyncParameterValue.TaskId = selectedAsyncTask.TaskId; asyncParameterValue.Data = selectedAsyncTask.Data; CallController callController = new CallController(asyncParameterValue.User); AsyncProcessingServiceReturnValue asyncReturnValue = (AsyncProcessingServiceReturnValue)callController.Invoke(selectedAsyncTask.ProcessName, asyncParameterValue); if (asyncReturnValue.ErrorFlag == true) { if (asyncReturnValue.ErrorMessageID == "APSStopCommand") { string exceptionInfo = "ErrorMessageID: " + asyncReturnValue.ErrorMessageID + Environment.NewLine + "ErrorMessage: " + asyncReturnValue.ErrorMessage; // Asynchronous task is stopped due to user 'stop' command. this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.RETRY, exceptionInfo); LogIF.ErrorLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("E0001") + asyncReturnValue.ErrorMessage, selectedAsyncTask.TaskId)); } else { // Exception occurred by other than BusinessApplicationException if (selectedAsyncTask.NumberOfRetries < this._maxNumberOfRetries) { // Asynchronous task does not exceeds the maximum number of retries // Updated as retry later string exceptionInfo = "ErrorMessageID: " + asyncReturnValue.ErrorMessageID + Environment.NewLine + "ErrorMessage: " + asyncReturnValue.ErrorMessage; selectedAsyncTask.NumberOfRetries += 1; this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.RETRY, exceptionInfo); LogIF.ErrorLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("E0004"), selectedAsyncTask.TaskId)); } else { // Asynchronous task exceeds maximum number of retries // Update task as abort string exceptionInfo = "ErrorMessageID: " + asyncReturnValue.ErrorMessageID + Environment.NewLine + "ErrorMessage: " + asyncReturnValue.ErrorMessage; this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.FAIL, exceptionInfo); LogIF.ErrorLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("E0005"), selectedAsyncTask.TaskId)); } } } else { // Selected Asynchronous task is completed successfully. this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.SUCCESS); LogIF.InfoLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("I0003"), selectedAsyncTask.TaskId)); } } catch (BusinessSystemException ex) { // Asynchronous task is aborted due to BusinessSystemException sent by user program. string exceptionInfo = "ErrorMessageID: " + ex.messageID + Environment.NewLine + "ErrorMessage: " + ex.Message; this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.FAIL, exceptionInfo); LogIF.ErrorLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("E0006"), selectedAsyncTask.TaskId, ex.Message)); } catch (Exception ex) { // Asynchronous task is aborted due to unexpected exception. string exceptionInfo = "ErrorMessageID: " + ex.GetType().Name + Environment.NewLine + "ErrorMessage: " + ex.Message; this.UpdateAsyncTask(selectedAsyncTask, AsyncTaskUpdate.FAIL, exceptionInfo); LogIF.ErrorLog("ASYNC-SERVICE", string.Format(GetMessage.GetMessageDescription("E0006"), selectedAsyncTask.TaskId, ex.Message)); } finally { // Async task is over this._workerThreadCount--; } }
/// <summary>非同期</summary> /// <param name="param">引数</param> /// <returns>結果</returns> /// <remarks> /// ここは副スレッドから実行されるので注意。 /// 非同期処理クラスに非同期処理を定義すると、 /// メンバ変数を引数として利用できる。 /// </remarks> public object btn6_Exec(object param) { // 戻り値(キャスト) TestParameterValue testParameterValue = (TestParameterValue)param; // 戻り値 TestReturnValue testReturnValue; // 呼出し制御部品(スレッドセーフでないため副スレッド内で作る) CallController callCtrl = new CallController(""); // Invoke testReturnValue = (TestReturnValue)callCtrl.Invoke( "testWebService", testParameterValue); //// 進捗表示のテスト //this.ChangeProgress = delegate(object o) //{ // MessageBox.Show(o.ToString()); //}; //this.ExecChangeProgress("進捗表示"); //// 非同期メッセージボックス表示のテスト //MessageBoxResult mr = this.ShowAsyncMessageBoxWPF( // "メッセージ", "タイトル", MessageBoxButton.YesNo, MessageBoxImage.Information); //// 非同期メッセージボックス表示のテスト(エラー) //System.Windows.Forms.DialogResult dr = this.ShowAsyncMessageBoxWin("メッセージ", "タイトル", // System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information); // 結果表示 return testReturnValue; }
/// <summary> /// フォームロードのUOCメソッド /// </summary> protected override void UOC_FormInit() { // フォーム初期化(初回ロード)時に実行する処理を実装する // TODO: MyBaseControllerWin.CanOutPutLog = false; // ddlDap this.ddlDap.Items.Add(new ComboBoxItem("SQL Server / SQL Client", "SQL")); this.ddlDap.Items.Add(new ComboBoxItem("Multi-DB / OLEDB.NET", "OLE")); this.ddlDap.Items.Add(new ComboBoxItem("Multi-DB / ODCB.NET", "ODB")); this.ddlDap.Items.Add(new ComboBoxItem("Oracle / ODP.NET", "ODP")); this.ddlDap.Items.Add(new ComboBoxItem("DB2 / DB2.NET", "DB2")); this.ddlDap.Items.Add(new ComboBoxItem("HiRDB / HiRDB-DP", "HIR")); this.ddlDap.Items.Add(new ComboBoxItem("MySQL Cnn/NET", "MCN")); this.ddlDap.Items.Add(new ComboBoxItem("PostgreSQL / Npgsql", "NPS")); this.ddlDap.SelectedIndex = 0; // ddlMode1 this.ddlMode1.Items.Add(new ComboBoxItem("個別Dao", "individual")); this.ddlMode1.Items.Add(new ComboBoxItem("共通Dao", "common")); this.ddlMode1.Items.Add(new ComboBoxItem("自動生成Dao(更新のみ)", "generate")); this.ddlMode1.SelectedIndex = 0; // ddlMode2 this.ddlMode2.Items.Add(new ComboBoxItem("静的クエリ", "static")); this.ddlMode2.Items.Add(new ComboBoxItem("動的クエリ", "dynamic")); this.ddlMode2.SelectedIndex = 0; // ddlIso this.ddlIso.Items.Add(new ComboBoxItem("ノットコネクト", "NC")); this.ddlIso.Items.Add(new ComboBoxItem("ノートランザクション", "NT")); this.ddlIso.Items.Add(new ComboBoxItem("ダーティリード", "RU")); this.ddlIso.Items.Add(new ComboBoxItem("リードコミット", "RC")); this.ddlIso.Items.Add(new ComboBoxItem("リピータブルリード", "RR")); this.ddlIso.Items.Add(new ComboBoxItem("シリアライザブル", "SZ")); this.ddlIso.Items.Add(new ComboBoxItem("スナップショット", "SS")); this.ddlIso.Items.Add(new ComboBoxItem("デフォルト", "DF")); this.ddlIso.SelectedIndex = 1; // WSでは使用しない(設定できないので)。 this.ddlIso.Enabled = false; // ddlExRollback this.ddlExRollback.Items.Add(new ComboBoxItem("正常時", "-")); this.ddlExRollback.Items.Add(new ComboBoxItem("業務例外", "Business")); this.ddlExRollback.Items.Add(new ComboBoxItem("システム例外", "System")); this.ddlExRollback.Items.Add(new ComboBoxItem("その他、一般的な例外", "Other")); this.ddlExRollback.Items.Add(new ComboBoxItem("業務例外への振替", "Other-Business")); this.ddlExRollback.Items.Add(new ComboBoxItem("システム例外への振替", "Other-System")); this.ddlExRollback.SelectedIndex = 0; // ddlOrderColumn this.ddlOrderColumn.Items.Add(new ComboBoxItem("c1", "c1")); this.ddlOrderColumn.Items.Add(new ComboBoxItem("c2", "c2")); this.ddlOrderColumn.Items.Add(new ComboBoxItem("c3", "c3")); this.ddlOrderColumn.SelectedIndex = 0; // ddlOrderSequence this.ddlOrderSequence.Items.Add(new ComboBoxItem("ASC", "A")); this.ddlOrderSequence.Items.Add(new ComboBoxItem("DESC", "D")); this.ddlOrderSequence.SelectedIndex = 0; // 呼出し制御部品 this.CallCtrl = new CallController(""); }