public AtualizarUsuarioCommandHandlerTest() { _mediator = new Mock <IMediator>(); _repository = new Mock <IUsuarioRepository>(); _uow = new Mock <IUnitOfWork>(); _service = new Mock <IUsuarioService>(); _notifications = new DomainNotificationHandler(); _handler = new AtualizarUsuarioCommandHandler(_mediator.Object, _uow.Object, _repository.Object, _service.Object, _notifications); _uow.Setup(uow => uow.Commit()).ReturnsAsync(CommandResponse.Ok); _service.Setup(s => s.VincularAoPerfilAsync(It.IsAny <Guid>(), It.IsAny <Usuario>())) .ReturnsAsync(true); _service.Setup(s => s.DisponivelEmailECpfAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>())) .ReturnsAsync(true); _repository.Setup(u => u.ObterPorIdAsync(It.IsAny <Guid>())) .ReturnsAsync(UsuarioBuilder.UsuarioFake()); }
public async void GetNotificationsError_Ok() { var faker = new Faker(); var message = faker.Lorem.Sentence(); var handler = new DomainNotificationHandler(); var domainNotification = DomainNotification.Fail(message); await handler.Handle(domainNotification, new CancellationToken()); var notifications = handler.GetNotificationsError(); var result = notifications.Select(x => x.Value); Assert.Contains(message, result); }
public AccountController( SignInManager <UserIdentity> signInManager, IUserAppService userAppService, IIdentityServerInteractionService interaction, IClientStore clientStore, IAuthenticationSchemeProvider schemeProvider, IEventService events, INotificationHandler <DomainNotification> notifications, IConfiguration configuration) { _signInManager = signInManager; _userAppService = userAppService; _interaction = interaction; _clientStore = clientStore; _schemeProvider = schemeProvider; _events = events; _configuration = configuration; _notifications = (DomainNotificationHandler)notifications; }
// Identity: Video 16 Eduardo Pires public RegisterModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, // Identity: Video 16 Eduardo Pires INotificationHandler <DomainNotification> notifications, IOrganizadorAppService organizadorAppService, IUser user) // : base(notifications) -- Identity: Não estamos mandando as notificações para BaseControler { _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; // Identity: Video 16 Eduardo Pires - (não consegui passar notifications como : base(notifications) _notifications = (DomainNotificationHandler)notifications; _organizadorAppService = organizadorAppService; _user = user; }
public async Task CadastroFiel(CadastroFielViewModel cadastroFielViewModel) { if (cadastroFielViewModel.EhValido()) { var fiel = _mapper.Map <FielViewModel>(cadastroFielViewModel); await _cadastroService.CadastroFiel(fiel); if (await _fielIunitOfWork.Commit()) { var cadastroEvent = new FielCadastradoEvent(cadastroFielViewModel.Email, cadastroFielViewModel.Telefone, cadastroFielViewModel.NomeFiel); await _mediatrHandler.PublicarEvento <FielCadastradoEvent>(cadastroEvent); } } foreach (var erro in cadastroFielViewModel.Erros()) { DomainNotificationHandler.AddNotification(new DomainNotification(erro.PropertyName, erro.ErrorMessage)); } }
public void AuthenticateApplicationService_Authenticate_invalid_password() { var user = new UserBuilder().WithEmail("*****@*****.**").WithPassword("qwe123").Builder(); _userRepository.Add(user); _unitOfWork.Commit(); var model = new AuthenticateModel { Email = user.Email, Password = "******" }; var result = _authenticateApplicationService.Authenticate(model); result.Token.Should().BeNullOrEmpty(); result.User.Should().BeNull(); DomainNotificationHandler.HasNotifications().Should().BeTrue(); DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.InvalidPassoword); }
public UserAppService( IStaticCacheManager cacheManager, IMediatorHandler bus, INotificationHandler <DomainNotification> notifications, IUserRepository userRepository, [NotNull] ILogger <UserAppService> logger, [NotNull] IPermissionRepository permissionRepository, [NotNull] IAuthorizationService authorizationService ) { _cacheManager = cacheManager ?? throw new ArgumentNullException(nameof(cacheManager)); _bus = bus ?? throw new ArgumentNullException(nameof(bus)); _notifications = (DomainNotificationHandler)notifications; _userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _permissionRepository = permissionRepository ?? throw new ArgumentNullException(nameof(permissionRepository)); _authorizationService = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService)); }
public void UserApplicationService_Disable_not_found() { var currentUser = new UserBuilder().WithProfile(ProfileType.Administrator).Builder(); _userRepository.Add(currentUser); _unitOfWork.Commit(); _requestScope.SetUserId(currentUser.Id); var user = new UserBuilder().WithProfile(ProfileType.Standard).WithActive(true).Builder(); _userRepository.Add(user); _unitOfWork.Commit(); _userApplicationService.Disable(Guid.NewGuid()); var result = _userRepository.GetById(user.Id); result.Active.Should().BeTrue(); DomainNotificationHandler.HasNotifications().Should().BeTrue(); DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.UserNotFound); }
public void UserApplicationService_Disable_without_permission() { var currentUser = new UserBuilder().WithProfile(ProfileType.Standard).Builder(); _userRepository.Add(currentUser); _unitOfWork.Commit(); _requestScope.SetUserId(currentUser.Id); var user = new UserBuilder().WithProfile(ProfileType.Standard).WithActive(true).Builder(); _userRepository.Add(user); _unitOfWork.Commit(); _userApplicationService.Disable(user.Id); var result = _userRepository.GetById(user.Id); result.Active.Should().BeTrue(); DomainNotificationHandler.HasNotifications().Should().BeTrue(); DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.StandardProfileUserDoesNotHavePermission); }
public async void DomainNotificationClear_Ok() { var faker = new Faker(); var handler = new DomainNotificationHandler(); var qtError = faker.Random.Int(min: 3, max: 10); var qtSuccess = faker.Random.Int(min: 3, max: 10); for (var i = 0; i < qtError; i++) { var message = faker.Lorem.Sentence(); var domainNotification = DomainNotification.Fail(message); await handler.Handle(domainNotification, new CancellationToken()); } for (var i = 0; i < qtSuccess; i++) { var message = faker.Lorem.Sentence(); var domainNotification = DomainNotification.Success(message); await handler.Handle(domainNotification, new CancellationToken()); } handler.Clear(); var notificationsError = handler.GetNotificationsError(); var notificationsSuccess = handler.GetNotificationsSuccess(); Assert.False(handler.HasNotificationsError()); Assert.False(handler.HasNotificationsSucess()); Assert.True(notificationsError.Count == 0); Assert.True(notificationsSuccess.Count == 0); }
public AccountController( IMediatorHandler bus, IStringLocalizer <AccountController> localizer, IIdentityServerInteractionService interaction, IClientStore clientStore, IAuthenticationSchemeProvider schemeProvider, IEventService events, IUserService users, SignInManager <ApplicationUser> signInManager, INotificationHandler <DomainNotification> notifications) { _bus = bus; _localizer = localizer; _users = users; _interaction = interaction; _clientStore = clientStore; _schemeProvider = schemeProvider; _events = events; _signInManager = signInManager; _notifications = (notifications as DomainNotificationHandler) ?? throw new ArgumentNullException(nameof(_notifications)); }
public void UserApplicationService_Delete_without_permission() { var currentUser = new UserBuilder().WithProfile(ProfileType.Standard).Builder(); _userRepository.Add(currentUser); _unitOfWork.Commit(); _requestScope.SetUserId(currentUser.Id); var user = new UserBuilder().WithProfile(ProfileType.Standard).Builder(); _userRepository.Add(user); _unitOfWork.Commit(); var result = _userRepository.Get(new Filter()); _userApplicationService.Delete(user.Id); result.totalItems.Should().Be(2); result.entities.Should().HaveCount(2); DomainNotificationHandler.HasNotifications().Should().BeTrue(); DomainNotificationHandler.GetNotifications.First().Value.Should().Be(DomainError.StandardProfileUserDoesNotHavePermission); }
public async void Handle_GivenUnknownCredentials_ShouldFail() { // arrange var mockUserRepository = new Mock <IUserRepository>(); mockUserRepository.Setup(repo => repo.FindByName(It.IsAny <string>())).ReturnsAsync((User)null); mockUserRepository.Setup(repo => repo.CheckPassword(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(true); var mockJwtFactory = new Mock <IJwtFactory>(); mockJwtFactory.Setup(factory => factory.GenerateEncodedToken(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(new AccessToken("", 0)); var mockTokenFactory = new Mock <ITokenFactory>(); var presenter = new LoginPresenter(); var mockMediatorHandler = new Mock <IMediatorHandler>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.Commit()).Returns(true); var notificationHandler = new DomainNotificationHandler(); var handler = new LoginHandler(mockUserRepository.Object, mockJwtFactory.Object, mockTokenFactory.Object, mockUnitOfWork.Object, mockMediatorHandler.Object, notificationHandler); var mockOutputPort = new Mock <IOutputPort <LoginResponse> >(); mockOutputPort.Setup(outputPort => outputPort.Handle(It.IsAny <LoginResponse>())); // act await handler.Handle(new LoginRequest("", "password", "127.0.0.1"), mockOutputPort.Object); // assert Assert.Null(presenter.data); mockTokenFactory.Verify(factory => factory.GenerateToken(32), Times.Never); }
private static void Publish <T>(T message) where T : Message { var msgType = message.MessageType; if (msgType.Equals("DomainNotification")) { var obj = new DomainNotificationHandler(); ((IDomainNotificationHandler <T>)obj).Handle(message); } if (msgType.Equals("RegistrarEventoCommand") || msgType.Equals("AtualizarEventoCommand") || msgType.Equals("ExcluirEventoCommand")) { var obj = new EventoCommandHandler(new FakeRepository(), new FakeUow(), new FakeBus(), new DomainNotificationHandler()); ((IHandler <T>)obj).Handle(message); } if (msgType.Equals("EventoRegistradoEvent") || msgType.Equals("EventoAtualizadoEvent") || msgType.Equals("EventoExcluidoEvent")) { var obj = new EventoEventHandler(); ((IHandler <T>)obj).Handle(message); } }
private static void Publish <T>(T message) where T : Message { var msgType = message.MessageType; if (msgType.Equals("DomainNotification")) { var obj = new DomainNotificationHandler(); ((IDomainNotificationHandler <T>)obj).Handle(message); } if (msgType.Equals("RegistrarParticipanteCommand") || msgType.Equals("AtualizarParticipanteCommand") || msgType.Equals("RemoverParticipanteCommand")) { var obj = new ParticipanteCommandHandler(new FakeUow(), new FakeBus(), new DomainNotificationHandler(), new FakeParticipanteRepository()); ((IHandler <T>)obj).Handle(message); } ; if (msgType.Equals("RegistrarParticipanteEvent") || msgType.Equals("AtualizarParticipanteEvent") || msgType.Equals("RemoverParticipanteEvent")) { var obj = new ParticipanteEventHandler(); ((IHandler <T>)obj).Handle(message); } }
public void InitTests() { db = GetDbInstance(); _unitOfWork = new UnitOfWork(db); _userRepository = new UserRepository(db); _mockMediator = new Mock <IMediatorHandler>(); _domainNotificationHandler = new DomainNotificationHandler(); _mockMediator.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())).Callback <DomainNotification>((x) => { _domainNotificationHandler.Handle(x, CancellationToken.None); }); _mapper = AutoMapperConfig.RegisterMappings().CreateMapper(); _userRepository.Add(new User { Email = "*****@*****.**", Name = "Test", Password = Cryptography.PasswordEncrypt("123456") }); _unitOfWork.Commit(); var mockConfig = new Mock <IConfiguration>(); mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Issuer"))]) .Returns("Test"); mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Duration"))]) .Returns("120"); mockConfig.Setup(x => x[It.Is <string>(s => s.Equals("Jwt:Key"))]) .Returns("IZpipYfLNJro403p"); _loginService = new LoginService(_userRepository, mockConfig.Object); handler = new LoginHandler(_unitOfWork, _userRepository, _mockMediator.Object, _mapper, _loginService); }
public static TResponse checkHasNotification(DomainNotificationHandler _notifications, TResponse response) { if (_notifications.HasNotifications()) { if (_notifications.GetNotifications().Any(x => x.ResultCode == NotificationCode.Error)) { foreach (var item in _notifications.GetNotifications()) { response.Message += item.request + "; "; } } _notifications.Dispose(); response.Success = false; response.Status = (int)StatusCode.Error; } else { response.Status = (int)StatusCode.Success; response.Message = StatusCode.Success.ToString(); response.Success = true; } return(response); }
protected ApiBaseController(INotificationHandler <DomainNotification> notifications, IDomainNotificationMediatorService mediator) { _notifications = (DomainNotificationHandler)notifications; _mediator = mediator; }
public LevantamentoContext(DbContextOptions <LevantamentoContext> options, IMediator mediator, INotificationHandler <DomainNotification> notifications) : base(options) { _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _notifications = (DomainNotificationHandler)notifications ?? throw new ArgumentNullException(nameof(notifications)); }
protected BaseApiController(INotificationHandler <DomainNotification> notifications, IMediatorHandler mediator) { _notifications = (DomainNotificationHandler)notifications; _mediator = mediator; }
public SummaryViewComponent(INotificationHandler <DomainNotification> notifications) { _notifications = (DomainNotificationHandler)notifications; }
public BaseController(INotificationHandler <DomainNotification> notifications) { _notifications = (DomainNotificationHandler)notifications; }
protected ApiController(INotificationHandler <DomainNotification> notifications) { _notifications = (DomainNotificationHandler)notifications; }
public CommandHandler(IUnitOfWork uow, IMediatorHandler mediatorHandler, INotificationHandler <DomainNotification> domainNotification) { _unitOfWork = uow; _mediatorHandler = mediatorHandler; _domainNotifications = (DomainNotificationHandler)domainNotification; }
public HeaderViewComponent(UserManager <ApplicationUser> userManager, INotificationHandler <DomainNotification> notifications) { _notifications = (DomainNotificationHandler)notifications; _userManager = userManager; }
protected ApiController(IMediator bus, INotificationHandler <DomainNotification> notifications) { Bus = bus; _notifications = (DomainNotificationHandler)notifications; }
public BaseApiController(INotificationHandler <DomainNotification> notifications) { this.notifications = (DomainNotificationHandler)notifications; }
public ApiController(IMediatorHandler mediator) { _notifications = (DomainNotificationHandler)mediator.GetNotificationHandler(); Mediator = mediator; }
protected CommandHandler(IUnitOfWork uow, IMediatorHandler bus, INotificationHandler <DomainNotification> notifications) { _uow = uow; _notifications = (DomainNotificationHandler)notifications; _bus = bus; }
public CommandHandler(IMediatorHandler bus, INotificationHandler <DomainNotification> notifications) { _notifications = (DomainNotificationHandler)notifications; _bus = bus; }