Beispiel #1
0
        public async Task <IActionResult> Get()
        {
            var request = new GetDictionariesRequest();
            await _commandProcessor.SendAsync(request);

            return(Ok(request.Result));
        }
        public async Task <IActionResult> Delete(string id, CancellationToken ct)
        {
            var deleteExistingAccountCommand = new DeleteExistingAccountCommand(Guid.Parse(id));
            await _commandProcessor.SendAsync(deleteExistingAccountCommand, false, ct);

            return(Ok());
        }
Beispiel #3
0
        public async Task When_Handling_A_Command_With_A_Inbox_Enabled_Async()
        {
            await _commandProcessor.SendAsync(_command);

            // should_store_the_command_to_the_inbox
            _inbox.GetAsync <MyCommand>(_command.Id, _contextKey).Result.Value.Should().Be(_command.Value);
        }
        public async Task When_Handling_A_Command_Once_Only_With_Throw_Enabled()
        {
            await _commandProcessor.SendAsync(_command);

            Exception ex = await Assert.ThrowsAsync <OnceOnlyException>(() => _commandProcessor.SendAsync(_command));

            Assert.Equal($"A command with id {_command.Id} has already been handled", ex.Message);
        }
Beispiel #5
0
        public async Task When_Handling_A_Command_Once_Only_With_Warn_Enabled()
        {
            await _commandProcessor.SendAsync(_command);

            await _commandProcessor.SendAsync(_command);

            MyStoredCommandToWarnHandlerAsync.ReceivedCount.Should().Be(1);
        }
Beispiel #6
0
        public async Task <IActionResult> GetRelationshipByWord(int id, int wordId)
        {
            var request = new GetRelationshipsByWordRequest
            {
                DictionaryId = id,
                WordId       = wordId
            };
            await _commandProcessor.SendAsync(request);

            return(Ok(request.Result));
        }
Beispiel #7
0
        public async Task <IActionResult> Post([FromBody] AddGreetingRequest request)
        {
            var newGreetingId      = Guid.NewGuid();
            var addGreetingCommand = new AddGreetingCommand(newGreetingId, request.Message);

            await _commandProcessor.SendAsync(addGreetingCommand);

            var addedGreeting = await _queryProcessor.ExecuteAsync(new GreetingsByIdQuery(newGreetingId));

            return(Ok(addedGreeting));
        }
        public async Task <IActionResult> CreateAsync(CreateExamCommand command)
        {
            if (!User.IsInRole(Roles.Admin))
            {
                command.Shared = false;
            }

            await _commandProcessor.SendAsync(command);

            return(Ok());
        }
Beispiel #9
0
        public async Task <IActionResult> Post([FromBody] AddToDoRequest request)
        {
            var addToDoCommand = new AddToDoCommand(request.Title, request.Completed, request.Order);

            await _commandProcessor.SendAsync(addToDoCommand);

            var addedToDo = await _queryProcessor.ExecuteAsync(new ToDoByIdQuery(addToDoCommand.ToDoItemId));

            addedToDo.Url = Url.RouteUrl("GetTodo", new { id = addedToDo.Id }, protocol: Request.Scheme);

            return(CreatedAtRoute("GetTodo", new { id = addedToDo.Id }, addedToDo));
        }
        public async Task <IActionResult> Post([FromBody] AddShippingLineRequest request)
        {
            var addShippingLineCommand = new AddShippingLineCommand(
                lineName: new LineName(request.LineName)
                );

            await _commandProcessor.SendAsync(addShippingLineCommand);

            var addedShip = await _queryProcessor.ExecuteAsync(new ShippingLineByIdQuery(new Id(addShippingLineCommand.Id)));

            return(Ok(addedShip));
        }
        public async Task <IActionResult> GetWords(int id, int pageNumber = 1, int pageSize = 10)
        {
            var request = new GetWordsByDictionaryRequest
            {
                DictionaryId = id,
                PageNumber   = pageNumber,
                PageSize     = pageSize
            };

            await _commandProcessor.SendAsync(request);

            return(Ok(request.Result));
        }
