public async Task <ActionResult> Ask(QuestionCreateRequest request, CancellationToken cancel)
        {
            var command = new QuestionCreateCommand(request.Title, request.Content, _markdown.TransformIntoHTML(request.Content), DateTime.Now, request.Tags);
            var result  = await _mediator.ExecuteAsync <QuestionCreateCommand, QuestionCreateCommandResult>(command, User.GetAppIdentity(), cancel);

            return(RedirectToRoute("QuestionRead", new { id = result.Id, slug = result.Slug, action = "get" }));
        }
Exemplo n.º 2
0
        public async Task QuestionCreateCommandTriggersEventToUpdateQueryDbWithQuestion()
        {
            var questionText = "Test Question 1";

            //Arrange
            var command = new QuestionCreateCommand(questionText);
            await _commandBus.Send(command);

            //Act
            var questions = await _questionRepo.FindByAsync(q => q.Id == 1).ConfigureAwait(false);

            var question = questions.FirstOrDefault();

            //Act
            Assert.IsNotNull(question);
            Assert.AreEqual(questionText, question.Text);
        }
Exemplo n.º 3
0
        private void AppendQuestion(XElement question, ConcurrentDictionary <String, String> idmap, IDictionary <String, String> usermap)
        {
            if (question.Attribute("OwnerUserId") == null || question.Attribute("Id") == null)
            {
                return;
            }

            var id     = question.Attribute("Id").Value;
            var userId = question.Attribute("OwnerUserId").Value;

            var user = new SimpleQAPrincipal(usermap[userId], "whatever", "", 0);

            var tags = Regex.Matches(question.Attribute("Tags").Value, "<(.*?)>")
                       .OfType <Match>()
                       .Select(m => m.ToString())
                       .Select(s => s.Substring(1, s.Length - 2))
                       .ToArray();

            var creationDate = DateTime.Parse(question.Attribute("CreationDate").Value);
            var views        = Int32.Parse(question.Attribute("ViewCount").Value);

            var command = new QuestionCreateCommand(question.Attribute("Title").Value,
                                                    question.Attribute("Body").Value,
                                                    question.Attribute("Body").Value,
                                                    creationDate,
                                                    tags);
            var sw = new Stopwatch();

            sw.Start();
            var result = _mediator.ExecuteAsync <QuestionCreateCommand, QuestionCreateCommandResult>(command, user.GetAppIdentity(), CancellationToken.None).Result;

            sw.Stop();

            var viewCommand = new VisitQuestionCommand(result.Id, views);

            _mediator.ExecuteAsync <VisitQuestionCommand, VisitQuestionCommandResult>(viewCommand, user.GetAppIdentity(), CancellationToken.None).Wait();

            Console.WriteLine("Added question: " + result.Slug + ",  " + question.Attribute("Body").Value.Length + " chars in " + sw.ElapsedMilliseconds + " ms.");

            idmap.TryAdd(id, result.Id);
        }
Exemplo n.º 4
0
        public async Task QuestionDeleteCommandTriggersEventToDeleteQuestionFromQueryDb()
        {
            //Arrange
            var command = new QuestionCreateCommand("Test Question 1");
            await _commandBus.Send(command);

            var questions = await _questionRepo.FindByAsync(q => q.Id == 1).ConfigureAwait(false);

            var question = questions.FirstOrDefault();

            //Act
            Assert.IsNotNull(question);

            var command2 = new QuestionDeleteCommand(1, 0);
            await _commandBus.Send(command2).ConfigureAwait(false);

            var questionAfterDelete = (await _questionRepo.FindByAsync(q => q.Id == 1).ConfigureAwait(false)).FirstOrDefault();

            //Act
            Assert.IsNull(questionAfterDelete);
        }