public void Method_Authentication_When_ParameterRequestIsNull_Should_ThrowInvalidCastException() { _employeeApplicationService = new EmployeeApplicationService(_employeeServiceMock.Object, _unitOfWorkMock.Object); Assert.ThrowsExceptionAsync <InvalidCastException>(() => _employeeApplicationService.AuthenticationAsync(null)); }
public void Method_Authentication_When_ParameterRequestBarcodeNotFoundInDataBase_Should_ReturnNullAndNotification() { _employeeServiceMock.Setup(item => item.AuthenticationByUsernameAsync(It.IsAny <Employee>())).Returns((Task <Employee>)null); _employeeApplicationService = new EmployeeApplicationService(_employeeServiceMock.Object, _unitOfWorkMock.Object); var dynamicRequest = JObject.Parse(RequestBarcode); var employeeAuth = _employeeApplicationService.AuthenticationAsync(dynamicRequest); Assert.IsNull(employeeAuth.Result); Assert.IsTrue(_employeeApplicationService.ListNotifications().Any()); }
public void Method_Authentication_When_ParameterRequestBarcodeIsValid_Should_Return_EmployeeAuthenticated() { _employeeServiceMock.Setup(item => item.AuthenticationByBarcodeAsync(It.IsAny <Employee>())) .Returns(_employeeTask); _employeeApplicationService = new EmployeeApplicationService(_employeeServiceMock.Object, _unitOfWorkMock.Object); var dynamicRequest = JObject.Parse(RequestBarcode); var employeeAuth = _employeeApplicationService.AuthenticationAsync(dynamicRequest); Assert.IsNotNull(employeeAuth); Assert.IsTrue(employeeAuth.Result.EmployeeNumber > 0); Assert.AreEqual(0, _employeeApplicationService.ListNotifications().Count()); }
public async Task <IActionResult> Authentication([FromBody] dynamic request) { if (request == null) { return(BadRequest(Messages.ERROR_BAD_REQUEST)); } Employee employeeAuth = await _employeeApplicationService.AuthenticationAsync(request); if (employeeAuth == null) { return(await Response(string.Empty, _employeeApplicationService.ListNotifications())); } var token = new JwtTokenBuilder() .AddSecurityKey(JwtSecurityKey.Create(Runtime.SecurityKey)) .AddSubject("Authentication") .AddIssuer(Runtime.Issuer) .AddAudience(Runtime.Audience) .AddClaim("Employee", employeeAuth.EmployeeNumber.ToString()) .AddClaim("UserName", employeeAuth.UserName) .AddClaim("FirstName", employeeAuth.FirstName) .AddClaim(ClaimTypes.Name, employeeAuth.UserName) .AddExpiry(1) .Build(); var response = new { access_token = token.Value, expires_in = token.ValidTo.ToLongDateString(), employee = new { employeenumber = employeeAuth.EmployeeNumber, username = employeeAuth.UserName, firstname = employeeAuth.FirstName, lastname = employeeAuth.LastName, barcode = employeeAuth.Barcode } }; return(await Response(response, _employeeApplicationService.ListNotifications())); }