public ActionResult ActivateUserConfirmed(string id, bool?invite) { User user = CompositionRoot.DocumentSession.Load <User>(id); if (user == null) { throw new HttpException(404, "User not found"); } if (user.IsActive) { user.Deactivate(); } else { if (invite.GetValueOrDefault()) { Debug.Assert(Request.Url != null, "Request.Url != null"); TaskPublisher taskPublisher = GetTaskPublisher(); user.ActivateWithEmail( t => taskPublisher.PublishTask(t, User.Identity.Name), Url, Request.Url !.Scheme); } else { user.Activate(); } } return(RedirectToAction("Users")); }
public void RegisterTask_EmailNotification_NotificationRegistered() { // Arrange EmailNotificationRegister notification = new EmailNotificationRegister("*****@*****.**", "plain text content"); string payload = JsonConvert.SerializeObject(notification); byte[] body = Encoding.UTF8.GetBytes(payload); Mock <IBasicProperties> basicPropertiesMock = new Mock <IBasicProperties>(); basicPropertiesMock.Setup(x => x.Persistent) .Verifiable(); Mock <IModel> modelMock = new Mock <IModel>(); modelMock.Setup(x => x.QueueDeclare(It.IsAny <string>(), It.Is <bool>(x => x), It.Is <bool>(x => x == false), It.Is <bool>(x => x == false), null)) .Verifiable(); modelMock.Setup(x => x.BasicQos(It.Is <uint>(x => x == 0), It.Is <ushort>(x => x == 1), It.Is <bool>(x => x == false))) .Verifiable(); modelMock.Setup(x => x.CreateBasicProperties()) .Returns(basicPropertiesMock.Object) .Verifiable(); modelMock.Setup(x => x.BasicPublish(It.IsAny <string>(), It.Is <string>(x => x == Subject.EMAIL.ToString()), It.Is <bool>(x => x == false), It.IsAny <IBasicProperties>(), It.IsAny <ReadOnlyMemory <byte> >())) .Verifiable(); Mock <IConnection> connectionMock = new Mock <IConnection>(); connectionMock.Setup(x => x.CreateModel()) .Returns(modelMock.Object); Mock <IRabbitMQConnectionFactory> connectionFactoryMock = new Mock <IRabbitMQConnectionFactory>(); connectionFactoryMock.CallBase = true; connectionFactoryMock.Setup(x => x.CreateConnection()) .Returns(connectionMock.Object); ITaskPublisher taskPublisher = new TaskPublisher(connectionFactoryMock.Object); // Act taskPublisher.RegisterTask(payload, Subject.EMAIL); // Assert connectionFactoryMock.Verify(); connectionMock.Verify(); modelMock.Verify(); }
public LibraryController(/*SchedulerService schedulerService ,*/ IWebHostEnvironment env, IOptions <MusicServerOptions> mso, /*IServiceProvider sp,*/ TaskPublisher tp, TaskRunner tr, IOptionsMonitor <MusicOptions> mo, ILogger <LibraryController> logger, MusicDb mdb) : base(logger, env) { this.musicOptions = mo.CurrentValue; //this.ss = schedulerService;// hs as SchedulerService; mo.OnChangeWithDelay((opt) => { this.musicOptions = opt; }); this.contentRootPath = env.ContentRootPath; this.log = logger; this.musicServerOptions = mso.Value; this.musicDb = mdb; this.taskPublisher = tp; this.taskRunner = tr; }
private Task CreateTask(BackupSet bs, TaskStartupType taskType, User u, BackupLevel?overridenLevel) { if (TasksQueueExists(bs)) { return(null); } Task newBackup = new Task(bs, taskType); newBackup.Operation = bs.Operation; newBackup.NodeId = bs.NodeId; newBackup.CurrentAction = "Initializing"; newBackup.RunStatus = TaskRunningStatus.PendingStart; newBackup.StartDate = DateTime.Now; if (overridenLevel.HasValue) { newBackup.Level = overridenLevel.Value; } else if (bs.ScheduleTimes.Count == 1) { newBackup.Level = bs.ScheduleTimes[0].Level; } else { newBackup.Level = BackupLevel.Refresh; } if (u != null) { newBackup.UserId = u.Id; Logger.Append("HUBRN", Severity.DEBUG, "User " + u.Id + " (" + u.Name + ") started new task for backupset " + bs.Id + " with level " + newBackup.Level + " (client #" + bs.NodeId + ")"); } // set an encryption key newBackup.EncryptionKey = Convert.ToBase64String(Guid.NewGuid().ToByteArray()); newBackup = new DAL.TaskDAO().Save(newBackup); TasksQueue.Add((Task)newBackup); Logger.Append("RUN", Severity.TRIVIA, "Created new task for scheduled backupset " + bs.ToString()); TaskPublisher.Instance().Notify(newBackup); return(newBackup); }