public void Check_DomainEvents_ActivityAdded_Raise() { //given //existing project var project = Project.From(EntityId.From(1u), Description.From("descriptionText")); //a activity it is attached to it var activity = Activity.From(Description.From("activity to do"), EntityId.From(1u), EntityId.From(1u), ActivityStatus.From(1)); var projectOptionsBuilder = new DbContextOptionsBuilder <ProjectDbContext>(); projectOptionsBuilder.UseSqlite("Data Source=todoagility_proj_activity_reference.db;"); var projectDbContext = new ProjectDbContext(projectOptionsBuilder.Options); var repProject = new ProjectRepository(projectDbContext); using var projectDbSession = new DbSession <IProjectRepository>(projectDbContext, repProject); repProject.Add(project); projectDbSession.SaveChanges(); var handlerActivityAdded = new ActivityAddedHandler(projectDbSession); var dispatcher = new DomainEventDispatcher(); dispatcher.Subscribe(typeof(ActivityAddedEvent).FullName, handlerActivityAdded); //when dispatcher.Publish(ActivityAddedEvent.For(activity)); //then var proj = repProject.Get(EntityId.From(1u)); Assert.True(proj.Activities.Count > 0); }
/// <summary> /// load an aggregate from store /// </summary> /// <param name="currentActivity"></param> private ActivityAggregationRoot(Activity currentActivity) : base(currentActivity) { if (currentActivity.ValidationResults.IsValid) { Change(currentActivity); Raise(ActivityAddedEvent.For(currentActivity)); } ValidationResults = currentActivity.ValidationResults; }