public void Run() { ConsoleKey?key = null; WriteWelcomeMessage(); do { if (key == ConsoleKey.C) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Sending Create Application Command"); Console.ResetColor(); var command = new CreateApplicationCommand() { ApplicationId = Guid.NewGuid(), FirstName = "foo", LastName = "bar", TTL = DateTime.Now.AddSeconds(5) }; _bus.Send(command); } key = Console.ReadKey().Key; Console.WriteLine(); } while (key != ConsoleKey.Q); }
public async Task <ActionResult <Application> > Create(ApplicationDto applicationDto) { var request = new CreateApplicationCommand(applicationDto); var response = await _mediator.Send(request); return(Ok(response)); }
public void SetUp() { _getAccountResponse = _fixture.Create <GetAccountResponse>(); _command = _fixture.Create <CreateApplicationCommand>(); _response = _fixture.Create <CreateApplicationResponse>(); _getStandardResponse = _fixture.Create <GetStandardsListItem>(); _account = _fixture.Create <Account>(); _accountsService = new Mock <IAccountsService>(); _accountsService.Setup(x => x.GetAccount(_command.EncodedAccountId)).ReturnsAsync(_account); _coursesApiClient = new Mock <ICoursesApiClient <CoursesApiConfiguration> >(); _coursesApiClient.Setup(x => x.Get <GetStandardsListItem>(It.Is <GetStandardDetailsByIdRequest>(r => r.Id == _command.StandardId))) .ReturnsAsync(_getStandardResponse); _levyTransferMatchingService = new Mock <ILevyTransferMatchingService>(); _levyTransferMatchingService.Setup(x => x.GetAccount(It.Is <GetAccountRequest>(r => r.AccountId == _command.EmployerAccountId))) .ReturnsAsync(_getAccountResponse); _levyTransferMatchingService.Setup(x => x.CreateApplication(It.IsAny <CreateApplicationRequest>())) .Callback <CreateApplicationRequest>(r => _createApplicationRequest = r) .ReturnsAsync(_response); _handler = new CreateApplicationCommandHandler(_levyTransferMatchingService.Object, _accountsService.Object, Mock.Of <ILogger <CreateApplicationCommandHandler> >(), _coursesApiClient.Object); }
public void ValidateFail() { var command = new CreateApplicationCommand(applicationDescription: "", applicationName: ""); Assert.AreEqual(false, command.Validate()); }
public void ValidateOk() { var command = new CreateApplicationCommand(applicationDescription: "Aplicação de teste", applicationName: "Aplicaçao"); Assert.AreEqual(true, command.Validate()); }
private ICommand CreateCommandChain(DeploymentItem item) { var itemContext = CreateContext(item); ICommand command; if (item.RemoveApplicationFirst) { var command6 = new UpgradeApplicationCommand(itemContext); var command5 = new CreateApplicationCommand(itemContext); var command4 = new ApplicationDeploymentCommand(itemContext, command5, command6); var command3 = new CreateApplicationTypeCommand(itemContext, command4); var command2 = new CopyImageToStoreCommand(itemContext, command3); command = new RemoveApplicationTypeCommand(itemContext, command2); } else { var command5 = new UpgradeApplicationCommand(itemContext); var command4 = new CreateApplicationCommand(itemContext); var command3 = new ApplicationDeploymentCommand(itemContext, command4, command5); var command2 = new CreateApplicationTypeCommand(itemContext, command3); command = new CopyImageToStoreCommand(itemContext, command2); } return(command); }
public async Task <IActionResult> Create(EApplicationDto eApplicationDto) { var createApplicationCommand = new CreateApplicationCommand(eApplicationDto); var response = await _mediator.Send(createApplicationCommand); return(Ok(response)); }
public async Task <IActionResult> Create(ApplicationDto applicationDto) { var createApplicationCommand = new CreateApplicationCommand(applicationDto); var response = await _mediator.Send(createApplicationCommand); return(response.StatusCode == HttpStatusCode.NotFound ? (IActionResult)NotFound(response) : Ok(response)); }
public void ValidateOk() { var command = new CreateApplicationCommand(applicationDescription: "Descrição aplicação", applicationName: "Aplicação"); var handle = new CreateApplicationHandler(_repository); var result = (CommandResult)handle.Handle(command); Assert.AreEqual(true, result.Ok); }
public void ValidateFail() { var command = new CreateApplicationCommand(applicationDescription: "", applicationName: ""); var handle = new CreateApplicationHandler(_repository); var result = (CommandResult)handle.Handle(command); Assert.AreEqual(false, result.Ok); }
public ActionResult Register(CreateApplicationCommand createApplicationCommand) { var result = new CreateApplicationResult(); var commandResult = _commandBus.Send(createApplicationCommand); return(new JsonResult() { Data = result.Create(commandResult.Values) }); }
public async Task CreateApplicationCommandHandler_Handel_ShouldReturnUpdatedValueOfApplication() { var createApplicationModel = new CreateApplicationDto { Description = "Application to store the feedback of users" }; var createApplicationCommand = new CreateApplicationCommand(createApplicationModel); var updateApplication = await _createApplicationCommandHandler.Handle(createApplicationCommand, CancellationToken.None); Assert.True(default(Guid) != updateApplication.Id); }
public async Task CreateRoleHandler_FluentValidationHandler_ThrowsValidationException() { //Setup var command = new CreateApplicationCommand(new CreateApplicationDto()); var validator = new CreateApplicationCommandValidator(); //Action var result = await validator.ValidateAsync(command); //Assert Assert.Contains(result.Errors, o => o.ErrorMessage == "ApplicationName cannot be empty"); }
public async Task ShouldFailWithUnknownCommand() { // arrange var logger = this.GetTestLogger <CreateApplicationCommand>(); var createApplicationCommand = new CreateApplicationCommand(logger, null, new TemplateBuilder()); // act Func <Task> act = async() => await createApplicationCommand.ParseInputConfigurationAsync(new CreateConsoleAppConfiguration()); // assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task <ActionResult> Create(ApplicationViewModel model, CancellationToken cancellationToken) { if (ModelState.IsValid) { CreateApplication command = new CreateApplicationCommand(User.Identity.GetUserId(), model.OrganizationId, model.Name); UserOrganizationApplication application = await _createApplication.Execute(command, cancellationToken); return(RedirectToAction("Details", new { id = application.ApplicationId })); } return(View()); }
public async Task Then_The_CommitmentService_Is_Called_To_Get_Apprenticeship_Details( long accountId, long accountLegalEntityId, long[] apprenticeshipIds, Guid applicationId, [Frozen] Mock <ICommitmentsService> commitmentsService, CreateApplicationCommandHandler handler) { var command = new CreateApplicationCommand(applicationId, accountId, accountLegalEntityId, apprenticeshipIds); await handler.Handle(command, CancellationToken.None); commitmentsService.Verify(x => x.GetApprenticeshipDetails(command.AccountId, command.ApprenticeshipIds), Times.Once); }
public async Task ShouldFailWithInvalidAPIMServiceName() { // arrange var logger = this.GetTestLogger <CreateApplicationCommand>(); var createApplicationCommand = new CreateApplicationCommand(logger, null, new TemplateBuilder()); // act Func <Task> act = async() => await createApplicationCommand.ParseInputConfigurationAsync(new CreateConsoleAppConfiguration { ConfigFile = string.Concat(this.invalidConfigurationFolder, "invalidAPIMServiceName.yml") }); // assert await act.Should().ThrowAsync <CreatorConfigurationIsInvalidException>(); }
public async Task ShouldCreateApplication() { var command = new CreateApplicationCommand() { ApplicationName = "MyApplication" }; var guid = await new CreateApplicationCommandHandler(createApplicationService, currentUserService) .Handle(command, CancellationToken.None); var application = applicationDbContext.Applications.FirstOrDefault(x => x.Id == guid); application.Should().NotBeNull(); application.Name.Should().Be("MyApplication"); application.UserId.Should().Be(currentUserId); }
/// <summary> /// Integration event handler which starts the create Application process /// </summary> /// <param name="@event"> /// Integration event message which is sent by the /// basket.api once it has successfully process the /// Application items. /// </param> /// <returns></returns> public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event) { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); var result = false; if (@event.RequestId != Guid.Empty) { using (LogContext.PushProperty("IdentifiedCommandId", @event.RequestId)) { var createApplicationCommand = new CreateApplicationCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.IDNumber, @event.Request, @event.PaymentTypeId); var requestCreateApplication = new IdentifiedCommand <CreateApplicationCommand, bool>(createApplicationCommand, @event.RequestId); _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", requestCreateApplication.GetGenericTypeName(), nameof(requestCreateApplication.Id), requestCreateApplication.Id, requestCreateApplication); result = await _mediator.Send(requestCreateApplication); if (result) { _logger.LogInformation("----- CreateApplicationCommand suceeded - RequestId: {RequestId}", @event.RequestId); } else { _logger.LogWarning("CreateApplicationCommand failed - RequestId: {RequestId}", @event.RequestId); } } } else { _logger.LogWarning("Invalid IntegrationEvent - RequestId is missing - {@IntegrationEvent}", @event); } } }
public async Task CreateApplicationCommandHandler_Handel_ShouldThrowAnExceptionIfApplicationNameIsAlreadyExistAndIgnoreCase() { var createApplicationDto = new CreateApplicationDto { Name = "Application" }; Context.Applications.Add(new Domain.Entities.Application { Name = "appLication" }); Context.Applications.Add(new Domain.Entities.Application { Name = "Application 1" }); Context.SaveChanges(); var createApplicationCommand = new CreateApplicationCommand(createApplicationDto); await Assert.ThrowsAsync <RecordAlreadyExistsException>(() => _createApplicationCommandHandler.Handle(createApplicationCommand, CancellationToken.None)); }
public async Task CreateApplicationAsync(CreateApplicationCommand command) { if (command.ApplicationId == Guid.Empty) { throw new AggregateValidationException("Invalid application Id"); } if (command.RegistrationUser == Guid.Empty) { throw new AggregateValidationException("Invalid user Id"); } if (command.InitialTransactionId == Guid.Empty) { throw new AggregateValidationException("Invalid transaction Id"); } var application = await applicationRepository.GetAsync(command.ApplicationId); if (application != null) { throw new AggregateIllegalLogicException("Cannot create application with given id. Application exists."); } var transaction = await transactionRepository.GetAsync(command.InitialTransactionId); if (transaction == null) { throw new AggregateValidationException("Transaction with given Id not exists."); } application = new ApplicationEntity(command.ApplicationId); application.ApplyTransaction(transaction, command.RegistrationUser); await applicationRepository.CreateAsync(application); }
public async Task Then_The_EmployerIncentivesService_Is_Called_To_Create_The_Initial_Application( long accountId, long accountLegalEntityId, long[] apprenticeshipIds, Guid applicationId, ApprenticeshipResponse[] apprenticeshipDetails, [Frozen] Mock <IApplicationService> applicationService, [Frozen] Mock <ICommitmentsService> commitmentsService, CreateApplicationCommandHandler handler) { var command = new CreateApplicationCommand(applicationId, accountId, accountLegalEntityId, apprenticeshipIds); commitmentsService.Setup(x => x.GetApprenticeshipDetails(command.AccountId, command.ApprenticeshipIds)) .ReturnsAsync(apprenticeshipDetails); await handler.Handle(command, CancellationToken.None); applicationService.Verify( x => x.Create( It.Is <CreateIncentiveApplicationRequestData>(p => p.IncentiveApplicationId == command.ApplicationId && p.AccountId == command.AccountId && p.AccountLegalEntityId == command.AccountLegalEntityId && p.Apprenticeships.Length == apprenticeshipDetails.Length)), Times.Once); }
/// <summary> /// 新建Application /// </summary> /// <param name="request"></param> /// <returns></returns> public ReturnValue Create(CreateApplicationCommand command) { var result = new ReturnValue(); //初始化一个application对象 var application = initApplication(command.AppName); try { //添加到资源库之前业务规则验证 Validate(application); //检查App是否已存在 IsHasApplicationByAppName(application.AppName); _applicationRepository.Register(application); } catch (BusinessRuleException excep) { return(excep.ReturnValue); } return(result); }
public CreateApplicationCommandTests() { _appClient = new Mock <IApplicationClient>(); var fabricClient = new Mock <IServiceFabricClient>(); fabricClient.Setup(c => c.Applications).Returns(_appClient.Object); _item = new DeploymentItem { PackagePath = @"c:\temp\pkg", ApplicationTypeName = "AppType", ApplicationName = "fabric:/app", ApplicationId = "app", ApplicationTypeVersion = "1.0.0", ApplicationTypeBuildPath = "pkg" }; var context = new CommandContext { FabricClient = fabricClient.Object, Logger = Logger.Object, CurrentDeploymentItem = _item }; _command = new CreateApplicationCommand(context); }
public async Task<ActionResult> Create(ApplicationViewModel model, CancellationToken cancellationToken) { if (ModelState.IsValid) { CreateApplication command = new CreateApplicationCommand(User.Identity.GetUserId(), model.OrganizationId, model.Name); UserOrganizationApplication application = await _createApplication.Execute(command, cancellationToken); return RedirectToAction("Details", new {id = application.ApplicationId}); } return View(); }
public CommandResult CreateApplication([FromServices] CreateApplicationHandler handler , [FromBody] CreateApplicationCommand command) { return((CommandResult)handler.Handle(command)); }
public static Domain.Applications.Application ToMap(this CreateApplicationCommand command) => new Domain.Applications.Application(command.Name) { Description = command.Description, Permissions = command.Permissions.Select(p => p.ToMap()).ToList() };
public async Task RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context, [DurableClient] IDurableOrchestrationClient processStarter, ILogger log) { _correlationInitializer.Initialize(context.InstanceId); var beginProcessCommand = this.BuildBeginProcessCommand(context); await context.CallActivityAsync <Task>(nameof(StatusTracker), beginProcessCommand); var command = context.GetInput <RegisterApplicationCommand>(); var uploadCvCommand = new UploadCvCommand( command.Cv.File, command.Cv.ContentType, command.Cv.Extension); var uploadPhotoCommand = new UploadPhotoCommand( command.Photo.File, command.Photo.ContentType, command.Photo.Extension); await Task.WhenAll( context.CallActivityAsync <Task>(nameof(CvUploader), uploadCvCommand), context.CallActivityAsync <Task>(nameof(PhotoUploader), uploadPhotoCommand)); var cvUploadedEventTask = context.WaitForExternalEvent <CvUploadedInternalFunctionEvent>(nameof(CvUploadedInternalFunctionEvent)); var cvUploadFailedEventTask = context.WaitForExternalEvent <CvUploadFailedInternalFunctionEvent>(nameof(CvUploadFailedInternalFunctionEvent)); var photoUploadedEventTask = context.WaitForExternalEvent <PhotoUploadedInternalFunctionEvent>(nameof(PhotoUploadedInternalFunctionEvent)); var photoUploadFailedEventTask = context.WaitForExternalEvent <PhotoUploadFailedInternalFunctionEvent>(nameof(PhotoUploadFailedInternalFunctionEvent)); var cvUploadEventTask = await Task.WhenAny(cvUploadedEventTask, cvUploadFailedEventTask); var photoUploadEventTask = await Task.WhenAny(photoUploadedEventTask, photoUploadFailedEventTask); var cvUploadedSuccessfully = cvUploadEventTask == cvUploadedEventTask; var photoUploadedSuccessfully = photoUploadEventTask == photoUploadedEventTask; if (!cvUploadedSuccessfully || !photoUploadedSuccessfully) { await this.HandleUploadFilesFailure( context, processStarter, log, photoUploadFailedEventTask, cvUploadFailedEventTask, command); return; } log.LogProgress(OperationStatus.InProgress, "Finished the files uploading", context.InstanceId); var cvUri = cvUploadedEventTask.Result.CvUri; var photoUri = photoUploadedEventTask.Result.PhotoUri; var saveApplicationCommand = new CreateApplicationCommand( context.InstanceId, command.Candidate.FirstName, command.Candidate.LastName, photoUri, cvUri, command.Candidate.Category, command.CreationTime, command.Candidate.EducationLevel, command.Candidate.Address, command.Candidate.FinishedSchools, command.Candidate.ConfirmedSkills, command.Candidate.WorkExperiences, context.InstanceId); await context.CallActivityAsync <Task>(nameof(ApplicationSaver), saveApplicationCommand); var applicationSavedEvent = context.WaitForExternalEvent <ApplicationSavedInternalFunctionEvent>(nameof(ApplicationSavedInternalFunctionEvent)); var applicationSaveFailed = context.WaitForExternalEvent <ApplicationSaveFailedInternalFunctionEvent>(nameof(ApplicationSaveFailedInternalFunctionEvent)); var applicationSaveEvent = await Task.WhenAny(applicationSavedEvent, applicationSaveFailed); var applicationSavedSuccessfully = applicationSaveEvent == applicationSavedEvent; if (!applicationSavedSuccessfully) { log.LogFailedOperation(OperationStatus.Failed, "Storing application failed", applicationSaveFailed.Result.Errors, context.InstanceId); var failedProcessCommand = this.BuildFailedProcessCommand(context, applicationSaveFailed.Result.Errors); await context.CallActivityAsync <Task>(nameof(StatusTracker), failedProcessCommand); await this.StartRecompensateProcess(processStarter, context, command, log); return; } var finishProcessCommand = this.BuildFinishedProcessCommand(context); await context.CallActivityAsync <Task>(nameof(StatusTracker), finishProcessCommand); }
public async Task <IActionResult> Create([FromBody] CreateApplicationCommand createApplicationCommand) { var id = await mediator.Send(createApplicationCommand); return(Ok(new { applicationId = id })); }
public async Task <ActionResult <Application> > PostApplication(CreateApplicationCommand command) { var response = await _mediator.Send(command); return(response); }