Example #1
0
        public void CheckInNewStudentNoSID()
        {
            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Unit.Add(unit);
                context.SaveChanges();
            }

            CheckInRequest request = new CheckInRequest()
            {
                UnitID   = unit.UnitId,
                Nickname = AlphaNumericStringGenerator.GetString(10)
            };

            CheckInFacade facade = new CheckInFacade();

            CheckInResponse response = facade.CheckIn(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
Example #2
0
        public TestDataTimeSpan AddTimeSpan(int?helpdeskID = null, string name = "", DateTime?startDate = null, DateTime?endDate = null)
        {
            var request = new AddTimeSpanRequest();

            if (helpdeskID != null)
            {
                request.HelpdeskId = (int)helpdeskID;
            }

            if (name == "" && PopulateEmptyStrings)
            {
                request.Name = AlphaNumericStringGenerator.GetString(10);
            }
            else
            {
                request.Name = name;
            }

            if (startDate == null)
            {
                request.StartDate = DateTime.Now;
            }

            if (endDate == null)
            {
                request.EndDate = DateTime.Now;
                request.EndDate.AddDays(1);
            }

            var response = HelpdeskFacade.AddTimeSpan(request);

            TestDataTimeSpan data = new TestDataTimeSpan(request, response);

            return(data);
        }
        public void GetActiveHelpdesks()
        {
            var factory = new TestEntityFactory();

            var hd1 = factory.AddHelpdesk(AlphaNumericStringGenerator.GetString(10));
            var hd2 = factory.AddHelpdesk(AlphaNumericStringGenerator.GetString(10));

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var helpdesk = context.Helpdesksettings.FirstOrDefault(hd => hd.HelpdeskId == hd2.Response.HelpdeskID);

                helpdesk.IsDeleted = true;
                context.SaveChanges();
            }

            var facade   = new HelpdeskFacade();
            var response = facade.GetActiveHelpdesks();

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.Helpdesks.Count > 0);

            List <int> helpdeskIds = response.Helpdesks.Select(hd => hd.HelpdeskID).ToList();

            Assert.IsTrue(helpdeskIds.Contains(hd1.Response.HelpdeskID));
            Assert.IsTrue(!helpdeskIds.Contains(hd2.Response.HelpdeskID));
        }
