Exemple #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_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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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 void Check_AddActivityCommandHandler_Succeed()
        {
            var description        = "Given Description";
            var projectId          = 1u;
            var dispatcher         = new DomainEventDispatcher();
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

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

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);
            taskDbSession.Repository.AddProject(Project.From(EntityId.From(projectId), Description.From(description)));
            taskDbSession.SaveChanges();

            var handler = new AddActivityCommandHandler(dispatcher, taskDbSession);
            var command = new AddActivityCommand(description, projectId);

            handler.Execute(command);

            var task = taskDbSession.Repository.Find(a => a.ProjectId == projectId);

            Assert.NotNull(task);
        }