Example #1
0
        /// <exception cref="NotSupportedMessageException">Raised when message type is not supported</exception>
        public IMessageHandler CreateHandler <T>()
        {
            var configuration   = new AppConfigConfiguration();
            var csProvider      = new ConnectionStringProvider();
            var dbCommands      = new DatabaseCommands(csProvider, configuration);
            var messagingLogger = new MessagingLogger(dbCommands);

            if (typeof(T) == typeof(PriceBandUpdated))
            {
                var validator = new PriceBandUpdatedValidator(dbCommands);
                return(new PriceBandEventHandler(dbCommands, validator, messagingLogger, configuration));
            }

            if (typeof(T) == typeof(AccountCreated))
            {
                var validator = new AccountCreatedValidator(dbCommands);
                var handler   = new AccountCreatedEventHandler(dbCommands, validator, configuration, messagingLogger);
                handler.OnProcessed += SendMessage;
                return(handler);
            }

            if (typeof(T) == typeof(AccountCreateFailed))
            {
                var validator = new AccountCreateFailedValidator(dbCommands);
                return(new AccountCreateFailedEventHandler(dbCommands, validator, messagingLogger));
            }

            if (typeof(T) == typeof(AccountUpdated))
            {
                var validator = new AccountUpdatedValidator(dbCommands);
                return(new AccountUpdatedEventHandler(dbCommands, validator, messagingLogger));
            }

            if (typeof(T) == typeof(AccountUpdateFailed))
            {
                var validator = new AccountUpdateFailedValidator(dbCommands);
                return(new AccountUpdateFailedEventHandler(dbCommands, validator, messagingLogger));
            }
            if (typeof(T) == typeof(AccountStatusChanged))
            {
                var validator = new AccountStatusChangedValidator(dbCommands);
                return(new AccountStatusChangedEventHandler(dbCommands, validator, messagingLogger));
            }
            if (typeof(T) == typeof(AccountStatusChangeFailed))
            {
                var validator = new AccountStatusChangeFailedValidator(dbCommands);
                return(new AccountStatusChangeFailedEventHandler(dbCommands, validator, messagingLogger));
            }
            if (typeof(T) == typeof(FileUploadCompleted))
            {
                var validator = new FileUploadEventValidator(dbCommands);
                return(new FileUploadCompletedHandler(dbCommands, validator, messagingLogger));
            }

            throw new NotSupportedMessageException(string.Format("Message type {0} is not supported.", typeof(T).Name));
        }
Example #2
0
        public void Should_return_false_when_EmailAddress_missing()
        {
            var builder = AccountUpdated.CreateBuilder();

            builder
            .SetUsername("1")
            .SetFirstName("1")
            .SetLastName("1")
            .SetExternalId("1");
            var accountCreated = builder.Build();

            var validator = new AccountUpdatedValidator(Mock.Of <IDatabaseCommands>());
            var actual    = validator.IsValidPayload(accountCreated);

            Assert.False(actual);
        }
Example #3
0
        public void Should_return_true_for_valid_model()
        {
            var builder = AccountUpdated.CreateBuilder();

            builder
            .SetUsername("1")
            .SetFirstName("1")
            .SetLastName("1")
            .SetEmailAddress("1")
            .SetExternalId("1");
            var accountCreated = builder.Build();

            var validator = new AccountUpdatedValidator(Mock.Of <IDatabaseCommands>());
            var actual    = validator.IsValidPayload(accountCreated);

            Assert.True(actual);
        }