Exemple #1
0
        public void Remove_User_Storage_InMemory_Tests_Method()
        {
            InMemoryStorage inMemoryStorage = new InMemoryStorage();

            Guid           guid = Guid.NewGuid();
            DomainUserItem user = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = DateTimeOffset.Now,
                FirstName          = "Null",
                Id      = guid,
                Message = "Null",
                Status  = StatusEnum.Null
            };
            Guid           guid2 = Guid.NewGuid();
            DomainUserItem user2 = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = DateTimeOffset.Now,
                FirstName          = "Null",
                Id      = guid2,
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user);
            inMemoryStorage.AddUser(user2);

            Assert.AreEqual(inMemoryStorage.Count, 2);

            inMemoryStorage.RemoveUser(guid);

            Assert.AreEqual(inMemoryStorage.Count, 1);
            Assert.AreNotEqual(inMemoryStorage.GetUser(guid2).Id, guid);
        }
Exemple #2
0
        public void Update_Status_Storage_InMemory_Tests_Method()
        {
            InMemoryStorage inMemoryStorage = new InMemoryStorage();

            Guid           guid = Guid.NewGuid();
            DomainUserItem user = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = DateTimeOffset.Now,
                FirstName          = "Null",
                Id      = guid,
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user);
            Assert.AreEqual(inMemoryStorage.Count, 1);
            inMemoryStorage.UpdateStatus(user);
            Assert.AreEqual(StatusEnum.Null, inMemoryStorage.GetUser(guid).Status);
            Assert.AreEqual(inMemoryStorage.Count, 1);
        }
Exemple #3
0
        public void Get_User_Id_Storage_InMemory_Tests_Method()
        {
            InMemoryStorage inMemoryStorage = new InMemoryStorage();

            Guid           guid = Guid.NewGuid();
            DateTimeOffset date = DateTimeOffset.Now;
            DomainUserItem user = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = date,
                FirstName          = "Null",
                Id      = guid,
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user);
            Assert.AreEqual(inMemoryStorage.Count, 1);
            IUserItem userItem = inMemoryStorage.GetUser(guid);

            Assert.AreEqual(inMemoryStorage.Count, 1);
            Assert.AreEqual(userItem, user);
        }
Exemple #4
0
        private void Receiver_MeesageReciver(object sender, MessageReceivedEventArgs e)
        {
            IDomainUserItem item = _storageInMemory.GetUser(e.ChatId);
            DomainUserItem  userItem;

            if (item == null)
            {
                Telegram.Storage.Core.UserItem newUser = new Telegram.Storage.Core.UserItem()
                {
                    ChatId             = Convert.ToInt64(e.ChatId),
                    DateOfRegistration = DateTimeOffset.Now,
                    FirstName          = e.FirstName,
                    Id      = Guid.NewGuid(),
                    Message = e.Message,
                    Status  = StatusEnum.User, //StatusEnum.User
                };

                _storage.AddUser(newUser);

                userItem = new DomainUserItem()
                {
                    ChatId             = newUser.ChatId,
                    DateOfRegistration = newUser.DateOfRegistration,
                    FirstName          = newUser.FirstName,
                    Id           = newUser.Id,
                    Message      = newUser.Message,
                    Status       = newUser.Status,                               //newUser.Status,
                    DomainStatus = DomainStatusEnum.Admin_Greeteng_Notification, //DomainStatusEnum.User_Greeting
                };
                _storageInMemory.AddUser(userItem);
            }
            else
            {
                DomainStatusEnum domainStatus = item.DomainStatus;
                if (item.DomainStatus.Equals(DomainStatusEnum.Null))
                {
                    if (item.Status.Equals(StatusEnum.Admin))
                    {
                        domainStatus = DomainStatusEnum.Admin_Greeteng_Notification;
                    }
                    else if (item.Status.Equals(StatusEnum.User))
                    {
                        domainStatus = DomainStatusEnum.User_Greeting;
                    }
                }
                userItem = new DomainUserItem()
                {
                    ChatId             = item.ChatId,
                    DateOfRegistration = item.DateOfRegistration,
                    FirstName          = item.FirstName,
                    Id                      = item.Id,
                    Message                 = e.Message,
                    Status                  = item.Status,  //ITEM.STATUS
                    DomainStatus            = domainStatus, //item.DomainStatus
                    weatherForecast         = item.weatherForecast,
                    Admin_MessageSend       = item.Admin_MessageSend,
                    Admin_InputName         = item.Admin_InputName,
                    CountDays               = item.CountDays,
                    User_Reminder_CountDays = item.User_Reminder_CountDays,
                    User_Reminder_City      = item.User_Reminder_City,
                    ReminderWeatherForecast = item.ReminderWeatherForecast,
                    Admin_Photo             = item.Admin_Photo,
                    Photo                   = e.Photo,
                    Caption                 = e.Caption,
                    Admin_Caption           = item.Admin_Caption
                };
            }

            userPanel  = new UserPanel(userItem, _sender, _reminder);
            panelAdmin = new PanelAdmin(userItem, _sender, _storage);

            if (userItem.Status.Equals(StatusEnum.User))
            {
                userItem = userPanel.UserPanelMessage(_storageInMemory);
            }
            else if (userItem.Status.Equals(StatusEnum.Admin))
            {
                userItem = panelAdmin.PanelAdminMessage(_storageInMemory);
            }
            else
            {
                _sender.SendMessage(userItem.ChatId, "Хмм... Что-то пошло не так.", null);
            }

            if (userItem != item)
            {
                _storageInMemory.UpdateStatus(userItem);
            }
        }