Ejemplo n.º 1
0
        public void NotificationMessageHandler_RethrowsException()
        {
            // arrange
            _actionHelperMock.Setup(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>())).Throws(new TestException());
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Once);
        }
Ejemplo n.º 2
0
        public void BaseMessageHandler_ThrowsUnsupportedActionTypeException_WhenActionTypeIsNotSupported()
        {
            // arrange
            _configHelperMock.Setup(m => m.SupportedActionTypes).Returns(MessageActionType.None);
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Never);
        }
Ejemplo n.º 3
0
        public void BaseMessageHandler_DiscardsMessage_WhenTransactionIsRolledBack()
        {
            // arrange
            _transactionValidatorMock.Setup(m => m.GetStatus(It.IsAny <ActionMessage>(), It.IsAny <TenantInformation>(), It.IsAny <BaseRepository>())).ReturnsAsync(TransactionStatus.RolledBack);
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Never);
        }
Ejemplo n.º 4
0
        public void BaseMessageHandler_ThrowsMessageHeaderValueNotFoundException_WhenHeaderValueIsNotFound()
        {
            // arrange
            _actionHelperMock.Setup(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>())).Returns(Task.FromResult(true));
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            // sends the message without setting headers
            Test.Handler(handler).OnMessage(message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Never);
        }
Ejemplo n.º 5
0
        public void NotificationMessageHandler_HandlesMessageSuccessfully()
        {
            // arrange
            _actionHelperMock.Setup(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>())).Returns(Task.FromResult(true));
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            Assert.IsNotNull(handler);
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Once);
        }
        public void SetUp()
        {
            _repo                = new Mock <INotificationsRepo>();
            _messageGenerator    = new Mock <INotificationMessageGenerator>();
            _messageDispatcher   = new Mock <INotificationMessageDispatcher>();
            _currentUserAccessor = new Mock <ICurrentUserAccessor>();

            _sut = new NotificationMessageHandler(_repo.Object, _messageGenerator.Object, _messageDispatcher.Object,
                                                  _currentUserAccessor.Object);


            _event = CoursePublishedEvent.Instance;
            _currentUserAccessor.Setup(x => x.OrganizationId).Returns("organizationId");
        }
Ejemplo n.º 7
0
        public void BaseMessageHandler_ThrowsException_WhenNoTenantsAreFound()
        {
            // arrange
            var noTenants = new Dictionary <string, TenantInformation>();

            _tenantInfoRetrieverMock.Setup(m => m.GetTenants()).ReturnsAsync(noTenants);
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Never);
        }
Ejemplo n.º 8
0
        public void BaseMessageHandler_ThrowsException_WhenTheRightTenantIsNotFound()
        {
            // arrange
            var tenant = new TenantInformation
            {
                TenantId = TenantId + "different"
            };
            var wrongTenant = new Dictionary <string, TenantInformation>
            {
                { tenant.TenantId, tenant }
            };

            _tenantInfoRetrieverMock.Setup(m => m.GetTenants()).ReturnsAsync(wrongTenant);
            var handler = new NotificationMessageHandler(_actionHelperMock.Object, _tenantInfoRetrieverMock.Object, _configHelperMock.Object, _transactionValidatorMock.Object);
            var message = new NotificationMessage();

            // act
            TestHandlerAndMessageWithHeader(handler, message);
            // assert
            _actionHelperMock.Verify(m => m.HandleAction(It.IsAny <TenantInformation>(), It.IsAny <ActionMessage>(), It.IsAny <BaseRepository>()), Times.Never);
        }
Ejemplo n.º 9
0
 public HomeController(WaveChatContext context, UserManager <WaveChat.Areas.Identity.Data.WaveChatUser> userManager, NotificationMessageHandler notificationsMessageHandler)
 {
     _context     = context;
     _userManager = userManager;
     _notificationsMessageHandler = notificationsMessageHandler;
 }