Ejemplo n.º 1
0
    public async Task PublishToQueueLogsShouldHaveContext()
    {
        var services = GivenJustSaying(levelOverride: LogLevel.Information)
                       .ConfigureJustSaying(
            (builder) => builder.WithLoopbackQueue <SimpleMessage>(UniqueName));

        var sp = services.BuildServiceProvider();

        var cts = new CancellationTokenSource();

        var publisher = sp.GetRequiredService <IMessagePublisher>();
        await publisher.StartAsync(cts.Token);

        var message = new SimpleMessage();
        await publisher.PublishAsync(message, cts.Token);

        var testLogger = sp.GetRequiredService <ITestLoggerSink>();

        var handleMessage = testLogger.LogEntries
                            .Single(le => le.OriginalFormat == "Published message {MessageId} of type {MessageType} to {DestinationType} '{MessageDestination}'.");

        var propertyMap = new Dictionary <string, object>(handleMessage.Properties);

        propertyMap.ShouldContainKeyAndValue("MessageId", message.Id);
        propertyMap.ShouldContainKeyAndValue("MessageType", message.GetType().FullName);
        propertyMap.ShouldContainKeyAndValue("DestinationType", "Queue");
        propertyMap.ShouldContainKey("MessageDestination");

        cts.Cancel();
    }
