public void Make_Decision_async_should_throw_if_person_domain_service_is_not_supplied()
        {
            var perceptionStatement = new StatementExtension();

            Assert.ThrowsExceptionAsync <ArgumentException>(() => _personApplicationService.MakeDecisionAsync(perceptionStatement,
                                                                                                              _personRepository.Object, null));
        }
示例#2
0
        public IActionResult Post([FromBody] JArray requestJArray)
        {
            var requestContent = requestJArray.ToString();

            _logger.LogInformation($"Received events: {requestContent}");

            EventGridSubscriber eventGridSubscriber = new EventGridSubscriber();

            EventGridEvent[] eventGridEvents = eventGridSubscriber.DeserializeEventGridEvents(requestContent);

            foreach (EventGridEvent eventGridEvent in eventGridEvents)
            {
                if (eventGridEvent.Data is SubscriptionValidationEventData eventData)
                {
                    _logger.LogInformation($"Got SubscriptionValidation event data, validationCode: {eventData.ValidationCode},  validationUrl: {eventData.ValidationUrl}, topic: {eventGridEvent.Topic}");
                    // Do any additional validation (as required) such as validating that the Azure resource ID of the topic matches
                    // the expected topic and then return back the below response
                    var responseData = new SubscriptionValidationResponse()
                    {
                        ValidationResponse = eventData.ValidationCode
                    };

                    return(Ok(responseData));
                }
                else
                {
                    var statement        = new StatementExtension((JObject)eventGridEvent.Data);
                    var statementWrapper = new StatementWrapper(eventGridEvent.Subject, statement);
                    _decisionChannel.Next(statementWrapper);
                }
            }

            return(Ok(null));
        }
示例#3
0
        public void Target_data_generic_should_return_the_data_if_it_is_set()
        {
            var targetData = new Person()
            {
                Name = "Test"
            };
            var targetDataJObject = JObject.FromObject(targetData);
            var extensionsJObject = new JObject()
            {
                { $"{StatementExtension.ActivityDefinitionDataExtension}", targetDataJObject }
            };

            var statementExtension = new StatementExtension()
            {
                target = new Activity()
                {
                    definition = new ActivityDefinition()
                    {
                        extensions = new TinCan.Extensions(extensionsJObject)
                    }
                }
            };

            Assert.AreNotEqual(targetData, statementExtension.targetData <Person>());
            Assert.AreEqual(targetData.Name, statementExtension.targetData <Person>().Name);
        }
示例#4
0
        public void Target_data_should_clone_and_return_the_data_if_it_is_set()
        {
            var targetData = JObject.FromObject(new Person()
            {
                Name = "Test"
            });
            var extensionsJObject = new JObject()
            {
                { $"{StatementExtension.ActivityDefinitionDataExtension}", targetData }
            };

            var statementExtension = new StatementExtension()
            {
                target = new Activity()
                {
                    definition = new ActivityDefinition()
                    {
                        extensions = new TinCan.Extensions(extensionsJObject)
                    }
                }
            };

            Assert.AreNotEqual(targetData, statementExtension.targetData());
            Assert.AreEqual(targetData.GetValue("Name").ToString(), statementExtension.targetData().GetValue("Name").ToString());
        }
        public void Prepare_to_persist_should_set_the_stored_value()
        {
            var statement = new StatementExtension();

            statement.prepareToPersist();

            Assert.IsNotNull(statement.stored);
        }
        public void Create_successor_should_not_return_the_precursor()
        {
            var precursorStatement = new StatementExtension();

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.AreNotEqual(precursorStatement, successorStatement);
        }
        public void Prepare_to_persist_should_set_an_id_if_one_is_not_set_already()
        {
            var statement = new StatementExtension();

            statement.prepareToPersist();

            Assert.IsNotNull(statement.id);
        }
        public void Create_successor_should_not_populate_the_context_if_there_is_no_precursor_context_and_no_precursor_id()
        {
            var precursorStatement = new StatementExtension();

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.IsNull(successorStatement.context);
        }
 public StatementWrapper(string connectionContextId, StatementExtension statement)
 {
     Data        = statement ?? throw new ArgumentException("Tried to create an event wrapper without a statement");
     DataVersion = "1.0.0";
     EventTime   = DateTime.Now;
     EventType   = statement.verb.id.ToString();
     Id          = Guid.NewGuid().ToString();
     Subject     = connectionContextId;
 }
        public void Target_id_should_handle_empty_target_id()
        {
            var statementExtension = new StatementExtension()
            {
                target = new Activity()
            };

            Assert.IsNull(statementExtension.targetId());
        }
        public void Prepare_to_persist_should_overwrite_an_existing_stored_value()
        {
            var existingStored = DateTime.Parse("2008-11-01T19:35:00.0000000Z");
            var statement      = new StatementExtension();

            statement.prepareToPersist();

            Assert.AreNotEqual(existingStored, statement.stored);
        }
