Exemplo n.º 1
0
        public Task Handle(PlaceOrder message, IMessageHandlerContext context)
        {
            logger.Info($"Received PlaceOrder, OrderId = {message.OrderId}");

            LogTrace(message);

            // This is normally where some business logic would occur

            // 25% of messages always fail with a missing parameter error - persistent
            // all messages fail 10% of the time with a deadlock - transient
            // all messages fail 10% of the time with a FraudDetectionUnavailableException - transient
            var d = message.GetHashCode();

            if (d > (int.MaxValue / 4) * 3)
            {
                throw SqlExceptionCreator.NewSqlException(137); // Must declare the scalar variable - PERSISTENT
            }
            else if (new Random(Guid.NewGuid().GetHashCode()).NextDouble() > 0.90)
            {
                throw SqlExceptionCreator.NewSqlException(1205); // deadlock - TRANSIENT
            }
            else if (new Random(Guid.NewGuid().GetHashCode()).NextDouble() > 0.80)
            {
                throw new FraudDetectionUnavailableException("Fraud detection system is down for a short time"); // SEMI TRANSIENT
            }

            var orderPlaced = new OrderPlaced
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderPlaced));
        }
 public LevyTransactionBatchStorageServiceFixture With_RepositoryThrowingSqlException(int number)
 {
     mockLevyTransactionRepository
     .Setup(x => x.SaveLevyTransactions(It.IsAny <List <LevyTransactionModel> >(),
                                        It.IsAny <CancellationToken>()))
     .ThrowsAsync(SqlExceptionCreator.NewSqlException(number));
     return(this);
 }
Exemplo n.º 3
0
        public void MonitoringMiddleware_Returns_JsonDetail_And_404_On_Specific_SqlException()
        {
            int expectedHttpCode = 404;
            Mock <IFrameworkTracer> frameworkTracerMock = new Mock <IFrameworkTracer>();
            SqlException            expectedException   = SqlExceptionCreator.NewSqlException(60000);

            _requestDelegateMock.Setup(rd => rd(It.IsAny <HttpContext>())).Throws(expectedException);
            var httpResponseMock = GetHttpResponseMock();
            var httpContextMock  = GetHttpContextMock(responseMock: httpResponseMock);

            var systemUnderTest = new MonitoringMiddleware(_requestDelegateMock.Object, frameworkTracerMock.Object);

            systemUnderTest.InvokeAsync(httpContextMock.Object).GetAwaiter().GetResult();

            httpResponseMock.VerifySet(t => t.StatusCode = expectedHttpCode);
        }
        public Task Handle(CancelOrder message, IMessageHandlerContext context)
        {
            logger.Info($"Received CancelOrder, OrderId = {message.OrderId}");

            // This is normally where some business logic would occur

            // SqlException is: Must declare the scalar variable - this will happen everytime
            // but the policy related to thse messages is a Transient By Default
            // and OrderNotFoundException are treated as persistent
            // so these messages will be retried up to the limit
            SqlExceptionCreator.NewSqlException(137);

            var orderCancelled = new OrderCancelled
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderCancelled));
        }