public void GetUserNotifications() { var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); using (var repo = new NotificationsRepository(unitOfWork)) { var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "******", MediaStartId = -1, Password = "******", Type = 1, UserName = "******", UserLanguage = "en" }; unitOfWork.Database.Insert(userDto); var userNew = Mock.Of <IUser>(e => e.Id == userDto.Id); var userAdmin = Mock.Of <IUser>(e => e.Id == 0); for (var i = 0; i < 10; i++) { var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 }; var result = unitOfWork.Database.Insert(node); var entity = Mock.Of <IEntity>(e => e.Id == node.NodeId); var notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture)); } var notifications = repo.GetUserNotifications(userAdmin); Assert.AreEqual(5, notifications.Count()); } }
public void GetUserNotifications() { IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var repo = new NotificationsRepository((IScopeAccessor)provider); var userDto = new UserDto { Email = "test", Login = "******", Password = "******", UserName = "******", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of <IUser>(e => e.Id == userDto.Id); IUser userAdmin = Mock.Of <IUser>(e => e.Id == Constants.Security.SuperUserId); for (int i = 0; i < 10; i++) { var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of <IEntity>(e => e.Id == node.NodeId); Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture)); } IEnumerable <Notification> notifications = repo.GetUserNotifications(userAdmin); Assert.AreEqual(5, notifications.Count()); } }
/// <summary> /// Gets the notifications for the user /// </summary> /// <param name="user"></param> /// <returns></returns> public IEnumerable <Notification> GetUserNotifications(IUser user) { var uow = _uowProvider.GetUnitOfWork(); var repository = new NotificationsRepository(uow); return(repository.GetUserNotifications(user)); }