public async Task GetActiveParticipationsAsync_Should_Include_Project_And_Person()
        {
            //Arrange
            Project       project       = ProjectSeed.Seed().First();
            Person        person        = PersonSeed.Seed().First();
            Participation participation = new Participation()
            {
                ProjectId = project.Id,
                PersonId  = person.Id,
            };

            participationRepositoryMock.Object.Add(participation);
            roosterPlannerContextMock.Object.SaveChanges();

            //Act
            List <Participation> participations =
                await participationRepositoryMock.Object.GetActiveParticipationsAsync(person.Id);

            //Assert
            foreach (Participation participation1 in participations)
            {
                Assert.NotNull(participation1.Project);
                Assert.NotNull(participation1.Person);
            }
        }
        public ActionResult <IEnumerable <Project> > Get()
        {
            var ps = HttpContext.Session.GetObject <ProjectSeed>(Constants.KEY);

            if (ps == null)
            {
                ps = new ProjectSeed();
                ps.FillProjectList();
                HttpContext.Session.SetObject(Constants.KEY, ps);
            }

            return(ps.Projects);
        }
        public BaseUnitTest()
        {
            roosterPlannerContextMock = CreateContextMock();
            roosterPlannerContextMock.Object.Projects.AddRange(ProjectSeed.Seed());
            roosterPlannerContextMock.Object.Persons.AddRange(PersonSeed.Seed());
            roosterPlannerContextMock.Object.Managers.AddRange(ManagerSeed.Seed());
            roosterPlannerContextMock.Object.Requirements.AddRange(RequirementSeed.Seed());
            roosterPlannerContextMock.Object.CertificateTypes.AddRange(CertificateTypeSeed.Seed());
            roosterPlannerContextMock.Object.Documents.AddRange(DocumentSeed.Seed());
            roosterPlannerContextMock.Object.Participations.AddRange(ParticipationSeed.Seed());
            roosterPlannerContextMock.Object.Tasks.AddRange(TaskSeed.Seed());
            roosterPlannerContextMock.Object.Categories.AddRange(CategorySeed.Seed());

            roosterPlannerContextMock.Object.SaveChanges();
        }
Exemple #4
0
        public async Task GetProjectManagersAsync_Should_Include_Related_Data()
        {
            //Arrange
            Guid projectId = ProjectSeed.Seed().First().Id;
            //Act
            List <Manager> managers = await managerRepositoryMock.Object.GetProjectManagersAsync(projectId);

            //Assert
            Assert.NotNull(managers);
            Assert.NotEmpty(managers);
            foreach (Manager manager in managers)
            {
                Assert.NotNull(manager.Person);
                Assert.NotNull(manager.Project);
                Assert.Equal(projectId, manager.ProjectId);
            }
        }
        public async Task GetActiveParticipationsAsync_Should_Include_ParticipationEndDate_Is_Null()
        {
            //Arrange
            Project project = ProjectSeed.Seed().First();

            project.ParticipationEndDate = null;
            Person person = PersonSeed.Seed().First();

            roosterPlannerContextMock.Object.SaveChanges();

            //Act
            List <Participation> participations =
                await participationRepositoryMock.Object.GetActiveParticipationsAsync(person.Id);

            //Assert
            Assert.NotEmpty(participations);
        }
        public async Task GetSpecificParticipationAsync_Should_Include_Related_Data()
        {
            //Arrange
            Guid person    = PersonSeed.Seed().First().Id;
            Guid projectId = ProjectSeed.Seed().First().Id;


            //Act
            Participation locatedParticipation =
                await participationRepositoryMock.Object.GetSpecificParticipationAsync(person, projectId);

            //Assert
            Assert.NotNull(locatedParticipation);
            Assert.Equal(person, locatedParticipation.PersonId);
            Assert.Equal(projectId, locatedParticipation.ProjectId);
            Assert.NotNull(locatedParticipation.Person);
            Assert.NotNull(locatedParticipation.Project);
            Assert.NotNull(locatedParticipation.Project.PictureUri);
        }
