public ActivateShould() { mobileRepositoryMock = new Mock <IRepository <Mobile> >(); dateTimeCreatorMock = new Mock <IDateTimeCreator>(); loggerMock = new Mock <ILogger <MobilesService> >(); guidCreatorMock = new Mock <IGuidCreator>(); getNextMobileIdQueryMock = new Mock <IGetNextMobileIdQuery>(); expectedMobileGlobalId = Guid.NewGuid(); expectedNewOrderGlobalId = Guid.NewGuid(); expectedActivateRequest = new ActivateRequest { ActivationCode = "ACT001" }; expectedMobile = new Mobile(dateTimeCreatorMock.Object, new MobileDataEntity { GlobalId = expectedMobileGlobalId, State = Mobile.MobileState.WaitingForActivate.ToString() }); guidCreatorMock.Setup(x => x.Create()).Returns(expectedNewOrderGlobalId); mobileRepositoryMock.Setup(x => x.GetById(expectedMobileGlobalId)) .Returns(expectedMobile); sut = new MobilesService(loggerMock.Object, mobileRepositoryMock.Object, guidCreatorMock.Object, getNextMobileIdQueryMock.Object); }
public Mobile Activate(Guid id, ActivateRequest activateRequest) { var mobile = this.mobileRepository.GetById(id); if (mobile == null) { logger.LogWarning("Attempt to Activate an unknown Mobile - MobileId: {MobileId}", id); return(null); } var newStateName = Order.State.New.ToString(); var orderType = Order.OrderType.Activate.ToString(); var dataEntity = new OrderDataEntity() { GlobalId = this.guidCreator.Create(), ActivationCode = activateRequest.ActivationCode, State = newStateName, Type = orderType }; var inProgressOrder = new Order(dataEntity); mobile.Activate(inProgressOrder); mobileRepository.Update(mobile); return(mobile); }
public Response GetResponse(ActivateRequest activateRequest) { string response = ""; Dictionary <string, string> responseMap = doRequest(GetURL(), "POST", Serializer <ActivateRequest> .Serialize(activateRequest).InnerXml); responseMap.TryGetValue(MESSAGE, out response); return(Serializer <Response> .Deserialize(response)); }
public void TestService() { activateRequest = new ActivateRequest(); activateRequest.Pan = 5112345678901255; activateRequest.SecureElementId = "10000000000000061001000333c0000237a5a89708b18e45"; activateRequest.AuditInfo.UserId = "testUser"; activateRequest.AuditInfo.UserName = "******"; activateRequest.AuditInfo.Organization = "Test Org"; response = service.GetResponse(activateRequest); Assert.IsNotNull(response.statusCode); }
public void ReturnNotFound() { var notFoundGlobalId = Guid.NewGuid(); var activateRequest = new ActivateRequest(); mobilesServiceMock.Setup(x => x.Activate(notFoundGlobalId, activateRequest)) .Returns(null as Mobile); var actual = sut.Activate(notFoundGlobalId, activateRequest); actual.Should().BeOfType <NotFoundResult>(); }
public ActionResult <ActivateResponse> Post([FromBody] ActivateRequest request) { try { ActivateResponse activateResponse = ConnectionService.activateConnection(request); return(activateResponse); } catch (Exception ex) { Console.WriteLine($"Failed to process activate request, message - {ex.Message}"); return(StatusCode(500)); } }
public async Task Activate(ActivateRequest request) { var json = JsonConvert.SerializeObject(request); using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json")) { try { HttpResponseMessage response = await httpClient.PostAsync($"{DecisionApiUrl}/v2/activate", stringContent); response.EnsureSuccessStatusCode(); } catch (HttpRequestException e) { exceptionHandler.Handle(e); } } }
public ActivateShould() { mobilesServiceMock = new Mock <IMobilesService>(); var dateTimeCreatorMock = new Mock <IDateTimeCreator>(); expectedMobileGlobalId = Guid.NewGuid(); expectedOrderGlobalId = Guid.NewGuid(); expectedActivateRequest = new ActivateRequest { ActivationCode = "BAS132" }; expectedOrderDataEntity = new OrderDataEntity { GlobalId = expectedOrderGlobalId, Type = Order.OrderType.Activate.ToString(), State = Order.State.New.ToString(), ActivationCode = expectedActivateRequest.ActivationCode, Name = "Neil Armstrong", ContactPhoneNumber = "0700123456", CreatedAt = new DateTime(2001, 5, 4), UpdatedAt = new DateTime(2002, 6, 5) }; expectedMobile = new Mobile(dateTimeCreatorMock.Object, new MobileDataEntity { State = MobileState.ProcessingActivate.ToString(), Orders = new List <OrderDataEntity> { expectedOrderDataEntity } }); mobileRepositoryMock = new Mock <IRepository <Mobile> >(); monitoringMock = new Mock <IMonitoring>(); mobileRepositoryMock.Setup(x => x.GetById(expectedMobileGlobalId)) .Returns(expectedMobile); mobilesServiceMock.Setup(x => x.Activate(expectedMobileGlobalId, expectedActivateRequest)) .Returns(expectedMobile); sut = new MobilesController(mobilesServiceMock.Object, mobileRepositoryMock.Object, monitoringMock.Object); }
/// <summary> /// Called when client needs to activate a session. /// </summary> /// <param name="request"></param> /// <returns></returns> public ActivateResponse Post(ActivateRequest request) { ActivateResponse response = null; new ActivateSessionStrategy( activateResponse => response = activateResponse ) .Execute(); if (response == null) { throw new InvalidOperationException( "Response is null" ); } return(response); }
public static ActivateResponse activateConnection(ActivateRequest activateRequest) { Console.WriteLine("Activate request received: ", activateRequest.ToString()); /********************************************/ /* TODO - Perisist activation request. */ /********************************************/ ActivateResponse activateResponse = new ActivateResponse(); List <ActionLink> links = new List <ActionLink>(); ActionLink link = new ActionLink(); link.href = "https://example.com/deactivate"; link.rel = "deactivate"; link.method = "POST"; link.title = "title"; links.Add(link); activateResponse.links = links; return(activateResponse); }
public IActionResult Activate(Guid id, [FromBody] ActivateRequest activateRequest) { var mobile = mobilesService.Activate(id, activateRequest); if (mobile == null) { return(NotFound()); } monitoring.Activate(); var newOrder = mobile.InProgressOrder; return(new OkObjectResult(new OrderResource { GlobalId = newOrder.GlobalId, Name = newOrder.Name, ContactPhoneNumber = newOrder.ContactPhoneNumber, State = newOrder.CurrentState.ToString(), Type = newOrder.Type.ToString(), CreatedAt = newOrder.CreatedAt, UpdatedAt = newOrder.UpdatedAt })); }
protected void OnActivateRequest() => ActivateRequest?.Invoke(this, EventArgs.Empty);
public async Task <IActionResult> ActivateAccount([FromBody] ActivateRequest request) { var result = await _mediator.Send(request); return(Ok(result)); }