Esempio n. 1
0
        public void Check_ActivityRespository_Update()
        {
            //given
            var descriptionText        = "Given Description";
            var descriptionTextChanged = "Given Description Modificada";
            var project = ProjectReference.From(EntityId.From(1u), Description.From(descriptionText));

            var id = EntityId.From(1u);

            var task = Activity.From(Description.From(descriptionText), id,
                                     EntityId.From(1u), ActivityStatus.From(1));

            //when
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_repo_update_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new ActivityDbSession(taskDbContext, repTask);
            taskDbSession.Repository.Add(task);
            taskDbSession.SaveChanges();

            //then
            var taskSaved  = taskDbSession.Repository.Get(id);
            var updatetask = Activity.CombineWithPatch(taskSaved,
                                                       Activity.Patch.FromDescription(Description.From(descriptionTextChanged)));

            taskDbSession.Repository.Add(updatetask);
            taskDbSession.SaveChanges();

            var taskUpdated = taskDbSession.Repository.Get(id);

            Assert.NotEqual(taskUpdated, task);
        }
        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);
        }
        public void Check_ChangeStatusActivityCommandHandler_Failed()
        {
            var description    = "Given Description";
            var id             = 1u;
            var newStatus      = 4;
            var projectId      = 1u;
            var dispatcher     = new DomainEventDispatcher();
            var optionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            optionsBuilder.UseSqlite("Data Source=todoagility_cqrs_changed_failed_test.db;");
            var taskDbContext = new ActivityDbContext(optionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);

            var originalTask = Activity.From(Description.From(description), EntityId.From(id),
                                             EntityId.From(projectId), ActivityStatus.From(1));

            taskDbSession.Repository.Add(originalTask);
            taskDbSession.SaveChanges();

            var command = new ChangeActivityStatusCommand(id, newStatus);

            var handler = new ChangeActivityStatusCommandHandler(taskDbSession, dispatcher);
            var result  = handler.Execute(command);

            Assert.False(result.IsSucceed);
        }
        public void Check_UpdateActivityCommandHandler_Succeed()
        {
            var description        = "Given Description";
            var id                 = 1u;
            var projectId          = 1u;
            var dispatcher         = new DomainEventDispatcher();
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_cqrs_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);

            var project      = Project.From(EntityId.From(projectId), Description.From(description));
            var originalTask = Activity.From(Description.From(description), EntityId.From(id),
                                             EntityId.From(projectId), ActivityStatus.From(1));

            taskDbSession.Repository.AddProject(project);
            taskDbSession.Repository.Add(originalTask);
            taskDbSession.SaveChanges();

            var descriptionNew = "Given Description Changed";
            var command        = new UpdateActivityCommand(id, descriptionNew);

            var handler = new UpdateActivityCommandHandler(taskDbSession, dispatcher);

            handler.Execute(command);

            var task = taskDbSession.Repository.Get(EntityId.From(id));

            Assert.NotEqual(task, originalTask);
        }
Esempio n. 5
0
        public void Check_Task_valid_instance()
        {
            var name     = Description.From("givenName");
            var entityId = EntityId.From(1u);

            var task = Activity.From(name, entityId, EntityId.From(1u), ActivityStatus.From(1));

            Assert.NotNull(task);
        }
Esempio n. 6
0
        public void Check_Task_GetValue()
        {
            var givenName = "givenName";
            var name      = Description.From(givenName);
            var project   = Project.From(EntityId.From(1u), Description.From(givenName));
            var entityId  = EntityId.From(1u);

            var todo = Activity.From(name, entityId, EntityId.From(1u), ActivityStatus.From(1));
            IExposeValue <ActivityState> state = todo;
            var todoState = state.GetValue();

            Assert.Equal(todoState.Description, givenName);
        }
