コード例 #1
0
ファイル: DocumentDbTests.cs プロジェクト: patrickCode/Quest
        public async Task AddAndRetrieveDocument()
        {
            //Init
            var id       = Guid.NewGuid().ToString();
            var question = GetSampleQuestion(id);

            //Action
            await _writer.CreateOrUpdateAsync(question);

            var document = await _reader.GetAsync(id);

            //Assert
            Assert.IsNotNull(document);
            Assert.AreEqual(question, document);
        }
コード例 #2
0
        public override async Task <CommandResult> ProcessAsync(UpdateQuestion command)
        {
            var originalQuestion = await _reader.GetAsync(command.UpdatedQuestion.Id);

            if (originalQuestion == null)
            {
                throw new DomainValidationException(command.Id, "This question doesn't exist", 15)
                      {
                          Suggestion = "Create this question as a new question"
                      }
            }
            ;

            var question = _domainValidator.FromDto(command.UpdatedQuestion, command.Id);

            question.Update(originalQuestion.Id,
                            originalQuestion.CreatedBy,
                            originalQuestion.CreatedOn,
                            command.UpdatedQuestion.LastModifiedBy);
            var document = _dtoParser.Create(question);

            await _writer.CreateOrUpdateAsync(document);

            return(new IdentityResult(command.Id, originalQuestion.Id));
        }
    }
コード例 #3
0
        public override async Task <CommandResult> ProcessAsync(AddQuestion command)
        {
            var id       = Guid.NewGuid().ToString();
            var question = _domainValidator.FromDto(command.NewQuestion, command.Id);

            question.Save(id, command.NewQuestion.CreatedBy);
            var document = _dtoParser.Create(question);

            await _writer.CreateOrUpdateAsync(document);

            return(new IdentityResult(command.Id, id));
        }