public void AuthClient_IfIsValidReturnTokenElseNull(string user, string password) { //arrage var mockRepo = new Mock <IClientRepository>(); mockRepo .Setup(r => r.ValidClient(It.IsAny <string>(), It.IsAny <string>())) .Returns(ListClient().FirstOrDefault(c => c.UserName == user && c.Password == password)); var mockToken = new Mock <ITokenHelper>(); mockToken.Setup(t => t.GenerateToken(It.IsAny <ClientEntity>())).Returns($"{user + password}"); var service = new AuthServiceHandler(mockRepo.Object, mockToken.Object); var expectClient = ListClient().FirstOrDefault(c => c.UserName == user && c.Password == password); var expect = expectClient != null ? $"{expectClient.UserName + expectClient.Password}" : null; //act var result = service.AuthClient(new ClientLoginRequest() { UserName = user, Password = password }); //assert mockRepo.Verify(r => r.ValidClient(It.IsAny <string>(), It.IsAny <string>()), Times.Once); if (expectClient != null) { mockToken.Verify(r => r.GenerateToken(It.IsAny <ClientEntity>()), Times.Once); } Assert.Equal(expect, result); }
/// <summary> /// Stops the service immediately, terminating any user activity. /// </summary> public void Stop() { lock (syncLock) { if (state == ServiceState.Stopped) { return; } SysLog.LogInformation("Authentication Service Stop"); SysLog.Flush(); base.Close(); state = ServiceState.Stopped; if (handler != null) { handler.Stop(); handler = null; } if (router != null) { router.Stop(); router = null; } Program.PerfCounters.Zero(); } }
private ServiceState state; // Current service state /// <summary> /// Constructor. /// </summary> public AppService() { this.router = null; this.handler = null; this.state = ServiceState.Stopped; // Prepare the service to accept remote ServiceControl commands. base.Open(); }
/// <summary> /// Handles the performance counter installation if they don't /// already exist. /// </summary> /// <returns>The application's <see cref="PerfCounterSet" />.</returns> public static PerfCounterSet InstallPerfCounters() { bool exists = PerformanceCounterCategory.Exists(Const.AuthServicePerf); PerfCounterSet perfCounters; perfCounters = new PerfCounterSet(false, true, Const.AuthServicePerf, Const.AuthServiceName); if (!exists) { AuthServiceHandler.InstallPerfCounters(perfCounters, null); AuthenticationEngine.InstallPerfCounters(perfCounters, null); perfCounters.Install(); } return(perfCounters); }
/// <summary> /// Starts the service, associating it with an <see cref="IServiceHost" /> instance. /// </summary> /// <param name="serviceHost">The service user interface.</param> /// <param name="args">Command line arguments.</param> public void Start(IServiceHost serviceHost, string[] args) { lock (syncLock) { if (router != null) { return; // Already started } // Global initialization NetTrace.Start(); Program.Config = new Config("LillTek.Datacenter.AuthService"); Program.InstallPerfCounters(); // Service initialization this.serviceHost = serviceHost; SysLog.LogInformation("Authentication Service v{0} Start", Helper.GetVersionString()); try { router = new LeafRouter(); router.Start(); handler = new AuthServiceHandler(); handler.Start(router, null, Program.PerfCounters, null); state = ServiceState.Running; } catch (Exception e) { router = null; SysLog.LogException(e); throw; } } }