Пример #1
0
        public void FindRecordByUserInputString_FromTheModel(User user, int selectedDay, int selectedMonth, int selectedStart, int selectedEnd,
                                                             bool exist)
        {
            var size       = RecordModel.GetAllRecords().Count;
            var testRecord = new Record(user, selectedDay, selectedMonth, selectedStart, selectedEnd);
            var text       = testRecord.FromTime.ToString("dd MMMM, HH:mm") + "—" + testRecord.ToTime.Hour + ":00";

            //Record is exist or not
            if (exist)
            {
                //Add record
                RecordModel.CreateRecord(user, selectedDay, selectedMonth, selectedStart, selectedEnd, exist);
                Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);

                //Select record from Record List
                var record = RecordModel.FindRecordByUserInputString(text);
                Assert.NotNull(record);
                StringAssert.AreEqualIgnoringCase(text,
                                                  record.FromTime.ToString("dd MMMM, HH:mm") + "—" + record.ToTime.Hour + ":00");
            }
            else
            {
                var record = RecordModel.FindRecordByUserInputString(text);
                Assert.Null(record);
            }
        }
Пример #2
0
        public void CreateRecord_AddValidRecord_RefuseInvalidRecord(DateTime startDateTime, int endTimeInt, bool valid, bool outOfRange)
        {
            var user      = new User();
            var size      = RecordModel.GetAllRecords().Count;
            var day       = startDateTime.Day.ToString();
            var month     = startDateTime.ToString("MMMM");
            var startTime = startDateTime.ToString("H:mm");
            var endTime   = endTimeInt + ":00";

            if (valid)
            {
                CreateRecordWithDialogueClass(user, day, month, startTime, endTime);

                Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);
                StringAssert.AreEqualIgnoringCase(startDateTime.ToString("MM-dd HH:mm:ss"),
                                                  RecordModel.GetAllRecords()[size].FromTime.ToString("MM-dd HH:mm:ss"));
            }
            else
            {
                if (outOfRange)
                {
                    Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                CreateRecordWithDialogueClass(user, day, month, startTime, endTime));
                }
                else
                {
                    Assert.AreEqual(size, RecordModel.GetAllRecords().Count);
                }
            }
        }
Пример #3
0
        public void DeleteRecord_DeleteExisting_IgnoreNonExisting(User user, int selectedDay, int selectedMonth, int selectedStart, int selectedEnd,
                                                                  bool exist)
        {
            var size   = RecordModel.GetAllRecords().Count;
            var record = new Record(user, selectedDay, selectedMonth, selectedStart, selectedEnd);

            //Record is exist or not
            if (exist)
            {
                //Add record
                RecordModel.CreateRecord(user, selectedDay, selectedMonth, selectedStart, selectedEnd, true);
                Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);

                //Select record from Record List
                var selectedRecord =
                    RecordModel.FindRecordByUserInputString(record.FromTime.ToString("dd MMMM, HH:mm") + "—" +
                                                            record.ToTime.Hour + ":00");

                //Delete selected record
                RecordModel.DeleteRecord(selectedRecord, user.Id);
                Assert.AreEqual(size, RecordModel.GetAllRecords().Count);
            }
            else
            {
                //Select record from Record List
                var selectedRecord =
                    RecordModel.FindRecordByUserInputString(record.FromTime.ToString("dd MMMM, HH:mm") + "—" +
                                                            record.ToTime.Hour + ":00");
                //Delete non-exist record
                RecordModel.DeleteRecord(selectedRecord, user.Id);
                Assert.AreEqual(size, RecordModel.GetAllRecords().Count);
            }
        }
Пример #4
0
        public void ScheduleRecords_RefuseOverlappingRecord_GetForMultipleUsers(User firstUser, int firstId, User secondUser, int secondId,
                                                                                TestRecord firstRecord, TestRecord secondRecord)
        {
            firstUser.Id = firstId;
            var size = RecordModel.GetAllRecords().Count;

            firstRecord.SetUser(firstUser);

            var firstUserSchedule  = from record in RecordModel.GetAllRecords() where record.User.Id == firstId select record;
            var secondUserSchedule = from record in RecordModel.GetAllRecords() where record.User.Id == secondId select record;
            var firstUserSize      = firstUserSchedule.Count();
            var secondUserSize     = secondUserSchedule.Count();

            CreateRecordWithDialogueClass(firstRecord);

            secondUser.Id = secondId;
            secondRecord.SetUser(secondUser);
            CreateRecordWithDialogueClass(secondRecord);

            firstUserSchedule  = from record in RecordModel.GetAllRecords() where record.User.Id == firstId select record;
            secondUserSchedule = from record in RecordModel.GetAllRecords() where record.User.Id == secondId select record;

            Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);
            Assert.AreEqual(firstUserSize + 1, firstUserSchedule.Count());
            Assert.AreEqual(secondUserSize, secondUserSchedule.Count());
        }
Пример #5
0
        public void CreateRecord_RefuseOverlappingRecord(DateTime startDateTime1, int endTimeInt1, DateTime startDateTime2,
                                                         int endTimeInt2)
        {
            var size = RecordModel.GetAllRecords().Count;

            CreateRecord_AddValidRecord_RefuseInvalidRecord(startDateTime1, endTimeInt1, true, false);
            CreateRecord_AddValidRecord_RefuseInvalidRecord(startDateTime2, endTimeInt2, false, false);
            var size1 = RecordModel.GetAllRecords().Count;

            Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);
        }
            public override async Task <AbstractDialogue> OnMessage(MessageEventArgs args)
            {
                var records = from record in RecordModel.GetAllRecords()
                              where record.User.Id == args.Message.From.Id
                              select record;

                await _sendMessege("You have the following reservations:",
                                   (ReplyKeyboardMarkup)
                                   records
                                   .Select(x => new[] { x.FromTime.ToString("dd MMMM, HH:mm") + "—" + x.ToTime.Hour + ":00" })
                                   .ToArray());

                var md = new MainMenuDialogue(_sendMessege);

                return(md);
            }