Example #4
0
        public void CheckInNoUnit()
        {
            Nicknames nickname = new Nicknames()
            {
                NickName = AlphaNumericStringGenerator.GetString(10),
                Sid      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Nicknames.Add(nickname);
                context.SaveChanges();
            }

            CheckInRequest request = new CheckInRequest()
            {
                SID = nickname.Sid
            };

            CheckInFacade facade = new CheckInFacade();

            CheckInResponse response = facade.CheckIn(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
Example #5
0
        public TestDataNickname AddNickname(string sID = "", string nickname = "")
        {
            var request = new AddStudentRequest();

            if (sID != null)
            {
                if (sID == "" && PopulateEmptyStrings)
                {
                    request.SID = AlphaNumericStringGenerator.GetStudentIDString();
                }
                else
                {
                    request.SID = sID;
                }
            }
            if (nickname != null)
            {
                if (nickname == "" && PopulateEmptyStrings)
                {
                    request.Nickname = AlphaNumericStringGenerator.GetString(20);
                }
                else
                {
                    request.Nickname = nickname;
                }
            }

            var response = StudentFacade.AddStudentNickname(request);

            TestDataNickname data = new TestDataNickname(request, response);

            return(data);
        }
Example #6
0
        public void GetUsers()
        {
            UsersFacade usersFacade = new UsersFacade();

            AddUserRequest addUserRequest = new AddUserRequest()
            {
                Username        = AlphaNumericStringGenerator.GetString(10),
                Password        = AlphaNumericStringGenerator.GetString(10),
                PasswordConfirm = AlphaNumericStringGenerator.GetString(10)
            };

            AddUserResponse addUserResponse = usersFacade.AddUser(addUserRequest);

            Assert.AreEqual(HttpStatusCode.OK, addUserResponse.Status);

            GetUsersResponse getUsersResponse = usersFacade.GetUsers();

            Assert.AreEqual(HttpStatusCode.OK, getUsersResponse.Status);
            Assert.IsNotNull(getUsersResponse.Users.Find(u => u.UserId == addUserResponse.UserId));

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var users = context.User.ToList();

                Assert.IsNotNull(users);
            }
        }
        public void UpdateTimespanNoName()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest()
            {
                HelpdeskId = 1,
                StartDate  = DateTime.Today,
                EndDate    = DateTime.Today.AddYears(1),
                Name       = AlphaNumericStringGenerator.GetString(10)
            };

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

            Assert.AreEqual(HttpStatusCode.OK, addTimeSpanResponse.Status);

            UpdateTimeSpanRequest updateTimespanRequest = new UpdateTimeSpanRequest()
            {
                StartDate = new DateTime(2019, 01, 01),
                EndDate   = new DateTime(2019, 06, 01),
            };

            UpdateTimeSpanResponse updateTimespanResponse = helpdeskFacade.UpdateTimeSpan(addTimeSpanResponse.SpanId, updateTimespanRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, updateTimespanResponse.Status);
        }
        public void GetStudentByNickname()
        {
            AddStudentRequest request = new AddStudentRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            var facade   = new StudentFacade();
            var response = facade.AddStudentNickname(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.StudentID > 0);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var student = context.Nicknames.FirstOrDefault(p => p.StudentId == response.StudentID);
                Assert.IsNotNull(student);
            }

            var getResponse = facade.GetStudentByNickname(request.Nickname);

            Assert.AreEqual(HttpStatusCode.OK, getResponse.Status);
            Assert.IsNotNull(getResponse.Nickname);
        }
        public void ValidateNicknameOldInValid()
        {
            Nicknames nickname = new Nicknames()
            {
                NickName = AlphaNumericStringGenerator.GetString(10),
                Sid      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Nicknames.Add(nickname);
                context.SaveChanges();
            }

            ValidateNicknameRequest request = new ValidateNicknameRequest()
            {
                Name = nickname.NickName,
                SID  = AlphaNumericStringGenerator.GetStudentIDString()
            };

            var facade = new StudentFacade();

            var response = facade.ValidateNickname(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
Example #10
0
        public void UpdateUserUsernameExists()
        {
            UsersFacade usersFacade = new UsersFacade();

            AddUserRequest addUserRequest = new AddUserRequest()
            {
                Username        = AlphaNumericStringGenerator.GetString(10),
                Password        = AlphaNumericStringGenerator.GetString(10),
                PasswordConfirm = AlphaNumericStringGenerator.GetString(10)
            };

            AddUserRequest addUserRequest2 = new AddUserRequest()
            {
                Username        = AlphaNumericStringGenerator.GetString(10),
                Password        = AlphaNumericStringGenerator.GetString(10),
                PasswordConfirm = AlphaNumericStringGenerator.GetString(10)
            };

            AddUserResponse addUserResponse  = usersFacade.AddUser(addUserRequest);
            AddUserResponse addUserResponse2 = usersFacade.AddUser(addUserRequest2);

            Assert.AreEqual(HttpStatusCode.OK, addUserResponse.Status);

            UpdateUserRequest updateUserRequest = new UpdateUserRequest()
            {
                Username = addUserResponse.Username,
                Password = AlphaNumericStringGenerator.GetString(10)
            };

            UpdateUserResponse updateUserResponse = usersFacade.UpdateUser(addUserResponse2.UserId, updateUserRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, updateUserResponse.Status);
        }
        /// <summary>
        /// Used to generate a new random nickname for admin purposes
        /// </summary>
        /// <returns>The response containing the nickname</returns>
        public GenerateNicknameResponse GenerateNickname()
        {
            var response = new GenerateNicknameResponse();

            try
            {
                string nickname = AlphaNumericStringGenerator.GetString(20);

                var dataLayer = new StudentDatalayer();

                var existingUsername = dataLayer.GetStudentNicknameByNickname(nickname);

                while (existingUsername != null)
                {
                    nickname         = AlphaNumericStringGenerator.GetString(20);
                    existingUsername = dataLayer.GetStudentNicknameByNickname(nickname);
                }

                response.Nickname = nickname;
                response.Status   = HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to generate nickname!");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to generate nickname!"));
            }
            return(response);
        }
        public void EditStudentNickname()
        {
            AddStudentRequest request = new AddStudentRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            StudentFacade      studentFacade = new StudentFacade();
            AddStudentResponse response      = studentFacade.AddStudentNickname(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);

            EditStudentNicknameRequest editStudentNicknameRequest = new EditStudentNicknameRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10)
            };

            EditStudentNicknameResponse editStudentNicknameResponse = studentFacade.EditStudentNickname(response.StudentID, editStudentNicknameRequest);

            Assert.AreEqual(HttpStatusCode.OK, editStudentNicknameResponse.Status);
            Assert.IsTrue(editStudentNicknameResponse.Result);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var nickname = context.Nicknames.FirstOrDefault(n => n.StudentId == response.StudentID);

                Assert.AreEqual(editStudentNicknameRequest.Nickname, nickname.NickName);
            }
        }
        public void DeleteTimespan()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest()
            {
                HelpdeskId = 1,
                Name       = AlphaNumericStringGenerator.GetString(10),
                StartDate  = DateTime.Today,
                EndDate    = DateTime.Today.AddYears(1)
            };

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

            Assert.AreEqual(HttpStatusCode.OK, addTimeSpanResponse.Status);

            DeleteTimeSpanResponse deleteResponse = helpdeskFacade.DeleteTimeSpan(addTimeSpanResponse.SpanId);

            Assert.AreEqual(HttpStatusCode.OK, deleteResponse.Status);

            GetTimeSpanResponse response = helpdeskFacade.GetTimeSpan(addTimeSpanResponse.SpanId);

            Assert.AreEqual(HttpStatusCode.NotFound, response.Status);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var timespan = context.Timespans.FirstOrDefault(ts => ts.SpanId == addTimeSpanResponse.SpanId);

                Assert.IsNull(timespan);
            }
        }
        public void JoinInvalidCheckNotFound()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = true,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            Topic topic = new Topic()
            {
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.Helpdeskunit.Add(helpdeskunit);

                context.SaveChanges();

                topic.UnitId = unit.UnitId;
                context.Topic.Add(topic);
                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                TopicID     = topic.TopicId,
                Nickname    = AlphaNumericStringGenerator.GetString(10),
                SID         = AlphaNumericStringGenerator.GetStudentIDString(),
                CheckInID   = -100,
                Description = "JoinInvalidCheckNotFound Test"
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

            Assert.AreEqual(HttpStatusCode.NotFound, response.Status);
        }
