public UserModel InspectGuid(TGuid uid) { string re; var user = DataContext.userModels .Where(x => x.User == uid.User) .Include(x => x.personnel_Words) .SingleOrDefault(); if (user == null) { return(null); } else if (user.Uid != uid.Uid) { return(null); } if (DateTime.Now >= user.DateTime.AddDays(1)) { user.DateTime = DateTime.Now; re = Guid.NewGuid().ToString(); user.Uid = re; DataContext.Attach(user); DataContext.SaveChanges(); } return(user); }
public void GetUsersForEventNotification_WhenEventTypeIsAppoitedOrDisappointedWorkItem_ReturnExpectedUser(int workItemNumber, EventType eventType, int relatedUserNumber, int currentUserId) { var relatedUserId = new TGuid(relatedUserNumber).ToGuid().ToString(); var usersService = CreateUserRepository(currentUserId); var workItemRepository = TestHelper.CreateFilledWorkItemRepository(usersService); var provider = CreateProvider(usersService, workItemRepository); var users = provider.GetUsersForEventNotification(CreateEvent(currentUserId, workItemNumber, eventType, relatedUserId)); Assert.AreEqual(1, users.Count); Assert.AreEqual(relatedUserId, users.Single().Id); }
public void Notify_WhenEventAddToCurrentUser_MakeEventSeen() { var currentUserId = new TGuid(3).ToGuid().ToString(); var eventRepo = CreateEventRepository(); var notificator = CreateNotificator(eventRepo); var workEvent = CreateEvent(currentUserId); notificator.Notify(workEvent, new[] { new ApplicationUser { Id = currentUserId } }); Assert.IsTrue(eventRepo.EventsUsers.All(x => x.State == EventState.Seen)); }
public void Notify_WhenEventIsValid_AddEventForExpectedUsers(int currentUserNumber, int[] users, int expectedEventUserCount) { var currentUserId = new TGuid(currentUserNumber).ToGuid().ToString(); var eventRepo = CreateEventRepository(); var notificator = CreateNotificator(eventRepo); var workEvent = CreateEvent(currentUserId); notificator.Notify(workEvent, users.Select(x => new ApplicationUser { Id = new TGuid(x).ToGuid().ToString() }).ToArray()); Assert.AreEqual(1, eventRepo.Events.Count); Assert.AreEqual(expectedEventUserCount, eventRepo.EventsUsers.Count); }
public void AddEvent_WhenEventAddToCurrentUser_MakeEventSeen() { var currentUserId = new TGuid(3).ToGuid().ToString(); var userRepo = CreateUserRepository(); userRepo.SetCurrentUser(currentUserId); var eventRepo = CreateTestEventRepository(); var service = CreateService(eventRepo, userRepo); var workEvent = CreateEvent(currentUserId); service.AddEvent(workEvent, new [] { currentUserId }); Assert.IsTrue(eventRepo.EventsUsers.All(x => x.State == EventState.Seen)); }
public void AddEvent_WhenEventAddToOtherUsers_MakeEventNew() { var currentUserId = new TGuid(0).ToGuid().ToString(); var userRepo = CreateUserRepository(); userRepo.SetCurrentUser(currentUserId); var eventRepo = CreateTestEventRepository(); var service = CreateService(eventRepo, userRepo); var workEvent = CreateEvent(currentUserId); service.AddEvent(workEvent, (new[] { 2, 3, 5, 6 }).Select(x => new TGuid(x).ToGuid().ToString())); Assert.IsTrue(eventRepo.EventsUsers.All(x => x.State == EventState.New)); }
public void AddEvent_WhenEventIsValid_AddEventForExpectedUsers(int currentUserNumber, int[] users) { var currentUserId = new TGuid(currentUserNumber).ToGuid().ToString(); var userRepo = CreateUserRepository(); userRepo.SetCurrentUser(currentUserId); var eventRepo = CreateTestEventRepository(); var service = CreateService(eventRepo, userRepo); var workEvent = CreateEvent(currentUserId); service.AddEvent(workEvent, users.Select(x => new TGuid(x).ToGuid().ToString())); Assert.AreEqual(1, eventRepo.Events.Count); Assert.AreEqual(users.Length, eventRepo.EventsUsers.Count); }
[TestCase(0, 0)] //директор добавляет задачу без исполнителя в свой раздел public void Add_WhenExecutorIsNotSet_SendExpectedEventNotifications(int currentUserNumber, int parentItemExecutor) { var userRepository = CreateUserRepository(); var curentUserId = new TGuid(currentUserNumber).ToGuid().ToString(); userRepository.SetCurrentUser(curentUserId); var workItemRepository = TestHelper.CreateFilledWorkItemRepository(userRepository); var notifyService = CreateTestNotifyService(); var service = CreateService(workItemRepository, userRepository, notifyService); var workItem = CreateWorkItem(workItemRepository, curentUserId, new TGuid(parentItemExecutor).ToGuid().ToString()); service.Add(workItem); Assert.AreEqual(curentUserId, workItem.CreatorId); Assert.AreEqual(1, notifyService.SendedRealtimeEvents.Count); Assert.AreEqual(1, notifyService.SendedEventNotifications.Count); Assert.IsTrue(notifyService.SendedEventNotifications.All(x => x.Type == EventType.WorkItemAdded)); }