Example #1
0
        public void Check_ProjectRespository_Remove()
        {
            //given
            var descriptionText = "Given Description";
            var projectId       = EntityId.From(1u);

            var project = Project.From(projectId, Description.From(descriptionText));

            var projectOptionsBuilder = new DbContextOptionsBuilder <ProjectDbContext>();

            projectOptionsBuilder.UseSqlite("Data Source=todoagility_project_remove.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 projectToremove = projectDbSession.Repository.Get(projectId);

            projectDbSession.Repository.Remove(projectToremove);
            projectDbSession.SaveChanges();

            //then
            Assert.Throws <InvalidOperationException>(() =>
            {
                var repProject3 = new ProjectRepository(projectDbContext);
                using var dbs   = new ProjectDbSession(projectDbContext, repProject3);
                return(dbs.Repository.Get(projectId));
            });
        }
Example #2
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);
        }