Пример #7
0
        public void ScheduleRecords_GetForSingleUser(User user, int userId, TestRecord firstRecord, TestRecord secondRecord)
        {
            user.Id = userId;
            firstRecord.SetUser(user);
            secondRecord.SetUser(user);
            var size            = RecordModel.GetAllRecords().Count;
            var userRecordCount =
                (from record in RecordModel.GetAllRecords() where record.User.Id == userId select record).Count();

            CreateRecordWithDialogueClass(firstRecord);
            CreateRecordWithDialogueClass(secondRecord);
            Assert.AreEqual(size + 2, RecordModel.GetAllRecords().Count);
            var userSchedule = from record in RecordModel.GetAllRecords() where record.User.Id == userId select record;

            Assert.AreEqual(userRecordCount + 2, userSchedule.Count());
        }
Пример #8
0
        private string createSchedule(DateTime start, DateTime end)
        {
            var result       = new StringBuilder();
            var recordsByDay = (from record in RecordModel.GetAllRecords() where record.FromTime <end && record.ToTime> start select record).GroupBy((record) => record.FromTime);

            for (DateTime i = start; i != end; i.AddDays(1))
            {
                string DaySchedule = i.ToString("DDDD dd: ");
                var    records     = (from day in recordsByDay where day.Key == i select day).FirstOrDefault().OrderBy(t => t.FromTime).ToList();
                if (records.Any())
                {
                    if ((records.First()).FromTime.Hour == 8)
                    {
                        DaySchedule = records.First().FromTime.ToString("hh:mm");
                    }
                    else
                    {
                        DaySchedule += $" 08:00 - { records.First().FromTime.ToString("hh:mm")}\n";
                        DaySchedule += $"{ records.First().ToTime.ToString("hh:mm")}";
                    }

                    if (records.Count > 1)
                    {
                        foreach (var record in records.Skip(1).Take(records.Count - 2))
                        {
                            DaySchedule += $" - { record.FromTime.ToString("hh:mm")}\n";
                            DaySchedule += $"{ record.ToTime.ToString("hh:mm")}";
                        }
                        DaySchedule += $" - { records.Last().FromTime.ToString("hh:mm")}\n";
                        if (records.Last().ToTime.Hour < 21)
                        {
                            DaySchedule += $"{ records.Last().ToTime.ToString("hh:mm")} - 21:00";
                        }
                    }
                    else
                    {
                        DaySchedule += $"21:00";
                    }
                }

                result.Append(DaySchedule);
                result.Append("\n-----------\n");
            }
            return(result.ToString());
        }
Пример #9
0
        public void CreateRecord_AddValidRecords(int count, int month, bool secondRound)
        {
            var user    = new User();
            var size    = RecordModel.GetAllRecords().Count;
            var counter = 0;

            while (counter < count)
            {
                for (var day = 1; day <= 28; day++)
                {
                    if (counter == count)
                    {
                        break;
                    }
                    for (var i = 8; i < 21; i++)
                    {
                        if (counter == count)
                        {
                            break;
                        }
                        if (!secondRound)
                        {
                            RecordModel.CreateRecord(user, day, month, i, i + 1, true);
                        }
                        //todo bug found here
                        else
                        {
                            CreateRecord_AddValidRecord_RefuseInvalidRecord(new DateTime(DateTime.Now.Year, month, day, i, 0, 0), i + 1, true, false);
                        }
                        counter++;
                    }
                }

                month++;
            }

            Assert.AreEqual(size + counter, RecordModel.GetAllRecords().Count);
            if (!secondRound)
            {
                CreateRecord_AddValidRecords(count, month, true);
            }
        }
        internal async void AskForRecord(int userId)
        {
            var records = from record in RecordModel.GetAllRecords() where record.User.Id == userId select record;

            if (records.Count() < 1)
            {
                _state = 99;
                var _menueMessage = "No record found";

                await _sendMessege(_menueMessage, MainMenuDialogue.getMainMenuKeyboard());
            }
            else
            {
                await _sendMessege("Select one of your reservations to update or delete:",
                                   (ReplyKeyboardMarkup)
                                   records
                                   .Select(x => new[] { x.FromTime.ToString("dd MMMM, HH:mm") + "—" + x.ToTime.Hour + ":00" })
                                   .ToArray());
            }
        }
Пример #11
0
        public void UpdateRecord_ValidUpdate(User user, TestRecord record, String recordDate, int newStartTime,
                                             int newEndTime)
        {
            var size = RecordModel.GetAllRecords().Count;

            record.SetUser(user);

            CreateRecordWithDialogueClass(record);
            Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);

            StringAssert.AreEqualIgnoringCase(recordDate + " " + record.startTime + ":00",
                                              RecordModel.GetAllRecords()[size].FromTime.ToString("yyyy-MM-dd HH:mm:ss"));

            RecordModel.UpdateRecord(RecordModel.GetAllRecords()[size], user, newStartTime, newEndTime);

            Assert.AreEqual(size + 1, RecordModel.GetAllRecords().Count);

            StringAssert.AreEqualIgnoringCase(recordDate + " " + newStartTime + ":00:00",
                                              RecordModel.GetAllRecords()[size].FromTime.ToString("yyyy-MM-dd HH:mm:ss"));
        }