Beispiel #12
0
        public async Task <IActionResult> Post([FromBody] TodoView view, CancellationToken cancellationToken = default(CancellationToken))
        {
            var id = Math.Abs(Guid.NewGuid().GetHashCode());
            await _commandProcessor.SendAsync(new CreateTodo(id, view.Title, view.Completed, view.Order), false, cancellationToken).ConfigureAwait(false);

            // todo: yeah, this is a hack
            view.Id  = id;
            view.Url = GetTodoUri(id);

            HttpContext.Response.Headers.Add("Location", view.Url);

            return(Created(view.Url, view));
        }
Beispiel #13
0
        public async Task <IActionResult> CreatePeriodical(int libraryId, [FromBody] PeriodicalView periodical, CancellationToken token = default(CancellationToken))
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var request = new AddPeriodicalRequest(libraryId, periodical.Map());
            await _commandProcessor.SendAsync(request, cancellationToken : token);

            var renderResult = _periodicalRenderer.Render(request.Result, libraryId);

            return(new CreatedResult(renderResult.Links.Self(), renderResult));
        }
Beispiel #14
0
        public async Task <IActionResult> CreateLibrary([FromBody] LibraryView library, CancellationToken token)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var request = new AddLibraryRequest(library.Map());
            await _commandProcessor.SendAsync(request, cancellationToken : token);

            var renderResult = _libraryRenderer.Render(request.Result);

            return(new CreatedResult(renderResult.Links.Self(), renderResult));
        }
        public async Task <IActionResult> GetAsync()
        {
            var list = await _queryProcessor.ExecuteAsync(new GetUserScoreFormulasQuery());

            if (list.Any())
            {
                return(Ok(list));
            }

            await _commandProcessor.SendAsync(new CloneScoreFormulaCommand());

            list = await _queryProcessor.ExecuteAsync(new GetUserScoreFormulasQuery());

            return(Ok(list));
        }
        public async Task <IActionResult> Post([FromBody] AddShipRequest request)
        {
            var addShipCommand = new AddShipCommand(
                type: (ShipType)Enum.Parse <ShipType>(request.Type),
                name: new ShipName(request.Name),
                capacity: new Capacity(request.Capacity),
                shippingLine: new Id(request.ShippingLine)
                );

            await _commandProcessor.SendAsync(addShipCommand);

            var addedShip = await _queryProcessor.ExecuteAsync(new ShipByIdQuery(new Id(addShipCommand.Id)));

            return(Ok(addedShip));
        }
Beispiel #17
0
        public void When_Monitoring_Is_on_For_A_Handler_Async()
        {
            AsyncContext.Run(async() => await _commandProcessor.SendAsync(_command));
            _beforeEvent = _controlBusSender.Observe <MonitorEvent>();
            _afterEvent  = _controlBusSender.Observe <MonitorEvent>();


            //_should_have_an_instance_name_before
            Assert.AreEqual("UnitTests", _beforeEvent.InstanceName);
            //_should_post_the_event_type_to_the_control_bus_before
            Assert.AreEqual(MonitorEventType.EnterHandler, _beforeEvent.EventType);
            //_should_post_the_handler_fullname_to_the_control_bus_before
            Assert.AreEqual(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName, _beforeEvent.HandlerFullAssemblyName);
            //_should_post_the_handler_name_to_the_control_bus_before
            Assert.AreEqual(typeof(MyMonitoredHandlerAsync).FullName, _beforeEvent.HandlerName);
            //_should_include_the_underlying_request_details_before
            Assert.AreEqual(_originalRequestAsJson, _beforeEvent.RequestBody);
            //should_post_the_time_of_the_request_before
            Assert.AreEqual(_at, _beforeEvent.EventTime);
            //_should_have_an_instance_name_after
            Assert.AreEqual("UnitTests", _afterEvent.InstanceName);
            //_should_post_the_event_type_to_the_control_bus_after
            Assert.AreEqual(MonitorEventType.ExitHandler, _afterEvent.EventType);
            //_should_post_the_handler_fullname_to_the_control_bus_after
            Assert.AreEqual(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName, _afterEvent.HandlerFullAssemblyName);
            //_should_post_the_handler_name_to_the_control_bus_after
            Assert.AreEqual(typeof(MyMonitoredHandlerAsync).FullName, _afterEvent.HandlerName);
            //_should_include_the_underlying_request_details_after
            Assert.AreEqual(_originalRequestAsJson, _afterEvent.RequestBody);
            //should_post_the_time_of_the_request_after
            Assert.Greater(_afterEvent.EventTime, _at);
            //should_post_the_elapsedtime_of_the_request_after
            Assert.AreEqual((_afterEvent.EventTime - _beforeEvent.EventTime).Milliseconds, _afterEvent.TimeElapsedMs);
        }
 public async Task Post()
 {
     await _processor.SendAsync(new BlogCommand()
     {
         Name = "bob"
     });
 }
        public void When_Handling_A_Command_With_A_Command_Store_Enabled_Async()
        {
            AsyncContext.Run(async() => await _commandProcessor.SendAsync(_command));

            // should_store_the_command_to_the_command_store
            Assert.AreEqual(_command.Value, _commandStore.GetAsync <MyCommand>(_command.Id).Result.Value);
        }