Exemple #7
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //Call base method first.
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <ProjectTask>(p =>
            {
                p.HasOne(pt => pt.Project)
                .WithMany(pt => pt.ProjectTasks)
                .HasForeignKey(pt => pt.ProjectId);

                p.HasOne(pt => pt.Task)
                .WithMany(t => t.ProjectTasks)
                .HasForeignKey(pt => pt.TaskId)
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <Project>(pro =>
            {
                pro.HasMany(pt => pt.ProjectTasks)
                .WithOne(p => p.Project);
                pro.HasMany(p => p.Participations)
                .WithOne(x => x.Project);
            });

            modelBuilder.Entity <Task>(tsk =>
            {
                tsk
                .HasMany(t => t.ProjectTasks)
                .WithOne(t => t.Task);

                tsk.HasMany(s => s.Shifts)
                .WithOne(t => t.Task)
                .OnDelete(DeleteBehavior.SetNull);
                tsk
                .HasMany(t => t.Requirements)
                .WithOne(t => t.Task);
            });

            modelBuilder.Entity <Document>(doc =>
            {
                doc.HasMany(d => d.Instructions)
                .WithOne(i => i.Instruction)
                .OnDelete(DeleteBehavior.SetNull);
                doc.HasMany(d => d.ProfilePictures)
                .WithOne(i => i.ProfilePicture)
                .OnDelete(DeleteBehavior.SetNull);
            });

            modelBuilder.Entity <Category>(cat =>
            {
                cat.HasMany(c => c.Tasks)
                .WithOne(t => t.Category)
                .OnDelete(DeleteBehavior.SetNull);
            });

            modelBuilder.Entity <Person>(p =>
            {
                p.HasIndex(per => per.Oid)
                .IsUnique();
                p.HasMany(cer => cer.Certificates)
                .WithOne(x => x.Person);
                p.HasMany(par => par.Participations)
                .WithOne(x => x.Person);
            });

            modelBuilder.Entity <Availability>(ava =>
            {
                ava.HasOne(p => p.Participation)
                .WithMany(a => a.Availabilities)
                .HasForeignKey(a => a.ParticipationId)
                .OnDelete(DeleteBehavior.Restrict);
                ava.HasOne(s => s.Shift)
                .WithMany(a => a.Availabilities)
                .HasForeignKey(a => a.ShiftId)
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <Participation>(par =>
            {
                par.HasMany(m => m.Availabilities)
                .WithOne(p => p.Participation);
                par.HasOne(p => p.Person)
                .WithMany(ppar => ppar.Participations)
                .HasForeignKey(ppar => ppar.PersonId);
                par.HasOne(p => p.Project)
                .WithMany(ppar => ppar.Participations)
                .HasForeignKey(ppar => ppar.ProjectId);
            });

            modelBuilder.Entity <Shift>(shf =>
            {
                shf.HasMany(m => m.Availabilities)
                .WithOne(t => t.Shift);
            });

            modelBuilder.Entity <Certificate>(cer =>
            {
                cer.HasOne(p => p.Person)
                .WithMany(c => c.Certificates)
                .HasForeignKey(c => c.PersonId);
                cer.HasOne(ct => ct.CertificateType)
                .WithMany(c => c.Certificates)
                .HasForeignKey(c => c.CertificateTypeId)
                .OnDelete(DeleteBehavior.SetNull);
            });

            modelBuilder.Entity <CertificateType>(ct =>
            {
                ct.HasMany(c => c.Certificates)
                .WithOne(x => x.CertificateType);
                ct.HasMany(c => c.Requirements)
                .WithOne(req => req.CertificateType);
            });

            modelBuilder.Entity <Requirement>(req =>
            {
                req.HasOne(t => t.Task)
                .WithMany(reqt => reqt.Requirements)
                .HasForeignKey(reqt => reqt.TaskId)
                .OnDelete(DeleteBehavior.Cascade);
                req.HasOne(cer => cer.CertificateType)
                .WithMany(reqt => reqt.Requirements)
                .HasForeignKey(reqt => reqt.CertificateTypeId)
                .OnDelete(DeleteBehavior.Cascade);
            });

            var categorySeed = new CategorySeed(modelBuilder);

            categorySeed.Seed();

            var personSeed = new PersonSeed(modelBuilder);

            personSeed.Seed();

            var projectseed = new ProjectSeed(modelBuilder);

            projectseed.Seed();

            var participationSeed = new ParticipationSeed(modelBuilder);

            participationSeed.Seed();

            var taskseed = new TaskSeed(modelBuilder);

            taskseed.Seed();

            var documentSeed = new DocumentSeed(modelBuilder);

            documentSeed.Seed();

            var certificateTypeSeed = new CertificateTypeSeed(modelBuilder);

            certificateTypeSeed.Seed();
        }
        private List <Project> CreateProjects()
        {
            List <Project> projects = ProjectSeed.Seed();

            return(projects);
        }
        public async System.Threading.Tasks.Task Get_Should_Include_Related_Entities()
        {
            //Arrange
            //Act
            Project project = await projectRepositoryMock.Object.GetProjectDetailsAsync(ProjectSeed.Seed()[0].Id);

            //Assert
            Assert.NotNull(project.PictureUri);
            Assert.NotNull(project.ProjectTasks);
        }