Example #15
0
        public TestDataQueue AddQueueItem(int?studentID = null, int?topicID = null, int?checkInID = null, string nickname = "", string sID = "", string description = "")
        {
            var request = new AddToQueueRequest();

            if (studentID != null)
            {
                request.StudentID = studentID;
            }
            if (topicID != null)
            {
                request.TopicID = (int)topicID;
            }
            if (checkInID != null)
            {
                request.CheckInID = (int)checkInID;
            }
            if (nickname != null)
            {
                if (nickname == "" && PopulateEmptyStrings)
                {
                    request.Nickname = AlphaNumericStringGenerator.GetString(20);
                }
                else
                {
                    request.Nickname = nickname;
                }
            }
            if (sID != null)
            {
                if (sID == "" && PopulateEmptyStrings)
                {
                    request.SID = AlphaNumericStringGenerator.GetStudentIDString();
                }
                else
                {
                    request.SID = sID;
                }
            }
            if (description != null)
            {
                if (description == "" && PopulateEmptyStrings)
                {
                    request.Description = "From Test Factory";
                }
                else
                {
                    request.Description = description;
                }
            }

            var response = QueueFacade.AddToQueue(request);

            TestDataQueue data = new TestDataQueue(request, response);

            return(data);
        }
        public void AddUnitCodeWrongLength()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Create unit with empty string for code.
            string       code     = AlphaNumericStringGenerator.GetString(20);
            TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, 1, "", code);

            Assert.AreEqual(HttpStatusCode.BadRequest, unitData.Response.Status);
        }
        public void GetHelpdesks()
        {
            var factory = new TestEntityFactory();

            var data = factory.AddHelpdesk(AlphaNumericStringGenerator.GetString(10));

            var facade   = new HelpdeskFacade();
            var response = facade.GetHelpdesks();

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.Helpdesks.Count > 0);
        }
        public void GetHelpdeskSuccess()
        {
            var factory = new TestEntityFactory();

            var data = factory.AddHelpdesk(AlphaNumericStringGenerator.GetString(10));

            var facade   = new HelpdeskFacade();
            var response = facade.GetHelpdesk(data.Response.HelpdeskID);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsNotNull(response.Helpdesk);
        }
