//----------------------------------------------------------------// public async Task <OkObjectResult> CreateOrUpdate(String s_time, Int64 chatId, String name) { TimeSpan time; if (TimeSpan.TryParse(s_time, out time)) { await _provider.GetService <ICaseService>().CreateDailyCaseAsync(time, name, chatId); return(Ok(CaseMessages.CaseAdded(ScheduleType.Daily, name, s_time))); } else { return(Ok(GeneralMessage.TIME_INCORRECT_FORMAT)); } }
public async Task CreateSpecificDayCase_Correct() { //arrange String s_dateTime = "22-01-2018 17:30"; String nameCase = "specific_case_test"; String command = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_SPECIFIC_DATE_CASE, nameCase, s_dateTime); Message expectedMessage = new Message() { Text = CaseMessages.CaseAdded(ScheduleType.ConcretyDate, nameCase, s_dateTime) }; ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupConcretyDateCase(String.Empty)); await TestTelegramCommand(command, expectedMessage); }
public async Task CreateDailyCase_Correct() { //arrange String time = "18:30"; String nameCase = "daily_case_test"; String command = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_DAILY_CASE, nameCase, time); //Response message Message expectedMessage = new Message() { Text = CaseMessages.CaseAdded(ScheduleType.Daily, nameCase, time) }; //Mocks ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupDailyCase(String.Empty)); await TestTelegramCommand(command, expectedMessage); }
public async Task CreateWeeklyCase_Correct() { //arrange String time = "05:30"; String nameCase = "week_case_test"; String[] daysOfWeek = new String[] { nameof(DayOfWeek.Monday), nameof(DayOfWeek.Tuesday), nameof(DayOfWeek.Monday) }; String s_days = String.Join(StringConstants.SPACE, daysOfWeek); String command = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_WEEKLY_CASE, nameCase, s_days, time); //Response message Message expectedMessage = new Message() { Text = CaseMessages.CaseAdded(ScheduleType.Weekly, nameCase, time) }; //Mocks ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupWeeklyCase(String.Empty)); await TestTelegramCommand(command, expectedMessage); }
//----------------------------------------------------------------// public async override Task <Message> ExecuteAsync(Message message) { Task t_reinitNotifacationList = Task.CompletedTask; String resultMsg = null; String[] values = GetCommandGroups(message.Text); if (values.Length > 0) { String s_time = GetTime(values); String nameCase = GetNameCase(values); if (TimeSpan.TryParse(s_time, out TimeSpan timeSpan)) { resultMsg = await CreateCase(values, message.Chat.Id, timeSpan); if (String.IsNullOrEmpty(resultMsg)) { resultMsg = CaseMessages.CaseAdded(scheduleType, nameCase, s_time); t_reinitNotifacationList = Provider.GetService <INotificationService>().ReinitNotificationList(); } } else { resultMsg = GeneralMessage.TIME_INCORRECT_FORMAT; } } else { resultMsg = GeneralMessage.COMMAND_NOT_MATCH_PATTERN; } Task <Message> t_sendMessage = BotClient.SendTextMessageAsync(message.Chat.Id, resultMsg, replyToMessageId: message.MessageId); return(await t_sendMessage); }