public UnitOfWork() { _context = new MessengerClient_DBEntities(); messagesRepo = new MessagesRepository(_context); usersRolesRepo = new UsersRepository(_context); rolesMappingRepo = new RolesRepository(_context); }
public void ShouldSendAndDeleteMessage() { //arrange var user = new User { Name = "testCharUser", Picture = new byte[] {} }; var login = "******"; var password = "******"; var title = "chatTitle"; var pic = new byte[] {}; string msg = "TestText of msg"; //act var userRepository = new UsersRepository(ConnectionString); var resultUser = userRepository.Create(user, login, password); var userIds = new List <Guid> { resultUser.Id }; _tempUsers.AddRange(userIds); var chatRepository = new ChatsRepository(ConnectionString); var resultChat = chatRepository.Create(title, userIds, pic); _tempChats.Add(resultChat.Id); var messageRepository = new MessagesRepository(ConnectionString); var resultMsg = messageRepository.Send(msg, resultUser.Id, resultChat.Id); messageRepository.Delete(resultMsg.Id); //asserts Assert.AreEqual(false, messageRepository.MessageExists(resultMsg.Id)); Assert.AreEqual(false, chatRepository.GetChatMessages(resultChat.Id).Any(m => m.Id == resultMsg.Id)); }
public async Task FetchUnprocessedAsync_should_return_unprocessed_messages_only() { var batchSize = 6; var publisher = Substitute.For <IMessagePublisher>(); var messages = Enumerable.Repeat(1, batchSize) .Select(CreateFakeMessage) .ToArray(); int index = 0; foreach (var message in messages) { if (0 == (index++ % 2)) { await message.Process(publisher, CancellationToken.None); } } await using var dbContext = _fixture.BuildDbContext(); dbContext.Messages.AddRange(messages); await dbContext.SaveChangesAsync(); var sut = new MessagesRepository(dbContext); var results = await sut.FetchUnprocessedAsync(batchSize, CancellationToken.None); results.Should().NotBeNullOrEmpty() .And.HaveCount(3); }
internal string PrintGraph() { string result = string.Empty; int startPoiId = Solver.Instance.WorkingConfiguration.StartingPointId; BreadthFirstSearch(startPoiId, (node, isVisited) => node.IsVisited = isVisited, (node) => node.IsVisited, node => { string message = MessagesRepository.GetMessage(MessageCode.CMGraphNodeToString, node.Entity.Name, node.ArrivalTime.ToString("HH:mm")); result += $"\t({node.Entity.Id} - {message})"; }, edge => { if (edge.Entity.PointTo.Id != startPoiId) { result += "\n"; } else { InterestPointWorker startPoi = this[startPoiId]; string message = MessagesRepository.GetMessage(MessageCode.CMGraphNodeToString, startPoi.Entity.Name, TimeSpent.ToString("HH:mm")); result += $"\n\t({startPoi.Entity.Id} - {message})"; } }); result += "\n"; Nodes.ToList().ForEach(node => node.IsVisited = default);
public int GetIdOfMessage(Messages entityToGetId) { IMessagesRepository repo = new MessagesRepository(getEntities()); Entities.Messages entityToGetId2 = Mapper.Map <Messages, Entities.Messages>(entityToGetId); return(repo.GetMessageId(entityToGetId2)); }
public void AddMessage(Messages entityToAdd) { IMessagesRepository repo = new MessagesRepository(getEntities()); Entities.Messages entityToAdd2 = Mapper.Map <Messages, Entities.Messages>(entityToAdd); repo.Add(entityToAdd2); }
public MessagesController() { var context = new ChatDatabaseContext(); messagesRepository = new MessagesRepository(context); usersRepository = new UsersRepository(context); }
public Message Save() { using (MessagesRepository repo = new MessagesRepository(DataContext)) { if (_id == 0) { _id = repo.Insert(ParentId, UserId, Type, Subject, Body, Data); } else { repo.Update(Id, ParentId, UserId, SentAt, Type, Subject, Body, Data); } return(this); } }
public ActionResult Create(string CampaignName, DateTime MessageDate, int Clicks, int Conversions, int Impressions, string AffiliateName) { MessagesRepository _messageRepository = new MessagesRepository(); Messages objMsg = new Messages(); objMsg.CampaignName = CampaignName; objMsg.MessageDate = MessageDate; objMsg.Clicks = Clicks; objMsg.Conversions = Conversions; objMsg.Impressions = Impressions; objMsg.AffiliateName = AffiliateName; //string msgReturn = _messageRepository.InsertMessages(objMsg.CampaignName, MessageDate, Clicks, Conversions, Impressions, AffiliateName); string msgReturn = _messageRepository.InsertMessages(objMsg); //if (msgReturn == "Success") //{ // TempData["msgReturnCreate"] = "Record has been Created successfully."; //} //else //{ // TempData["msgReturnCreate"] = "Error Gets Generated for Create Record"; //} return(RedirectToAction("Index")); }
public Messages Load() { using (MessagesRepository repo = new MessagesRepository(base.DataContext)) { return((Messages)repo.Load <Message>(this, repo.GetItems())); } }
public void Clean() { var usersRepository = new UsersRepository(_connectionString); var chatsRepository = new ChatsRepository(_connectionString, usersRepository); var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository); foreach (var cm in _tempChatIdMemberIds) { chatsRepository.DeleteMember(cm.ChatId, cm.MemberId); } foreach (var messageId in _tmpMessages) { messagesRepository.DeleteMessage(messageId); } foreach (var chatId in _tmpChats) { chatsRepository.DeleteChat(chatId); } foreach (var userId in _tmpUsers) { usersRepository.DeleteUser(userId); } }
/// <summary> /// Initializes a new instance of the <see cref="TaxReturnRepository"/> class. /// </summary> public TaxReturnRepository() { taxReturnDataService = new TaxReturnDataService(); messageRepository = new MessagesRepository(); paymentDataService = new PaymentDataService(); }
public void GetMessages_BadRecipient_Throws(string recipient) { var target = new MessagesRepository(); Should.Throw <ArgumentException>(() => target.GetMessages(recipient)); }
public void ShouldGetMessage() { //arrange var usersRepository = new UsersRepository(_connectionString); var chatsRepository = new ChatsRepository(_connectionString, usersRepository); var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository); var createdMessage = messagesRepository.CreateMessage(_message); _tmpMessages.Add(createdMessage.Id); //act var gottenMessage = messagesRepository.GetMessage(createdMessage.Id); //assert Assert.AreEqual(createdMessage.Text, gottenMessage.Text); Assert.AreEqual(createdMessage.IsSelfDestructing, gottenMessage.IsSelfDestructing); Assert.AreEqual(createdMessage.Date.ToString(CultureInfo.InvariantCulture), gottenMessage.Date.ToString(CultureInfo.InvariantCulture)); if (createdMessage.Attachments.ElementAt(0).Length == gottenMessage.Attachments.ElementAt(0).Length) { Assert.IsTrue(createdMessage.Attachments.ElementAt(0). SequenceEqual(gottenMessage.Attachments.ElementAt(0))); Assert.IsTrue(createdMessage.Attachments.ElementAt(1). SequenceEqual(gottenMessage.Attachments.ElementAt(1))); } else { Assert.IsTrue(createdMessage.Attachments.ElementAt(0). SequenceEqual(gottenMessage.Attachments.ElementAt(1))); Assert.IsTrue(createdMessage.Attachments.ElementAt(1). SequenceEqual(gottenMessage.Attachments.ElementAt(0))); } }
public PartialViewResult _QuizChoice(int qid) { MessagesRepository _messageRepository = new MessagesRepository(); var vm = _messageRepository.GetQuizHariult(qid); return(PartialView(vm)); }
public void ShouldDeleteMessage() { var profile = new Profile { Id = Guid.NewGuid(), Login = "******", Avatar = Guid.NewGuid(), Password = "******", Name = "odmin", Surname = "odmin" }; const string chatName = "SendChat"; var usersRepository = new ProfilesRepository(Constants.Constants.ConnectionString); var result = usersRepository.CreateProfile(profile); _tempUsers.Add(result.Id); var chatRepository = new ChatsRepository(Constants.Constants.ConnectionString, usersRepository); var chatBefore = new Chat { ChatId = Guid.NewGuid(), ChatName = chatName, ChatMembers = new List <Guid>(new[] { profile.Id }) }; var chat = chatRepository.CreateChat(chatBefore); _chats.Add(chat.ChatId); var messageRepository = new MessagesRepository(Constants.Constants.ConnectionString); var message = new Message { MessageId = Guid.NewGuid(), ProfileId = profile.Id, ChatId = chat.ChatId, MessageText = "Hello, world!", Date = DateTime.Now, TimeToDestroy = 0, Attachment = Guid.Empty }; _messages.Add(message.MessageId); messageRepository.CreateMessage(message); messageRepository.DeleteMessage(message.MessageId); try { messageRepository.GetMessage(message.MessageId); } catch (Exception) { return; } }
public void Delete() { using (MessagesRepository repo = new MessagesRepository(DataContext)) { repo.Delete(_id); } }
public ActionResult Add(int containerId, string text) { if (!IsAuthenticated || AuthenticationService.CurrentUser.Role < UserRoles.User) { var error = new { Error = "У вас прав нет." }; return(Json(error, JsonRequestBehavior.AllowGet)); } try { ValidateAndGetContainer(containerId); } catch (Exception e) { var error = new { Error = e.Message }; return(Json(error, JsonRequestBehavior.AllowGet)); } Message message = new Message { UserId = CurrentUser.Id, ContainerId = containerId, Date = DateTime.Now, Text = text }; message = MessagesRepository.Add(message); MessagesRepository.SaveChanges(); var response = new { Html = ConvertViewToString("Content/_Message", message) }; return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult GetMessages() { MessagesRepository _messageRepository = new MessagesRepository(); var model = _messageRepository.GetAllMessages(); return(PartialView("_MessagesList", model)); }
public ActionResult GetMessages() { MessagesRepository _messageRepository = new MessagesRepository(); //let's say we only want to display the last 10 return(PartialView("_MessagesList", _messageRepository.GetAllMessages().Take(10))); }
void ReloadChats() { using (MainDataBase dataBase = new MainDataBase()) { Chats = GetChatsByUser(User); if (Chats.Count > 0) { SelectedChat = Chats[0]; MessageViewModels = new ObservableCollection <MessageViewModel>(); messagesRepository = new MessagesRepository(dataBase); usersRepository = new UsersRepository(dataBase); foreach (MessageModel model in messagesRepository.GetAll(i => i.ChatID == SelectedChat.Id)) { MessageViewModels.Add(new MessageViewModel() { Fullname = usersRepository.GetById((int)model.SenderID).Fullname, Sent = model.Sent, Text = model.Text }); } } } }
protected override void Seed(MainDataBase dataBase) { _usersRepository = new UsersRepository(dataBase); _chatsRepository = new ChatsRepository(dataBase); _chatUserRepository = new ChatUserRepository(dataBase); _messagesRepository = new MessagesRepository(dataBase); }
public string GetTransactionResult() { MessagesRepository _messageRepository = new MessagesRepository(); var model = _messageRepository.GetAllMessages(); return(model.FirstOrDefault().Payment); //model.FirstOrDefault().Payment; }
public Messages Load(Dictionary <string, string> @params) { using (MessagesRepository repo = new MessagesRepository(base.DataContext)) { return((Messages)repo.Load <Message>(this, repo.GetItems(@params))); } }
/// <summary> /// /// </summary> /// <returns></returns> public string GetRfid() { MessagesRepository _messageRepository = new MessagesRepository(); var model = _messageRepository.GetAllMessages(); return(model.FirstOrDefault().Rfid); }
public MessagesController(UsersRepository userRepository, MessagesRepository messagesRepository, DialogsRepository dialogsRepository) : base(userRepository) { _messagesRepository = messagesRepository; _dialogsRepository = dialogsRepository; }
public ActionResult GetMessages() { UserProfile currentUser = (Session["UserProfileSession"] as UserProfile); MessagesRepository _messageRepository = new MessagesRepository(); return(PartialView("_MessagesList", _messageRepository.GetAllUnreadMessages(currentUser.Id))); }
public Message Load(int id) { using (MessagesRepository repo = new MessagesRepository(DataContext)) { return(repo.LoadOne <Message>(this, repo.GetItem(id))); } }
public void RemoveMessage(Messages entityToRemove) { IMessagesRepository repo = new MessagesRepository(getEntities()); Entities.Messages entityToRemove2 = Mapper.Map <Messages, Entities.Messages>(entityToRemove); repo.Remove(entityToRemove2); }
public ActionResult Update(int Id, DateTime MessageDate, string CampaignName, int Clicks, int Conversions, int Impressions, string AffiliateName) { MessagesRepository _messageRepository = new MessagesRepository(); Messages objMsg = new Messages(); objMsg.CampaignName = CampaignName; objMsg.MessageDate = MessageDate; objMsg.Clicks = Clicks; objMsg.Conversions = Conversions; objMsg.Impressions = Impressions; objMsg.AffiliateName = AffiliateName; objMsg.ID = Id; //string msgReturn = _messageRepository.UpdateMessages(Id, MessageDate, CampaignName, Clicks, Conversions, Impressions, AffiliateName); string msgReturn = _messageRepository.UpdateMessages(objMsg); //if (msgReturn == "Success") //{ // TempData["msgReturnUpdate"] = "Record has been Updated successfully."; //} //else //{ // TempData["msgReturnUpdate"] = "Error Gets Generated for Update Record"; //} //return Json(new { data }, JsonRequestBehavior.AllowGet); return(View("Index")); }
public testMessagesDao(int testNumber) { this.messageRepo = DaoFactory.getDao (DaoFactory.MySql).getMessagesRepository (); switch( testNumber ) { case 0: break; } }
public ActionResult CreateMessage(Message message) { message.DatePosted = DateTime.Now; message.Author = User.Identity.Name; using (var repo = new MessagesRepository()) { repo.Add(message); } return RedirectToAction("ThreadMessages", new { id = message.ThreadId }); }
public void BuildParametersForInsertingTest() { List<DbParam> expectedParametersForInserting = new List<DbParam> { new DbParam {Name = "@MessageText", Value = _message.MessageText}, new DbParam {Name = "@FromId", Value = _message.FromId}, new DbParam {Name = "@ToId", Value = _message.ToId} }; MessagesRepository repository = new MessagesRepository(_dbWrapper); List<DbParam> actualParametersForInserting = repository.BuildParametersForInserting(_message).ToList(); CollectionAssert.AreEqual(expectedParametersForInserting, actualParametersForInserting); }
public MessagesController() { var context = new ChatDatabaseContext(); messagesRepository = new MessagesRepository(context); }
public MessageService(IValidationDictionary validationDictionary) { _validationDictionary = validationDictionary; _messagesRepository = new MessagesRepository(); MessageTypeService = new MessageTypeService(validationDictionary); }
public void ReadSingleEntityAllNotNullTest() { _dataReader.Expect(x => x.IsDBNull(1)).Repeat.Once().Return(false); _dataReader.Expect(x => x.IsDBNull(3)).Repeat.Once().Return(false); _dataReader.Expect(x => x.GetInt32(0)).Return(_message.Key).Repeat.Once(); _dataReader.Expect(x => x.GetString(1)).Return(_message.MessageText).Repeat.Once(); _dataReader.Expect(x => x.GetInt32(2)).Return(_message.FromId).Repeat.Once(); _dataReader.Expect(x => x.GetInt32(3)).Return((int)_message.ToId).Repeat.Once(); _dataReader.Expect(x => x.GetDateTime(4)).Return(_message.CreatedOn).Repeat.Once(); _mockRepository.ReplayAll(); MessagesRepository devicesRepository = new MessagesRepository(_dbWrapper); Message actual = devicesRepository.ReadSingleEntity(_dataReader); Assert.AreEqual(_message.Key, actual.Key); Assert.AreEqual(_message.MessageText, actual.MessageText); Assert.AreEqual(_message.FromId, actual.FromId); Assert.AreEqual(_message.ToId, actual.ToId); _mockRepository.VerifyAll(); }
public MessageController() { this.messageRepo = DaoFactory.getDao( DaoFactory.MySql ).getMessagesRepository(); }