示例#12
0
        public void Target_data_generic_should_handle_empty_target_definition()
        {
            var statementExtension = new StatementExtension()
            {
                target = new Activity()
            };

            Assert.IsNull(statementExtension.targetData <Person>());
        }
示例#13
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);
        }
        public async Task SavePerceptionAsync(StatementExtension statement)
        {
            if (statement == null)
            {
                return;
            }

            statement.prepareToPersist();

            await _documentClient.CreateDocumentAsync(_perceptionCollectionUri, statement.ToJObject());
        }
示例#15
0
        public StatementExtension RetrievePersonDecider(StatementExtension perceptionStatement, Person person)
        {
            if (perceptionStatement?.verbString() != Verb.PersonRequested)
            {
                throw new InvalidOperationException("Incorrect verb to retrieve person");
            }

            return(person != null?
                   perceptionStatement.createSuccessor(Verb.PersonRetrieved, person) :
                       perceptionStatement.createSuccessor(Verb.PersonRetrievalFailed, null));
        }
        public void Create_successor_should_populate_the_target_id_if_it_is_supplied()
        {
            var newId = "http://eventualityPOC.com/test/2";

            var precursorStatement = new StatementExtension();

            var successorStatement = precursorStatement.createSuccessor(VerbId, null, newId);

            Assert.IsNotNull(successorStatement.target.ToJObject(TCAPIVersion.V103).GetValue("id"));
            Assert.AreEqual(successorStatement.target.ToJObject(TCAPIVersion.V103).GetValue("id").ToString(), newId);
        }
        public void Create_successor_should_create_a_new_id_for_the_successor()
        {
            var precursorStatement = new StatementExtension()
            {
            };

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.AreNotEqual(precursorStatement.id, successorStatement.id);
            Assert.IsNotNull(successorStatement.id);
        }
        public void Prepare_to_persist_should_not_overwrite_an_existing_id()
        {
            var existingId = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247482");
            var statement  = new StatementExtension()
            {
                id = existingId
            };

            statement.prepareToPersist();

            Assert.AreEqual(existingId, statement.id);
        }
        public void Target_id_should_return_target_id_if_it_is_set()
        {
            var statementExtension = new StatementExtension()
            {
                target = new Activity()
                {
                    id = "http://eventualityPOC.com/test/1"
                }
            };

            Assert.AreEqual("http://eventualityPOC.com/test/1", statementExtension.targetId());
        }
示例#20
0
        public void Target_data_should_handle_empty_target_definition_extensions()
        {
            var statementExtension = new StatementExtension()
            {
                target = new Activity()
                {
                    definition = new ActivityDefinition()
                }
            };

            Assert.IsNull(statementExtension.targetData());
        }
        public void Create_person_decider_should_throw_if_the_perception_statement_verb_is_incorrect()
        {
            var perceptionStatement = new StatementExtension()
            {
                verb = new TinCan.Verb()
                {
                    id = new Uri(Verb.PersonRequested)
                }
            };

            Assert.ThrowsException <InvalidOperationException>(() => _personDomainService.CreatePersonDecider(perceptionStatement, null));
        }