Example #19
0
        public void CheckOutForced()
        {
            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Unit.Add(unit);
                context.SaveChanges();
            }

            CheckInRequest request = new CheckInRequest()
            {
                UnitID   = unit.UnitId,
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            CheckInFacade facade = new CheckInFacade();

            CheckInResponse response = facade.CheckIn(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.CheckInID > 0);

            CheckOutRequest coRequest = new CheckOutRequest()
            {
                ForcedCheckout = true
            };

            CheckOutResponse coResponse = facade.CheckOut(coRequest, response.CheckInID);

            Assert.AreEqual(HttpStatusCode.OK, coResponse.Status);
            Assert.IsTrue(coResponse.Result);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                Checkinhistory checkOut = context.Checkinhistory.FirstOrDefault(co => co.CheckInId == response.CheckInID);

                Assert.IsNotNull(checkOut);

                var baseTime = DateTime.Now.AddMinutes(-1);
                var addTime  = checkOut.CheckoutTime;
                var timeDiff = baseTime.CompareTo(addTime);
                Assert.IsTrue(timeDiff == -1);

                Assert.AreEqual(coRequest.ForcedCheckout, checkOut.ForcedCheckout);
            }
        }
        public void EditStudentNicknameNotFound()
        {
            StudentFacade studentFacade = new StudentFacade();

            EditStudentNicknameRequest editStudentNicknameRequest = new EditStudentNicknameRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10),
            };

            EditStudentNicknameResponse editStudentNicknameResponse = studentFacade.EditStudentNickname(-1, editStudentNicknameRequest);

            Assert.AreEqual(HttpStatusCode.NotFound, editStudentNicknameResponse.Status);
        }
        public void UpdateNotFoundHelpdesk()
        {
            var facade        = new HelpdeskFacade();
            var updateRequest = new UpdateHelpdeskRequest()
            {
                HasCheckIn = true,
                HasQueue   = true,
                Name       = AlphaNumericStringGenerator.GetString(10)
            };

            var updateResponse = facade.UpdateHelpdesk(-1, updateRequest);

            Assert.AreEqual(HttpStatusCode.NotFound, updateResponse.Status);
        }
        public void ValidateNicknameNew()
        {
            ValidateNicknameRequest request = new ValidateNicknameRequest()
            {
                Name = AlphaNumericStringGenerator.GetString(10),
                SID  = AlphaNumericStringGenerator.GetStudentIDString()
            };

            var facade = new StudentFacade();

            var response = facade.ValidateNickname(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
        }
Example #23
0
        public void AddUserUsernameTooLong()
        {
            UsersFacade usersFacade = new UsersFacade();

            AddUserRequest addUserRequest = new AddUserRequest();

            addUserRequest.Username        = AlphaNumericStringGenerator.GetString(21);
            addUserRequest.Password        = "******";
            addUserRequest.PasswordConfirm = "Password1";

            AddUserResponse addUserResponse = usersFacade.AddUser(addUserRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, addUserResponse.Status);
        }
Example #24
0
        public void UpdateUserPasswordTooShort()
        {
            UsersFacade usersFacade = new UsersFacade();

            UpdateUserRequest updateUserRequest = new UpdateUserRequest()
            {
                Username = AlphaNumericStringGenerator.GetString(10),
                Password = AlphaNumericStringGenerator.GetString(5),
            };

            UpdateUserResponse updateUserResponse = usersFacade.UpdateUser(8, updateUserRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, updateUserResponse.Status);
        }
Example #25
0
        public void UpdateUserNotFound()
        {
            UsersFacade usersFacade = new UsersFacade();

            UpdateUserRequest updateUserRequest = new UpdateUserRequest()
            {
                Username = AlphaNumericStringGenerator.GetString(9),
                Password = AlphaNumericStringGenerator.GetString(9)
            };

            UpdateUserResponse updateUserResponse = usersFacade.UpdateUser(-1, updateUserRequest);

            Assert.AreEqual(HttpStatusCode.NotFound, updateUserResponse.Status);
        }
        public void GetUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID);

            Topic topic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = false,
                UnitId    = unitData.Response.UnitID
            };
            Topic deletedTopic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = true,
                UnitId    = unitData.Response.UnitID
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Topic.Add(topic);
                context.Topic.Add(deletedTopic);
                context.SaveChanges();
            }

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get the unit that was just created.
            UnitsFacade     unitsFacade     = new UnitsFacade();
            GetUnitResponse getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);

            // Check that unit response is okay and that names match.
            Assert.AreEqual(HttpStatusCode.OK, getUnitResponse.Status);
            Assert.AreEqual(unitData.Request.Name, getUnitResponse.Unit.Name);
            Assert.IsTrue(getUnitResponse.Unit.Topics.Count == 2);
            Assert.AreEqual(topic.Name, getUnitResponse.Unit.Topics[1].Name);
        }
        public void UpdateTimespanNotFound()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            UpdateTimeSpanRequest updateTimespanRequest = new UpdateTimeSpanRequest()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                StartDate = new DateTime(2019, 08, 01),
                EndDate   = new DateTime(2019, 11, 01)
            };

            UpdateTimeSpanResponse updateTimespanResponse = helpdeskFacade.UpdateTimeSpan(-1, updateTimespanRequest);

            Assert.AreEqual(HttpStatusCode.NotFound, updateTimespanResponse.Status);
        }
        public void JoinQueueInvalidTopicFail()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = true,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.Helpdeskunit.Add(helpdeskunit);

                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString(),
                TopicID  = 0
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
Example #29
0
        public void CheckInExistingStudent()
        {
            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            Nicknames nickname = new Nicknames()
            {
                NickName = AlphaNumericStringGenerator.GetString(10),
                Sid      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Unit.Add(unit);
                context.Nicknames.Add(nickname);
                context.SaveChanges();
            }

            CheckInRequest request = new CheckInRequest()
            {
                UnitID    = unit.UnitId,
                StudentID = nickname.StudentId
            };

            CheckInFacade facade = new CheckInFacade();

            CheckInResponse response = facade.CheckIn(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.CheckInID > 0);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                Checkinhistory checkInHistory = context.Checkinhistory.FirstOrDefault(cih => cih.CheckInId == response.CheckInID);

                var baseTime = DateTime.Now.AddMinutes(-1);
                var addTime  = checkInHistory.CheckInTime;
                Assert.AreEqual(request.UnitID, checkInHistory.UnitId);
                var timeDiff = baseTime.CompareTo(addTime);
                Assert.IsTrue(timeDiff == -1);
                Assert.AreEqual(request.StudentID, checkInHistory.StudentId);
            }
        }