Beispiel #20
0
        public async Task <IActionResult> Index()
        {
            var request = new GetEntryRequest();
            await _commandProcessor.SendAsync(request);

            return(Ok(request.Result));
        }
        public async Task When_Monitoring_Is_on_For_A_Handler_Async()
        {
            await _commandProcessor.SendAsync(_command);

            _beforeEvent = _controlBusSender.Observe <MonitorEvent>();
            _afterEvent  = _controlBusSender.Observe <MonitorEvent>();

            //_should_have_an_instance_name_before
            _beforeEvent.InstanceName.Should().Be("UnitTests");
            //_should_post_the_event_type_to_the_control_bus_before
            _beforeEvent.EventType.Should().Be(MonitorEventType.EnterHandler);
            //_should_post_the_handler_fullname_to_the_control_bus_before
            _beforeEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName);
            //_should_post_the_handler_name_to_the_control_bus_before
            _beforeEvent.HandlerName.Should().Be(typeof(MyMonitoredHandlerAsync).FullName);
            //_should_include_the_underlying_request_details_before
            _beforeEvent.RequestBody.Should().Be(_originalRequestAsJson);
            //should_post_the_time_of_the_request_before
            _beforeEvent.EventTime.AsUtc().Should().BeCloseTo(_at.AsUtc(), 1000);
            //_should_have_an_instance_name_after
            _afterEvent.InstanceName.Should().Be("UnitTests");
            //_should_post_the_event_type_to_the_control_bus_after
            _afterEvent.EventType.Should().Be(MonitorEventType.ExitHandler);
            //_should_post_the_handler_fullname_to_the_control_bus_after
            _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName);
            //_should_post_the_handler_name_to_the_control_bus_after
            _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandlerAsync).FullName);
            //_should_include_the_underlying_request_details_after
            _afterEvent.RequestBody.Should().Be(_originalRequestAsJson);
            //should_post_the_time_of_the_request_after
            _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc());
        }
Beispiel #22
0
        public async Task <ActionResult <AuthDataViewModel> > PostAsync([FromBody] RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var emailUnique = await _queryProcessor.ExecuteAsync(new IsEmailUniqueQuery(model.Email));

            if (!emailUnique)
            {
                return(BadRequest(new { email = "User with this email already exists" }));
            }

            var usernameUnique = await _queryProcessor.ExecuteAsync(new IsEmailUniqueQuery(model.Username));

            if (!usernameUnique)
            {
                return(BadRequest(new { username = "******" }));
            }

            var command = new CreateUserCommand(model.Username, model.Email, model.Password);

            await _commandProcessor.SendAsync <CreateUserCommand>(command);

            return(new AuthDataViewModel(_jwtSecretKey, _jwtLifespan, command.UserId));
        }