示例#22
0
        public StatementExtension UpdatePersonDecider(StatementExtension perceptionStatement, Person personToUpdate)
        {
            if (perceptionStatement?.verbString() != Verb.PersonUpdateRequested)
            {
                throw new InvalidOperationException("Incorrect verb to update person");
            }

            var updatedPerson = perceptionStatement.targetData <Person>();

            return(personToUpdate != null && updatedPerson?.Name != null?
                   perceptionStatement.createSuccessor(Verb.PersonUpdated, updatedPerson) :
                       perceptionStatement.createSuccessor(Verb.PersonUpdateFailed, null));
        }
        public void Create_successor_should_create_a_context_if_there_is_a_precursor_id()
        {
            var precursorId        = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247483");
            var precursorStatement = new StatementExtension()
            {
                id = precursorId
            };

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.IsNotNull(successorStatement.context);
            Assert.AreEqual(successorStatement.context.statement.id, precursorId);
        }
        public void Create_person_decider_should_fail_if_no_person_is_submitted()
        {
            var perceptionStatement = new StatementExtension()
            {
                verb = new TinCan.Verb()
                {
                    id = new Uri(Verb.PersonCreationRequested)
                }
            };

            var decisionStatement = _personDomainService.CreatePersonDecider(perceptionStatement, null);

            Assert.AreEqual(decisionStatement.verb.id, Verb.PersonCreationFailed);
        }
示例#25
0
        public void Retrieve_person_decider_should_fail_if_the_person_is_not_found()
        {
            var perceptionStatement = new StatementExtension()
            {
                verb = new TinCan.Verb()
                {
                    id = new Uri(Verb.PersonRequested)
                }
            };

            var responseStatement = _personDomainService.RetrievePersonDecider(perceptionStatement, null);

            Assert.AreEqual(responseStatement.verb.id, Verb.PersonRetrievalFailed);
        }
        public void Make_Decision_async_should_persist_the_decision_statement()
        {
            var perceptionStatement = new StatementExtension()
            {
                verb = new TinCan.Verb()
                {
                    id = new Uri(Verb.PersonRequested)
                }
            };

            var decisionStatement = _personApplicationService.MakeDecisionAsync(perceptionStatement, _personRepository.Object,
                                                                                _personDomainService.Object).Result;

            _personRepository.Verify(pr => pr.SaveDecisionAsync(decisionStatement));
        }
        public void Create_successor_should_clone_and_copy_actor()
        {
            var precursorStatement = new StatementExtension()
            {
                actor = new Agent()
                {
                    mbox = "*****@*****.**"
                }
            };

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.AreNotEqual(precursorStatement.actor, successorStatement.actor);
            Assert.AreEqual(precursorStatement.actor.mbox, successorStatement.actor.mbox);
        }
        public void Create_successor_should_clone_and_copy_authority()
        {
            var precursorStatement = new StatementExtension()
            {
                authority = new Agent()
                {
                    name = "External LMS"
                }
            };

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.AreNotEqual(precursorStatement.authority, successorStatement.authority);
            Assert.AreEqual(precursorStatement.authority.name, successorStatement.authority.name);
        }
        public void Create_successor_should_not_modify_the_precursor()
        {
            var precursorStatement = new StatementExtension()
            {
                actor = new Agent()
                {
                    mbox = "*****@*****.**"
                }
            };

            var precursorString = precursorStatement.ToString();

            var successorStatement = precursorStatement.createSuccessor(VerbId);

            Assert.AreEqual(precursorString, precursorStatement.ToString());
        }
        public void Create_person_decider_should_fail_if_the_person_does_not_have_a_name()
        {
            var perceptionStatement = new StatementExtension()
            {
                verb = new TinCan.Verb()
                {
                    id = new Uri(Verb.PersonCreationRequested)
                }
            };

            perceptionStatement.populateTarget(new Person());

            var decisionStatement = _personDomainService.CreatePersonDecider(perceptionStatement, null);

            Assert.AreEqual(decisionStatement.verb.id, Verb.PersonCreationFailed);
        }