Ejemplo n.º 1
0
        public async Task ReadDocumentById()
        {
            //Init
            var id = _sampleDocumentId;

            //Action
            var document = await _reader.GetAsync(id);

            //Assert
            Assert.IsNotNull(document);
            Assert.AreEqual(id, document.Id);
        }
Ejemplo n.º 2
0
        public static async Task <TView> GetOrNewAsync <TView>(this IDocumentReader <unit, TView> reader)
            where TView : new()
        {
            var entityMaybe = await reader.GetAsync(unit.it).ConfigureAwait(false);

            return(entityMaybe.GetValue(new TView()));
        }
Ejemplo n.º 3
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));
        }
    }
Ejemplo n.º 4
0
        public static async Task <TEntity> LoadAsync <TKey, TEntity>(this IDocumentReader <TKey, TEntity> self, TKey key)
        {
            var entityMaybe = await self.GetAsync(key).ConfigureAwait(false);

            if (entityMaybe.HasValue)
            {
                return(entityMaybe.Value);
            }
            var txt = string.Format("Failed to load '{0}' with key '{1}'.", typeof(TEntity).Name, key);

            throw new InvalidOperationException(txt);
        }
Ejemplo n.º 5
0
 public async Task <List <CategoryDto> > GetAsync()
 {
     return(await _reader.GetAsync());
 }
Ejemplo n.º 6
0
 public static Task <Maybe <TSingleton> > GetAsync <TSingleton>(this IDocumentReader <unit, TSingleton> reader)
 {
     return(reader.GetAsync(unit.it));
 }
Ejemplo n.º 7
0
 public async Task <List <QuestionDto> > GetAsync()
 {
     return(await _reader.GetAsync());
 }