Ejemplo n.º 2
0
        public async Task HandleMessageFromQueueLogs_ShouldHaveContext(bool handlerShouldSucceed, LogLevel level, string status, string exceptionMessage)
        {
            var handler = new InspectableHandler <SimpleMessage>()
            {
                ShouldSucceed = handlerShouldSucceed,
            };

            if (exceptionMessage != null)
            {
                handler.OnHandle = msg => throw new Exception(exceptionMessage);
            }

            var services = GivenJustSaying(levelOverride: LogLevel.Information)
                           .ConfigureJustSaying(
                (builder) => builder.WithLoopbackQueue <SimpleMessage>(UniqueName)
                .Subscriptions(sub => sub.WithDefaults(sgb =>
                                                       sgb.WithDefaultConcurrencyLimit(10))))
                           .AddSingleton <IHandlerAsync <SimpleMessage> >(handler);

            var sp = services.BuildServiceProvider();

            var cts = new CancellationTokenSource();

            var publisher = sp.GetRequiredService <IMessagePublisher>();
            await publisher.StartAsync(cts.Token);

            await sp.GetRequiredService <IMessagingBus>().StartAsync(cts.Token);

            var message = new SimpleMessage();
            await publisher.PublishAsync(message, cts.Token);

            await Patiently.AssertThatAsync(() => handler.ReceivedMessages
                                            .ShouldHaveSingleItem()
                                            .Id.ShouldBe(message.Id));

            var testLogger = sp.GetRequiredService <ITestLoggerSink>();

            await Patiently.AssertThatAsync(() =>
            {
                var handleMessage = testLogger.LogEntries
                                    .SingleOrDefault(le => le.OriginalFormat == "{Status} handling message with Id '{MessageId}' of type {MessageType} in {TimeToHandle}ms.");

                handleMessage.ShouldNotBeNull();

                handleMessage.LogLevel.ShouldBe(level);
                handleMessage.Exception?.Message.ShouldBe(exceptionMessage);

                var propertyMap = new Dictionary <string, object>(handleMessage.Properties);
                propertyMap.ShouldContainKeyAndValue("Status", status);
                propertyMap.ShouldContainKeyAndValue("MessageId", message.Id);
                propertyMap.ShouldContainKeyAndValue("MessageType", message.GetType().FullName);
                propertyMap.ShouldContainKey("TimeToHandle");
            });

            cts.Cancel();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Example of a deprecated endpoint, returns input.
        /// </summary>
        /// <exception cref="SymphonyOSS.RestApiClient.Generated.OpenApi.AgentApi.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="sessionToken">Session authentication token.</param>
        /// <param name="keyManagerToken">Key Manager authentication token.</param>
        /// <param name="echoInput">Message in plain text\n</param>
        /// <returns>Task of ApiResponse (SimpleMessage)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <SimpleMessage> > V1UtilObsoletePostAsyncWithHttpInfo(string sessionToken, string keyManagerToken, SimpleMessage echoInput)
        {
            // verify the required parameter 'sessionToken' is set
            if (sessionToken == null)
            {
                throw new ApiException(400, "Missing required parameter 'sessionToken' when calling UtilApi->V1UtilObsoletePost");
            }
            // verify the required parameter 'keyManagerToken' is set
            if (keyManagerToken == null)
            {
                throw new ApiException(400, "Missing required parameter 'keyManagerToken' when calling UtilApi->V1UtilObsoletePost");
            }
            // verify the required parameter 'echoInput' is set
            if (echoInput == null)
            {
                throw new ApiException(400, "Missing required parameter 'echoInput' when calling UtilApi->V1UtilObsoletePost");
            }

            var    localVarPath         = "/v1/util/obsolete";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (sessionToken != null)
            {
                localVarHeaderParams.Add("sessionToken", Configuration.ApiClient.ParameterToString(sessionToken));                       // header parameter
            }
            if (keyManagerToken != null)
            {
                localVarHeaderParams.Add("keyManagerToken", Configuration.ApiClient.ParameterToString(keyManagerToken));                          // header parameter
            }
            if (echoInput.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(echoInput); // http body (model) parameter
            }
            else
            {
                localVarPostBody = echoInput; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400)
            {
                throw new ApiException(localVarStatusCode, "Error calling V1UtilObsoletePost: " + localVarResponse.Content, localVarResponse.Content);
            }
            else if (localVarStatusCode == 0)
            {
                throw new ApiException(localVarStatusCode, "Error calling V1UtilObsoletePost: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
            }

            return(new ApiResponse <SimpleMessage>(localVarStatusCode,
                                                   localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                   (SimpleMessage)Configuration.ApiClient.Deserialize(localVarResponse, typeof(SimpleMessage))));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Example of a deprecated endpoint, returns input.
        /// </summary>
        /// <exception cref="SymphonyOSS.RestApiClient.Generated.OpenApi.AgentApi.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="sessionToken">Session authentication token.</param>
        /// <param name="keyManagerToken">Key Manager authentication token.</param>
        /// <param name="echoInput">Message in plain text </param>
        /// <returns>ApiResponse of SimpleMessage</returns>
        public ApiResponse <SimpleMessage> V1UtilObsoletePostWithHttpInfo(string sessionToken, string keyManagerToken, SimpleMessage echoInput)
        {
            // verify the required parameter 'sessionToken' is set
            if (sessionToken == null)
            {
                throw new ApiException(400, "Missing required parameter 'sessionToken' when calling UtilApi->V1UtilObsoletePost");
            }
            // verify the required parameter 'keyManagerToken' is set
            if (keyManagerToken == null)
            {
                throw new ApiException(400, "Missing required parameter 'keyManagerToken' when calling UtilApi->V1UtilObsoletePost");
            }
            // verify the required parameter 'echoInput' is set
            if (echoInput == null)
            {
                throw new ApiException(400, "Missing required parameter 'echoInput' when calling UtilApi->V1UtilObsoletePost");
            }

            var    localVarPath         = "./v1/util/obsolete";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (sessionToken != null)
            {
                localVarHeaderParams.Add("sessionToken", Configuration.ApiClient.ParameterToString(sessionToken));                       // header parameter
            }
            if (keyManagerToken != null)
            {
                localVarHeaderParams.Add("keyManagerToken", Configuration.ApiClient.ParameterToString(keyManagerToken));                          // header parameter
            }
            if (echoInput != null && echoInput.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(echoInput); // http body (model) parameter
            }
            else
            {
                localVarPostBody = echoInput; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("V1UtilObsoletePost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <SimpleMessage>(localVarStatusCode,
                                                   localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                                   (SimpleMessage)Configuration.ApiClient.Deserialize(localVarResponse, typeof(SimpleMessage))));
        }