예제 #1
0
        public async Task ExecuteShouldAddGroupClass()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();
            GroupLevel  groupLevel          = new GroupLevelBuilder(context).With(x => x.Level = 1).With(x => x.Name = "Początkujący").BuildAndSave();
            Room        room                   = new RoomBuilder(context).WithName("Sala biała").BuildAndSave();
            User        anchor                 = new UserBuilder(context).WithEmail("*****@*****.**").BuildAndSave();
            Role        role                   = new RoleBuilder(context).WithName(Roles.Anchor).AddUserToRole(anchor).BuildAndSave();
            List <User> participants           = new List <User>();
            var         participantRoleBuilder = new RoleBuilder(context).WithName(Roles.Participant);

            for (var i = 0; i < 10; i++)
            {
                User user = new UserBuilder(context).WithEmail($"email{i}@gmail.com").BuildAndSave();
                participants.Add(user);
                participantRoleBuilder.AddUserToRole(user);
            }

            participantRoleBuilder.BuildAndSave();

            Command cmd = new Command
            {
                Name    = "Groupa zajęciowa",
                Anchors = new List <string> {
                    anchor.Id
                },
                IsSolo           = true,
                PassPrice        = 200,
                ParticipantLimit = 20,
                GroupLevelId     = groupLevel.Id,
                Participants     = participants.Select(x => new ParticipantDto
                {
                    Id   = x.Id,
                    Role = ParticipantRole.Leader
                }).ToList(),
                DayOfWeeks = new List <ClassDayOfWeekDto>(),
                RoomId     = 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.GroupClass.Should().NotBeEmpty("we add new group");
            GroupClass groupClass = context.GroupClass.First();

            groupClass.Anchors.Should().NotBeEmpty();
            groupClass.Room.Should().Be(room);
            groupClass.GroupLevel.Should().Be(groupLevel);
            groupClass.PassPrice.Should().Be(cmd.PassPrice);
            groupClass.Participants.Should().NotBeEmpty().And.HaveCount(participants.Count).And
            .Contain(x => participants.Contains(x.User));
        }
예제 #2
0
        public async Task ExecuteShouldEditScheduleGroupClass()
        {
            //Arrange
            SchoolManagementContext context = new ContextBuilder().BuildClean();
            GroupLevel groupLevel           = new GroupLevelBuilder(context).With(x => x.Level = 1).With(x => x.Name = "Początkujący").BuildAndSave();
            Room       room   = new RoomBuilder(context).WithName("Sala biała").BuildAndSave();
            User       anchor = new UserBuilder(context).WithEmail("*****@*****.**").BuildAndSave();

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

            for (var i = 0; i < 10; i++)
            {
                User user = new UserBuilder(context).WithEmail($"email{i}@gmail.com").BuildAndSave();
                participants.Add(user);
                participantRoleBuilder.AddUserToRole(user);
            }

            participantRoleBuilder.BuildAndSave();

            string expectedAnchorEmail = "*****@*****.**";
            var    groupClass          = CreateGroupClass(context, expectedAnchorEmail);
            string expectedAnchorId    = groupClass.Anchors.Where(x => x.User.Email == expectedAnchorEmail).Select(x => x.UserId).First();

            Command cmd = new Command
            {
                GroupClassId = groupClass.Id,
                Name         = "Groupa zajęciowa",
                Anchors      = new List <string> {
                    anchor.Id, expectedAnchorId
                },
                IsSolo             = true,
                ParticipantLimit   = 20,
                UtcOffsetInMinutes = 0,
                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(19, 0, 0),
                        DayOfWeek = DayOfWeek.Tuesday
                    },
                    new ClassDayOfWeekDto()
                    {
                        BeginTime = new TimeSpan(18, 0, 0),
                        DayOfWeek = DayOfWeek.Wednesday
                    },
                    new ClassDayOfWeekDto()
                    {
                        BeginTime = new TimeSpan(19, 0, 0),
                        DayOfWeek = DayOfWeek.Friday
                    },
                },
                DurationTimeInMinutes = 90,
                NumberOfClasses       = 24,
                RoomId = room.Id
            };

            var            expectedParticipant = groupClass.Participants.Select(x => x.User).First();
            ParticipantDto expectedRole        = new ParticipantDto()
            {
                Id   = expectedParticipant.Id,
                Role = ParticipantRole.Leader
            };

            cmd.Participants.Add(expectedRole);
            //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.GroupClass.Should().NotBeEmpty("we add new group");
            groupClass.Anchors.Should().NotBeEmpty().And.HaveCount(cmd.Anchors.Count);
            groupClass.Room.Should().Be(room);
            groupClass.IsSolo.Should().BeTrue();
            groupClass.Name.Should().Be(cmd.Name);
            groupClass.GroupLevel.Should().Be(groupLevel);
            groupClass.Participants.Should().NotBeEmpty().And.HaveCount(cmd.Participants.Count).And
            .Contain(x => participants.Contains(x.User));
            groupClass.Participants.Where(x => x.User.Email == expectedParticipant.Email).Select(x => x.Role).First()
            .Should().Be(expectedRole.Role, "we changed role");

            ValidateClassDayOfWeek(groupClass);

            groupClass.Schedule.Should().NotBeNullOrEmpty().And.HaveCount(24).And.OnlyContain(x =>
                                                                                              x.StartDate.DayOfWeek == DayOfWeek.Tuesday || x.StartDate.DayOfWeek == DayOfWeek.Friday ||
                                                                                              x.StartDate.DayOfWeek == DayOfWeek.Wednesday);
        }
예제 #3
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);
            }
        }