public async Task ExecuteShouldSetPresenceAsHelp()
        {
            SchoolManagementContext context = new ContextBuilder().BuildClean();
            User user = new UserBuilder(context).BuildAndSave();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();

            GroupClass makeUpClass = new GroupClassBuilder(context)
                                     .WithStartClasses(DateTime.Now.Subtract(TimeSpan.FromDays(30)))
                                     .WithNumberOfClasses(14)
                                     .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, TimeSpan.FromHours(18)))
                                     .AddParticipant(x => x.WithEmail("*****@*****.**"), ParticipantRole.Follower, passBuilder => passBuilder.AsActive())
                                     .WithTimeDurationInMinutes(90)
                                     .CreateSchedule()
                                     .BuildAndSave();

            ClassTime classTime = context.ClassTimes.First(x => x.GroupClassId == makeUpClass.Id);

            Command command = new Command
            {
                ParticipantId = user.Id,
                ClassTimeId   = classTime.Id
            };

            DataResult dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            dataResult.Status.Should().Be(DataResult.ResultStatus.Success);

            classTime.PresenceParticipants.Should().HaveCount(2);
            classTime.PresenceParticipants[1].WasPresence.Should().BeTrue();
            classTime.PresenceParticipants[1].PresenceType = PresenceType.Help;
        }
        private static GroupClass CreateGroupClass(SchoolManagementContext context, string expectedAnchorEmail)
        {
            var groupClassBuilder = new GroupClassBuilder(context)
                                    .WithName("Stara grupa")
                                    .WithRoom(builder => builder.WithName("Old room"))
                                    .WithGroupLevel(x => x.With(z => z.Name = "Beginner"))
                                    .AddAnchor(user => user.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"))
                                    .AddAnchor(user => user.WithEmail(expectedAnchorEmail).WithName("Kamil", "Kowalski"))
                                    .AddAnchor(user => user.WithEmail("*****@*****.**").WithName("Jan", "Nowak"))
                                    .AddParticipant(user => user.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"), ParticipantRole.Follower)
                                    .AddParticipant(user => user.WithEmail("*****@*****.**").WithName("Kamil", "Kowalski"), ParticipantRole.Leader)
                                    .AddParticipant(user => user.WithEmail("*****@*****.**").WithName("Jan", "Nowak"), ParticipantRole.Follower)
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Wednesday, new TimeSpan(18, 0, 0)))
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Friday, new TimeSpan(18, 0, 0)))
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Saturday, new TimeSpan(18, 0, 0)))
                                    .WithStartClasses(new DateTime(2019, 09, 02, 0, 0, 0))
                                    .WithTimeDurationInMinutes(90)
                                    .WithNumberOfClasses(24)
                                    .CreateSchedule();



            var groupClass = groupClassBuilder.BuildAndSave();

            return(groupClass);
        }
        public async Task ExecuteShouldThrowWrongType()
        {
            SchoolManagementContext context = new ContextBuilder().BuildClean();
            User user = new UserBuilder(context).BuildAndSave();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();
            GroupClass groupClassToMakeUp = new GroupClassBuilder(context)
                                            .WithStartClasses(DateTime.Now.Subtract(TimeSpan.FromDays(30)))
                                            .WithNumberOfClasses(14)
                                            .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, TimeSpan.FromHours(18)))
                                            .AddParticipant(x => x.WithUser(user), ParticipantRole.Follower, passBuilder => passBuilder.AsActive())
                                            .WithTimeDurationInMinutes(90)
                                            .CreateSchedule()
                                            .BuildAndSave();

            List <ParticipantClassTime> participantClassTimes = context.ParticipantPresences.ToList();

            for (int i = 0; i < participantClassTimes.Count - 5; i++)
            {
                participantClassTimes[i].WasPresence  = true;
                participantClassTimes[i].PresenceType = PresenceType.Member;
            }

            ParticipantClassTime makeUpParticipantClassTime = participantClassTimes[participantClassTimes.Count - 5];

            makeUpParticipantClassTime.PresenceType = PresenceType.MakeUp;
            context.UpdateRange(participantClassTimes);
            context.SaveChanges();

            GroupClass makeUpClass = new GroupClassBuilder(context)
                                     .WithStartClasses(DateTime.Now.Subtract(TimeSpan.FromDays(30)))
                                     .WithNumberOfClasses(14)
                                     .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, TimeSpan.FromHours(18)))
                                     .AddParticipant(x => x.WithEmail("*****@*****.**"), ParticipantRole.Follower, passBuilder => passBuilder.AsActive())
                                     .AddParticipant(x => x.WithUser(user), ParticipantRole.Follower)
                                     .WithTimeDurationInMinutes(90)
                                     .CreateSchedule()
                                     .BuildAndSave();

            ClassTime            classTime       = context.ClassTimes.Last(x => x.GroupClassId == makeUpClass.Id);
            ParticipantClassTime newUserToRemove = classTime.PresenceParticipants.Last();

            newUserToRemove.MakeUpParticipant   = makeUpParticipantClassTime;
            newUserToRemove.MakeUpParticipantId = makeUpParticipantClassTime.Id;
            newUserToRemove.PresenceType        = PresenceType.Help;
            context.Update(newUserToRemove);
            context.SaveChanges();
            Command command = new Command
            {
                ParticipantId = user.Id,
                ClassTimeId   = classTime.Id
            };

            DataResult dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            dataResult.Status.Should().Be(DataResult.ResultStatus.Error);
            dataResult.Message.Should().Be(PolishReadableMessage.Presence.RemoveWrongType);

            classTime.PresenceParticipants.Should().HaveCount(2);
        }
        public async Task ExecuteShouldThrowExceptionParticipantNotFound()
        {
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();
            GroupClass groupClassToMakeUp = new GroupClassBuilder(context)
                                            .WithStartClasses(DateTime.Now.Subtract(TimeSpan.FromDays(30)))
                                            .WithNumberOfClasses(14)
                                            .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, TimeSpan.FromHours(18)))
                                            .AddParticipant(x => x.WithEmail("*****@*****.**"), ParticipantRole.Follower, passBuilder => passBuilder.AsActive())
                                            .WithTimeDurationInMinutes(90)
                                            .CreateSchedule()
                                            .BuildAndSave();
            ClassTime classTime = groupClassToMakeUp.Schedule.First();
            Command   command   = new Command
            {
                ParticipantId = "dsad",
                ClassTimeId   = classTime.Id
            };

            DataResult dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            dataResult.Status.Should().Be(DataResult.ResultStatus.Error);
            dataResult.Message.Should().Be(PolishReadableMessage.Presence.ParticipantNotFound);
        }
