Ejemplo n.º 1
0
        public void Check_That_Reminder_Calls_Internal_Delegate()
        {
            var reminderStorage = new ReminderStorage();
            var reminderDomain  = new ReminderDomain(reminderStorage);

            bool delegateWasFalse = false;

            reminderDomain.SendReminder += (reminder) =>
            {
                delegateWasFalse = true;
            };

            reminderDomain.Add(new AddReminderModel
            {
                Date = DateTimeOffset.Now
            });

            reminderDomain.Run();

            Thread.Sleep(2000);

            Assert.IsTrue(delegateWasFalse);
        }
Ejemplo n.º 2
0
        public void Correct_Change_Status_To_Ready()
        {
            //var item = new ReminderItem();
            var storage = new InMemoryReminderStorage();

            storage.Add(new ReminderItem(DateTimeOffset.Now, null, null));

            using (var domain = new ReminderDomain(
                       storage,
                       TimeSpan.FromMilliseconds(50),
                       TimeSpan.FromSeconds(1)))
            {
                //т.к. таймеры в домене отрабатывают раз в секунду, надо подождать пару секунд
                domain.Run();
                System.Threading.Thread.Sleep(200);
            }
            //проверки
            var readyList = storage.Get(ReminderItemStatus.Ready);

            //gпустой список, а не null
            Assert.IsNotNull(readyList);
            Assert.AreEqual(1, readyList.Count);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            const string token = "790352518:AAFWfSGPTPAUVb3IMJMDQx5RdSeH1sIMWyk";


            var receiver = new TelegramReminderReceiver(token);
            var sender   = new TelegramReminderSender(token);
            var storage  = new InMemoryReminderStorage();

            var domain = new ReminderDomain(
                storage,
                receiver,
                sender);

            //Console.Write(receiver.GetHelloFromBot());
            domain.AddingSucceded  += Domain_AddingSucceded;
            domain.SendingSucceded += Domain_SendingSucceded;
            domain.SendingFailed   += Domain_SendingFailed;

            domain.Run();

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public void Method_Run_Should_Call_Failed_Event_When_Sending_does_not_Thrown()
        {
            var storage = new InMemoryReminderStorage();

            storage.Add(DateTimeOffset.Now, null, null, ReminderItemStatus.Awaiting);

            bool failedEventCalled = false;

            //создает класс содержащий  интерфейс
            var mockReceiver = new Mock <IReminderReceiver>();
            var fakeReceiver = mockReceiver.Object;

            using (var domain = new ReminderDomain(
                       storage,
                       fakeReceiver,
                       TimeSpan.FromMilliseconds(50),
                       TimeSpan.FromSeconds(50)))
            {
                domain.SendReminder += (reminder) =>
                {
                    throw new Exception("test exception");
                };

                domain.SendingFailed += (s, e) =>
                {
                    if (e.SendingException.Message == "test exception")
                    {
                        failedEventCalled = true;
                    }
                };

                domain.Run();
                System.Threading.Thread.Sleep(1200);
            }

            Assert.IsTrue(failedEventCalled);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            const string token = "1467408776:AAGSGszyTCYYCTWTKu4PL_it029uC8X8hbs";
            //botID = "1467408776"

            var storage  = new InMemoryReminderStorage();
            var sender   = new TelegramReminderSender(token);
            var receiver = new TelegramReminderReceiver(token);

            using var domain = new ReminderDomain(storage, receiver, sender, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));//Dependency injection

            var addReminderModel = new AddReminderModel(DateTimeOffset.Now.AddSeconds(2), "Hello World!", "1467408776");

            domain.SendingSucceeded += Domain_SendingSucceeded;
            domain.SendingFailed    += Domain_SendingFailed;

            //receiver.MessageReceived += ;

            //domain.AddReminderModel(addReminderModel);
            domain.Run();

            Console.WriteLine("Domain logic running...");
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public void Check_That_On_SendReminder_SendingSucceded_Event_Raised()
        {
            var reminderStorage = new ReminderStorage();
            var reminderDomain  = new ReminderDomain(reminderStorage);

            bool eventHandlerCalled = false;

            reminderDomain.SendingSucceded += (s, e) =>
            {
                eventHandlerCalled = true;
            };

            reminderDomain.Add(
                new AddReminderModel()
            {
                Date = DateTimeOffset.Now
            });

            reminderDomain.Run();

            Thread.Sleep(2500);

            Assert.IsTrue(eventHandlerCalled);
        }
Ejemplo n.º 7
0
        static void Main()
        {
            const string token = "633428988:AAHEOPx2C24pNmcHJz0IBL7FH3a4lGjXqcs";

            var storage  = new ReminderStoageWebApiClient("https://localhost:44348/api/reminders");
            var sender   = new TelegramReminderSender(token);
            var receiver = new TelegramReminderReceiver(token);

            using var domain = new ReminderDomain(
                      storage,
                      sender,
                      receiver,
                      TimeSpan.FromSeconds(1),
                      TimeSpan.FromSeconds(1));

            domain.AddingSucceeded += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("OK ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"SCHEDULED on {e.Date:G}");
            };

            domain.AddingFailed += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"Error ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Cannot SCHEDULE reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"to be sent on {e.Date:G}");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Exception);
                Console.ResetColor();
            };

            domain.SendingSucceeded += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("OK ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"SENT on {e.Date:G}");
            };

            domain.SendingFailed += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"Error ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Cannot SEND reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"on {e.Date:G}");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Exception);
                Console.ResetColor();
            };

            domain.Run();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string token    = @"1658241756:AAEGWnqk2BVg6qTOmaaQAby-g00DiqWhFRY";
            var    storage  = new InMemoryReminderStorage();
            var    sender   = new TelegramReminderSender(token);
            var    receiver = new TelegramReminderReceiver(token);

            using var domain = new ReminderDomain(
                      storage,
                      sender,
                      receiver,
                      TimeSpan.FromSeconds(1),
                      TimeSpan.FromSeconds(1));
            domain.AddingSucceeded += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("OK ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"SCHEDULED on {e.Date:G}");
            };

            domain.AddingFailed += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"Error ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Cannot SCHEDULE reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"to be sent on {e.Date:G}");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Exception);
                Console.ResetColor();
            };

            domain.SendingSucceeded += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("OK ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"SENT on {e.Date:G}");
            };

            domain.SendingFailed += (s, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"Error ");
                Console.ResetColor();
                Console.WriteLine(
                    $"Cannot SEND reminder item ID {e.Id} " +
                    $"from {e.ContactId} " +
                    $"with message \"{e.Message}\" " +
                    $"on {e.Date:G}");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Exception);
                Console.ResetColor();
            };

            domain.Run();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }