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);
            }
        }
Esempio n. 2
0
        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();
        }
        public async Task GetParticipations_Should_Include_Project()
        {
            //Arrange


            //Act
            List <Participation> participations = await participationRepositoryMock.Object.GetParticipations(
                Guid.Parse("55c92c6a-067b-442a-b33d-b8ce35cf1d8a"));

            //Assert
            Assert.Equal(PersonSeed.Seed().Count, participations.Count);
            foreach (Participation participation in participations)
            {
                Assert.NotNull(participation.Project);
            }
        }
        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);
        }
        public async Task GetActiveParticipationsAsync_Should_Filter_Closed_Projects()
        {
            //Arrange
            await foreach (Project project in roosterPlannerContextMock.Object.Projects)
            {
                project.Closed = true;
                roosterPlannerContextMock.Object.Projects.Update(project);
            }

            Person person = PersonSeed.Seed().First();

            roosterPlannerContextMock.Object.SaveChanges();

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

            //Assert
            Assert.Empty(participations);
        }
        public async Task GetActiveParticipationsAsync_Should_Filter_Inactive_Participations()
        {
            //Arrange

            Person person = PersonSeed.Seed().First();

            await foreach (Participation participation in roosterPlannerContextMock.Object.Participations)
            {
                participation.Active = false;
                roosterPlannerContextMock.Object.Participations.Update(participation);
            }

            roosterPlannerContextMock.Object.SaveChanges();

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

            //Assert
            Assert.Empty(participations);
        }
        public async Task GetActiveParticipationsAsync_Should_Filter_ParticipationEndDate_In_The_Past()
        {
            //Arrange
            Project project = roosterPlannerContextMock.Object.Projects.First();

            project.ParticipationEndDate = DateTime.Today.AddDays(-7);
            Person person = PersonSeed.Seed().First();

            roosterPlannerContextMock.Object.Projects.Update(project);
            roosterPlannerContextMock.Object.SaveChanges();

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

            //Assert
            foreach (Participation participation in participations)
            {
                Assert.NotEqual(project.Id, participation.ProjectId);
            }
        }
Esempio n. 9
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();
        }