예제 #1
0
        public async Task <StatementExtension> MakeDecisionAsync(StatementExtension perceptionStatement, IPersonRepository personRepository,
                                                                 PersonDomainService personDomainService)
        {
            if (perceptionStatement == null)
            {
                return(null);
            }

            if (personRepository == null)
            {
                throw new ArgumentException("Person application service asked to make a decision without a person repository");
            }
            if (personDomainService == null)
            {
                throw new ArgumentException("Person application service asked to make a decision without a person domain service");
            }

            var personVerbs = new List <string>()
            {
                Verb.PersonCreationRequested, Verb.PersonRequested, Verb.PersonUpdateRequested
            };

            if (!personVerbs.Contains(perceptionStatement.verbString()))
            {
                return(null);
            }

            StatementExtension decisionStatement = null;

            await personRepository.SavePerceptionAsync(perceptionStatement);

            switch (perceptionStatement?.verbString())
            {
            case Verb.PersonCreationRequested:
                var personToCreate = perceptionStatement.targetData <Person>();
                decisionStatement = personDomainService.CreatePersonDecider(perceptionStatement, personToCreate);
                break;

            case Verb.PersonRequested:
                var idOfPersonRequested = perceptionStatement.targetId();
                var personRequested     = personRepository.RetrievePerson(idOfPersonRequested);
                decisionStatement = personDomainService.RetrievePersonDecider(perceptionStatement, personRequested);
                break;

            case Verb.PersonUpdateRequested:
                var idOfPerson     = perceptionStatement.targetId();
                var personToUpdate = personRepository.RetrievePerson(idOfPerson);
                decisionStatement = personDomainService.UpdatePersonDecider(perceptionStatement, personToUpdate);
                break;
            }

            await personRepository.SaveDecisionAsync(decisionStatement);

            return(decisionStatement);
        }
예제 #2
0
        public void Retrieve_person_decider_should_throw_if_the_perception_statement_does_not_have_a_verb()
        {
            var perceptionStatement = new StatementExtension();

            Assert.ThrowsException <InvalidOperationException>(() => _personDomainService.RetrievePersonDecider(perceptionStatement, null));
        }