Example #30
0
        /// <summary>
        /// Adds a test unit to the database.
        /// </summary>
        /// <param name="unitID">The ID of the unit to update. Should not be provided if adding a new helpdesk.</param>
        /// <param name="helpdeskID">The ID of the helpdesk that the unit is being added to.</param>
        /// <param name="name">Name of the unit (auto-generates if not provided, or empty string is provided).</param>
        /// <param name="code">Code of the unit (auto-generates if not provided, or empty string is provided).</param>
        /// <param name="isDeleted">Whether or not the helpdesk is removed from the system.</param>
        /// <param name="topics">A list of topics associated with the unit.</param>
        /// <returns></returns>
        public TestDataUnit AddUpdateUnit(int unitID = 0, int?helpdeskID = null, string name = "", string code = "", bool?isDeleted = false, List <string> topics = null)
        {
            var request = new AddUpdateUnitRequest();

            if (helpdeskID != null)
            {
                request.HelpdeskID = (int)helpdeskID;
            }
            if (name != null)
            {
                if (name == "" && PopulateEmptyStrings)
                {
                    request.Name = AlphaNumericStringGenerator.GetString(10);
                }
                else
                {
                    request.Name = name;
                }
            }
            if (code != null)
            {
                if (code == "" && PopulateEmptyStrings)
                {
                    request.Code = AlphaNumericStringGenerator.GetString(8);
                }
                else
                {
                    request.Code = code;
                }
            }
            if (isDeleted != null)
            {
                request.IsDeleted = (bool)isDeleted;
            }
            if (topics != null)
            {
                request.Topics = topics;
            }

            var facade   = new UnitsFacade();
            var response = facade.AddOrUpdateUnit(unitID, request);

            TestDataUnit data = new TestDataUnit(request, response);

            return(data);
        }