Exemple #5
0
        public async Task ExecuteShouldChangePresenceForMemberAndGetPassEntry()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();

            GroupClass groupClass = new GroupClassBuilder(context)
                                    .WithStartClasses(DateTime.Now)
                                    .WithTimeDurationInMinutes(90)
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                                    .AddParticipant(userBuilder => userBuilder.WithName("Piotr", "Kowalski"), ParticipantRole.Follower,
                                                    passBuilder => passBuilder.WithNumberOfEntry(2))
                                    .WithName("Boogie woogie")
                                    .WithNumberOfClasses(5)
                                    .CreateSchedule().BuildAndSave();

            User      participant = context.Users.First();
            ClassTime classTime   = context.ClassTimes.First();
            Command   command     = new Command
            {
                ClassTimeId   = classTime.Id,
                ParticipantId = participant.Id,
                IsPresence    = true,
                PresenceType  = PresenceType.Member
            };

            //Act
            DataResult dataResult = await new Handler(context).Handle(command, CancellationToken.None);
            //Assert
            ParticipantClassTime participantClassTime = classTime.PresenceParticipants.First();

            participantClassTime.WasPresence.Should().BeTrue("we set presence");
        }
Exemple #6
0
        public async Task ExecuteShouldRemoveGroup()
        {
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Anchor).BuildAndSave();
            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();
            var groupClass = new GroupClassBuilder(context)
                             .WithName("Stara grupa")
                             .WithRoom(builder => builder.WithName("Old room"))
                             .WithGroupLevel(x => x.With(z => z.Name = "Beginner"))
                             .AddAnchor(user => user.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"))
                             .AddParticipant(user => user.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"), ParticipantRole.Follower)
                             .AddParticipant(user => user.WithEmail("*****@*****.**").WithName("Jan", "Nowak"), ParticipantRole.Follower).BuildAndSave();

            Command cmd = new Command
            {
                Id = groupClass.Id
            };

            DataResult dataResult = await new Handler(context).Handle(cmd, CancellationToken.None);


            dataResult.Status.Should().Be(DataResult.ResultStatus.Success);
            context.GroupClass.Should().BeEmpty("we remove this group");
        }
        public async Task ExecuteShouldGetSecondPassWhenFirstIsUsed()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();

            GroupClass groupClass = new GroupClassBuilder(context)
                                    .WithStartClasses(DateTime.Now)
                                    .WithTimeDurationInMinutes(90)
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                                    .AddParticipant(userBuilder => userBuilder.WithName("Piotr", "Kowalski"), ParticipantRole.Follower,
                                                    passBuilder => passBuilder.WithNumberOfEntry(2).AsActive())
                                    .WithName("Boogie woogie")
                                    .WithNumberOfClasses(1)
                                    .CreateSchedule().BuildAndSave();
            User participant = context.Users.First();
            ParticipantGroupClass participantGroupClass = context.GroupClassMembers.First();

            new PassBuilder(context)
            .WithNumberOfEntry(5)
            .WithStartDate(groupClass.StartClasses)
            .With(x => x.Used = 5)
            .With(x => x.Id   = 4)
            .WithParticipant(participant)
            .WithParticipantGroupClass(participantGroupClass).BuildAndSave();

            ClassTime            classTime            = context.ClassTimes.First();
            ParticipantClassTime participantClassTime = classTime.PresenceParticipants.First();

            participantClassTime.WasPresence  = true;
            participantClassTime.PresenceType = PresenceType.Member;
            Command command = new Command
            {
                ParticipantClassTimeId = participantClassTime.Id
            };


            //Act
            DataResult <PassMessage> dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            //Assert
            participantClassTime.PassId.Should().NotBeNull("all presence member have to contains pass entry");
            Pass activePass = context.Passes.First(x => x.Status == Pass.PassStatus.Active);

            activePass.Used.Should().Be(1);
            activePass.ParticipantClassTimes.Should().HaveCount(1);
            Pass noActivePass = context.Passes.First(x => x.Status == Pass.PassStatus.NotActive);

            noActivePass.Used.Should().Be(5);
            dataResult.Data.Should().NotBeNull();
        }
        public async Task WhenPassIsOutThenDuplicateAndMarkAsNotPaidAndLogEntryFromNew()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();

            GroupClass groupClass = new GroupClassBuilder(context)
                                    .WithStartClasses(DateTime.Now)
                                    .WithTimeDurationInMinutes(90)
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                                    .AddParticipant(userBuilder => userBuilder.WithName("Piotr", "Kowalski"), ParticipantRole.Follower,
                                                    passBuilder => passBuilder.WithNumberOfEntry(2).AsActive())
                                    .WithName("Boogie woogie")
                                    .WithNumberOfClasses(5)
                                    .CreateSchedule().BuildAndSave();

            User                 participant          = context.Users.First();
            ClassTime            classTime            = context.ClassTimes.First();
            ParticipantClassTime participantClassTime = classTime.PresenceParticipants.First();

            participantClassTime.WasPresence  = true;
            participantClassTime.PresenceType = PresenceType.Member;

            Command command = new Command
            {
                ParticipantClassTimeId = participantClassTime.Id
            };


            Pass oldPass = context.Passes.OrderBy(x => x.Id).First();

            oldPass.NumberOfEntry = 10;
            oldPass.Status        = Pass.PassStatus.NotActive;
            oldPass.Used          = 10;

            //Act
            DataResult <PassMessage> dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            //Assert
            participantClassTime.PassId.Should().NotBeNull("presence for make up have to contain pass ");
            context.Passes.Should().HaveCount(2);
            Pass newPass = context.Passes.OrderBy(x => x.Id).Last();

            newPass.WasGenerateAutomatically.Should().BeTrue("we generate this pass");
            newPass.Status.Should().Be(Pass.PassStatus.Active);
            newPass.Used.Should().Be(1);
            newPass.Start.Should().Be(participantClassTime.ClassTime.StartDate);
            newPass.ParticipantClassTimes.Should().HaveCount(1);
            dataResult.Data.Should().NotBeNull();
        }
Exemple #9
0
        public async Task ExecuteShouldReturnPassAndRemoveWhenItWasGenerated()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();

            new RoleBuilder(context).WithName(Roles.Participant).BuildAndSave();

            GroupClass groupClass = new GroupClassBuilder(context)
                                    .WithStartClasses(DateTime.Now)
                                    .WithTimeDurationInMinutes(90)
                                    .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                                    .AddParticipant(userBuilder => userBuilder.WithName("Piotr", "Kowalski"), ParticipantRole.Follower,
                                                    passBuilder => passBuilder.WithNumberOfEntry(2).AsActive())
                                    .WithName("Boogie woogie")
                                    .WithNumberOfClasses(5)
                                    .CreateSchedule().BuildAndSave();

            ParticipantGroupClass participantGroupClass = groupClass.Participants.First();
            ParticipantClassTime  participantClassTime  = context.ParticipantPresences.First();
            Pass pass = new PassBuilder(context)
                        .WithParticipant(participantGroupClass.User)
                        .WithParticipantGroupClass(participantGroupClass)
                        .WithNumberOfEntry(2)
                        .With(x => x.ParticipantClassTimes.Add(participantClassTime))
                        .With(x => x.Used = 0).BuildAndSave();
            Pass generatedPass = new PassBuilder(context).AsActive()
                                 .WithParticipant(participantGroupClass.User)
                                 .WithParticipantGroupClass(participantGroupClass)
                                 .With(x => x.WasGenerateAutomatically = true)
                                 .WithNumberOfEntry(2)
                                 .With(x => x.ParticipantClassTimes.Add(participantClassTime))
                                 .With(x => x.Used = 0).BuildAndSave();

            PassAggregate.FromState(generatedPass).UsePass(participantClassTime);
            context.Update(participantClassTime);
            await context.SaveChangesAsync();

            Command command = new Command
            {
                ParticipantId = participantGroupClass.UserId,
                ClassTimeId   = participantClassTime.ClassTimeId
            };
            //Act
            DataResult dataResult = await new Handler(context).Handle(command, CancellationToken.None);

            //Assert
            context.Passes.Should().NotContain(generatedPass);
            context.Passes.Should().Contain(pass);
            pass.Used.Should().Be(0);
        }
        public async Task ExecuteShouldEditAddNewDayOfWeekWithNewUser()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();
            GroupLevel groupLevel           = new GroupLevelBuilder(context).With(x => x.Level = 1).With(x => x.Name = "Początkujący").BuildAndSave();

            new RoleBuilder(context).WithName(Roles.Anchor).BuildAndSave();
            List <User> participants           = new List <User>();
            var         participantRoleBuilder = new RoleBuilder(context).WithName(Roles.Participant);

            User user = new UserBuilder(context).WithEmail($"email{5}@gmail.com").BuildAndSave();

            participants.Add(user);
            participantRoleBuilder.AddUserToRole(user).BuildAndSave();

            var groupClass = new GroupClassBuilder(context)
                             .WithName("Stara grupa")
                             .WithRoom(builder => builder.WithName("Old room"))
                             .WithGroupLevel(x => x.With(z => z.Name = "Beginner"))
                             .AddAnchor(anchor => anchor.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"))
                             .AddParticipant(aprticipant => aprticipant.WithEmail("*****@*****.**").WithName("Jan", "Kowalski"), ParticipantRole.Follower)
                             .AddClassDayOfWeek(x => x.WithDate(DayOfWeek.Monday, new TimeSpan(18, 0, 0)))
                             .WithStartClasses(new DateTime(2019, 09, 02, 0, 0, 0))
                             .WithTimeDurationInMinutes(90)
                             .WithNumberOfClasses(10)
                             .CreateSchedule().BuildAndSave();

            participants.Add(groupClass.Participants.First().User);

            Command cmd = new Command
            {
                GroupClassId = groupClass.Id,
                Name         = "Groupa zajęciowa",
                Anchors      = new List <string> {
                    groupClass.Anchors.First().UserId
                },
                IsSolo           = true,
                ParticipantLimit = 20,
                Start            = groupClass.StartClasses,
                GroupLevelId     = groupLevel.Id,
                Participants     = participants.Select(x => new ParticipantDto
                {
                    Id   = x.Id,
                    Role = ParticipantRole.Leader
                }).ToList(),
                DayOfWeeks = new List <ClassDayOfWeekDto>
                {
                    new ClassDayOfWeekDto()
                    {
                        BeginTime = new TimeSpan(18, 0, 0),
                        DayOfWeek = DayOfWeek.Monday
                    },
                    new ClassDayOfWeekDto()
                    {
                        BeginTime = new TimeSpan(20, 0, 0),
                        DayOfWeek = DayOfWeek.Wednesday
                    }
                },
                DurationTimeInMinutes = 90,
                UtcOffsetInMinutes    = 0,
                NumberOfClasses       = 10,
                RoomId = groupClass.Room.Id
            };


            //Act
            DataResult result = await new Handler(context).Handle(cmd, CancellationToken.None);

            //Assert
            result
            .Should().NotBeNull();
            result.Status.Should().Be(DataResult.ResultStatus.Success, "all parameters are corrected");


            context.ClassTimes.Should().HaveCount(cmd.NumberOfClasses);
            context.ParticipantPresences.Should().HaveCount(cmd.NumberOfClasses * cmd.Participants.Count);
            foreach (var contextClassTime in context.ClassTimes)
            {
                contextClassTime.PresenceParticipants.Should().HaveCount(2);
            }
        }