Esempio n. 7
0
        public void Check_TaskAggregation_UpdateTaskStatus_invalid()
        {
            //given
            var descriptionText = "Given Description";
            var id        = EntityId.From(1u);
            var newStatus = 6;

            var oldState = Activity.From(Description.From(descriptionText), id, EntityId.From(1u),
                                         ActivityStatus.From(1));

            //when
            var agg = ActivityAggregationRoot.ReconstructFrom(oldState);

            agg.ChangeTaskStatus(ActivityStatus.From(newStatus));

            //then
            Assert.False(agg.ValidationResults.IsValid);
        }
Esempio n. 8
0
        public void Check_TaskAggregation_UpdateTaskStatus()
        {
            //given
            var descriptionText = "Given Description";
            var id        = EntityId.From(1u);
            var newStatus = 2;
            var oldState  = Activity.From(Description.From(descriptionText), id, EntityId.From(1u),
                                          ActivityStatus.From(1));

            //when
            var agg = ActivityAggregationRoot.ReconstructFrom(oldState);

            agg.ChangeTaskStatus(ActivityStatus.From(newStatus));
            var changes = agg.GetChange();

            //then
            Assert.NotEqual(changes, oldState);
        }
Esempio n. 9
0
        public void Check_TaskAggregation_Create()
        {
            //given
            var descriptionText = "Given Description";
            var id        = EntityId.From(1u);
            var projectId = EntityId.From(1u);

            var project = Project.From(projectId, Description.From(descriptionText));
            var task    = Activity.From(Description.From(descriptionText), id, EntityId.From(1u),
                                        ActivityStatus.From(1));

            //when
            var agg     = ActivityAggregationRoot.CreateFrom(Description.From(descriptionText), id, project);
            var changes = agg.GetChange();

            //then
            Assert.Equal(changes, task);
        }
Esempio n. 10
0
        public void Check_ProjectActivityReferenceRespository_Update()
        {
            //given
            var descriptionText = "Given Description";
            var projectId       = EntityId.From(1u);
            var id               = EntityId.From(1u);
            var project          = Project.From(EntityId.From(1u), Description.From(descriptionText));
            var projectReference = ProjectReference.From(projectId, Description.From(descriptionText));
            var task             = Activity.From(Description.From(descriptionText), id, projectId,
                                                 ActivityStatus.From(1));

            var projectOptionsBuilder = new DbContextOptionsBuilder <ProjectDbContext>();

            projectOptionsBuilder.UseSqlite("Data Source=todoagility_project_update.db;");
            var projectDbContext = new ProjectDbContext(projectOptionsBuilder.Options);
            var repProject       = new ProjectRepository(projectDbContext);

            using var projectDbSession = new ProjectDbSession(projectDbContext, repProject);
            projectDbSession.Repository.Add(project);
            projectDbSession.SaveChanges();

            //when
            var tasks = new List <EntityId> {
                task.Id
            };
            var projectWithTasks  = Project.CombineProjectAndActivities(project, tasks);
            var projectDbContext2 = new ProjectDbContext(projectOptionsBuilder.Options);
            var repProject2       = new ProjectRepository(projectDbContext2);

            //then
            using var projectDbSession2 = new DbSession <IProjectRepository>(projectDbContext2, repProject2);
            projectDbSession2.Repository.Add(projectWithTasks);
            projectDbSession2.SaveChanges();

            var projectUpdated = projectDbSession2.Repository.Get(projectWithTasks.Id);

            Assert.True(projectUpdated.Activities.Count > 0);
        }
 public ChangeActivityStatusCommand(uint id, int newStatus)
 {
     Id        = EntityId.From(id);
     NewStatus = ActivityStatus.From(newStatus);
 }
Esempio n. 12
0
        public void Check_TaskStatus_valid_Status()
        {
            var statusStarted = ActivityStatus.From(2);

            Assert.Equal(2, statusStarted.Value);
        }
Esempio n. 13
0
        public void Check_TaskStatus_Invalid_Status()
        {
            var status = ActivityStatus.From(-1);

            Assert.False(status.ValidationResults.IsValid);
        }