Beispiel #23
0
        public async Task <IActionResult> DeleteFile(int fileId, CancellationToken token = default(CancellationToken))
        {
            var request = new DeleteFileRequest(fileId);
            await _commandProcessor.SendAsync(request, cancellationToken : token);

            return(new NoContentResult());
        }
Beispiel #24
0
        public async Task <IActionResult> AddCorrection(string language, string profile, [FromBody] CorrectionView correction, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            correction.Language = language;
            correction.Profile  = profile;

            var request = new AddCorrectionRequest(correction.Map());
            await _commandProcessor.SendAsync(request, cancellationToken : cancellationToken);

            var renderResult = _correctionRenderer.Render(request.Result);

            return(new CreatedResult(renderResult.Links.Self(), renderResult));
        }
Beispiel #25
0
        public async Task When_A_Request_Logger_Is_In_The_Pipeline_Async()
        {
            await _commandProcessor.SendAsync(_myCommand);

            //_should_log_the_request_handler_call
            _logger.Logs.Should().Contain(log => log.Message.Contains("Logging handler pipeline call"));
            //_should_log_the_type_of_handler_in_the_call
            _logger.Logs.Should().Contain(log => log.Message.Contains(typeof(MyCommand).ToString()));
        }
        public void When_A_Request_Logger_Is_In_The_Pipeline_Async()
        {
            AsyncContext.Run(async() => await _commandProcessor.SendAsync(_myCommand));


            //_should_log_the_request_handler_call
            Assert.True(((Func <IList <SpyLog.LogRecord>, bool>)(logs => logs.Any(log => log.Message.Contains("Logging handler pipeline call")))).Invoke(_logger.Logs));
            //_should_log_the_type_of_handler_in_the_call
            Assert.True(((Func <IList <SpyLog.LogRecord>, bool>)(logs => logs.Any(log => log.Message.Contains(typeof(MyCommand).ToString())))).Invoke(_logger.Logs));
        }
Beispiel #27
0
        public async Task <IHttpActionResult> Post(CreateWorksheetRequest request)
        {
            var userIdOnPrincipal = 210;
            var worksheetId       = new Guid();

            var command = new CreateWorksheetCommand(worksheetId, request.WorksheetName, userIdOnPrincipal);
            await _commandProcessor.SendAsync(command);

            return(CreatedAtRoute("GetWorksheetBrighter", new { worksheetId = worksheetId }, worksheetId));
        }
Beispiel #28
0
        public async Task SendAsync <T>(T command, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default)
            where T : class, IRequest
        {
            if (!(command is CommandBase commandBase))
            {
                await _commandProcessor.SendAsync(command, continueOnCapturedContext, cancellationToken);

                return;
            }

            if (!(commandBase is ISkipLogging))
            {
                await _commandQueryLogger.LogCommandAsync(command);
            }

            commandBase.UserId = await _userIdProvider.GetAsync();

            await _commandProcessor.SendAsync(command, continueOnCapturedContext, cancellationToken);
        }
Beispiel #29
0
        public void Execute(int dictionaryId)
        {
            _logger.LogDebug("Started downloading dictionary {0}", dictionaryId);
            var downloadDictionaryCommand = new DownloadDictionaryCommand
            {
                DictionaryId = dictionaryId
            };

            _commandProcessor.SendAsync(downloadDictionaryCommand).Wait();

            _logger.LogDebug("Dictionary {0} downloaded to {1}", dictionaryId, downloadDictionaryCommand.FilePath);

            _commandProcessor.SendAsync(new AddLocalDictionaryCommand
            {
                Dictionary = downloadDictionaryCommand.Result,
                FilePath   = downloadDictionaryCommand.FilePath
            }).Wait();

            _logger.LogDebug("Finished downloading dictionary {0}", dictionaryId);
        }
Beispiel #30
0
        public async Task <IActionResult> Create()
        {
            var command = new CreateGameCommand(UserId);

            await _commandProcessor.SendAsync(command);

            return(CreatedAtAction(
                       "GetGame",
                       new { command.Id },
                       new { command.Id, command.CreatedOn }));
        }