Ejemplo n.º 1
0
        public async void POST_Sessions_In_StudentAlreadySignedIn_ShouldReturn500WithMessage()
        {
            var session = new KioskSignInDTO()
            {
                PersonId        = 2,
                Tutoring        = false,
                SelectedClasses = new List <int> ()
                {
                    1, 2
                },
                SelectedReasons = new List <int> ()
                {
                    1
                }
            };

            var client = _factory.CreateClient();

            await client.PostAsJsonAsync("api/sessions/in", session);

            var response = await client.PostAsJsonAsync("api/sessions/in", session);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
            var errorMessage = await response.Content.ReadAsAsync <ErrorMessage> ();

            Assert.Equal("You are already signed in.", errorMessage.Message);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SignIn([FromBody] KioskSignInDTO signIn)
        {
            var person = await _personRepo.Find(x => x.Id == signIn.PersonId);

            if (person.PersonType == PersonType.Teacher)
            {
                var teacherSession = new Session()
                {
                    InTime       = DateTime.Now,
                    PersonId     = signIn.PersonId,
                    SemesterCode = _semesterRepo.GetAll().Last().Code
                };
                var teacherResult = await _sessionRepo.Create(teacherSession);

                if (teacherResult is Session)
                {
                    return(Created($"sessions/{teacherResult.Id}", teacherResult));
                }
                throw new TCSException("Something went wrong");
            }

            if (!signIn.Tutoring && signIn.SelectedReasons.Count() < 1)
            {
                throw new TCSException("Must select 1 or more reasons for visiting.");
            }

            var alreadySignedIn = await _sessionRepo.Exist(x => x.PersonId == signIn.PersonId && x.OutTime == null);

            if (alreadySignedIn)
            {
                throw new TCSException("You are already signed in.");
            }

            var session = new Session()
            {
                InTime         = DateTime.Now,
                SessionClasses = signIn.SelectedClasses.Select(x => new SessionClass()
                {
                    ClassId = x
                }).ToList(),
                SessionReasons = signIn.SelectedReasons.Select(x => new SessionReason()
                {
                    ReasonId = x
                }).ToList(),
                PersonId     = signIn.PersonId,
                SemesterCode = _semesterRepo.GetAll().Last().Code,
                Tutoring     = signIn.Tutoring
            };

            var result = await _sessionRepo.Create(session);

            if (result is Session)
            {
                return(Created($"sessions/{result.Id}", result));
            }
            throw new TCSException("Something went wrong");
        }
Ejemplo n.º 3
0
        public async void POST_Session_In_TeacherSignsIn_ShouldReturn201()
        {
            var session = new KioskSignInDTO()
            {
                PersonId = 771771771
            };

            var client = _factory.CreateClient();

            var response = await client.PostAsJsonAsync("api/sessions/in", session);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
Ejemplo n.º 4
0
        public async void POST_Session_In_StudentSelectsNoReasonsWithTutoringFalse_ShouldReturn500WithMessage()
        {
            var session = new KioskSignInDTO()
            {
                PersonId        = 7,
                Tutoring        = false,
                SelectedClasses = new List <int> ()
                {
                    1, 2
                },
                SelectedReasons = new List <int> ()
                {
                }
            };

            var client = _factory.CreateClient();

            var response = await client.PostAsJsonAsync("api/sessions/in", session);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Ejemplo n.º 5
0
        public async void POST_Sessions_In_StudentSelectsNoReasonsWithTutoringTrue_ShouldReturn201()
        {
            var session = new KioskSignInDTO()
            {
                PersonId        = 7,
                Tutoring        = true,
                SelectedClasses = new List <int> ()
                {
                    1, 2
                },
                SelectedReasons = new List <int> ()
                {
                }
            };

            var client = _factory.CreateClient();

            var response = await client.PostAsJsonAsync("api/sessions/in", session);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }