public async Task ProcessAsyncJobProfileDeletedTestReturnsOk()
        {
            // arrange
            const HttpStatusCode expectedResult = HttpStatusCode.OK;
            const string         message        = "{}";
            const long           sequenceNumber = 1;

            A.CallTo(() => mappingService.MapToSegmentModel(message, sequenceNumber)).Returns(A.Fake <HowToBecomeSegmentModel>());
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).Returns(expectedResult);

            // act
            var result = await messageProcessor.ProcessAsync(message, sequenceNumber, MessageContentType.JobProfile, MessageAction.Deleted).ConfigureAwait(false);

            // assert
            A.CallTo(() => mappingService.MapToSegmentModel(message, sequenceNumber)).MustHaveHappenedOnceExactly();
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(expectedResult, result);
        }
Esempio n. 2
0
        public async Task ProcessAsyncCallsDeleteAsyncWhenDeletedMessageActionSent()
        {
            // Act
            var result = await processor
                         .ProcessAsync(BaseMessage, SequenceNumber, MessageContentType.JobProfile, MessageAction.Deleted)
                         .ConfigureAwait(false);

            // Assert
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(HttpStatusCode.OK, result);
        }
Esempio n. 3
0
        private async Task <HttpStatusCode> ProcessFullJobProfile(string message, long sequenceNumber, MessageAction messageAction)
        {
            var fullJobProfile = mappingService.MapToSegmentModel(message, sequenceNumber);

            if (messageAction == MessageAction.Deleted)
            {
                return(await httpClientService.DeleteAsync(fullJobProfile.DocumentId).ConfigureAwait(false));
            }

            return(await SendMessageData(fullJobProfile).ConfigureAwait(false));
        }
Esempio n. 4
0
        public MessageProcessorTests()
        {
            var expectedMappedModel = GetSegmentModel();

            mappingService = A.Fake <IMappingService>();
            A.CallTo(() => mappingService.MapToSegmentModel(A <string> .Ignored, A <long> .Ignored)).Returns(expectedMappedModel);

            httpClientService = A.Fake <IHttpClientService>();
            A.CallTo(() => httpClientService.DeleteAsync(A <Guid> .Ignored)).Returns(HttpStatusCode.OK);

            processor = new MessageProcessor(httpClientService, mappingService);
        }
        private async Task <HttpStatusCode> ProcessJobProfileMessageAsync(string message, string messageAction, string messageContentId, long sequenceNumber)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentException("Message cannot be null or empty.", nameof(message));
            }

            if (string.IsNullOrWhiteSpace(messageAction))
            {
                throw new ArgumentException("Message action cannot be null or empty.", nameof(messageAction));
            }

            if (string.IsNullOrWhiteSpace(messageContentId))
            {
                throw new ArgumentException("Message content id cannot be null or empty", nameof(messageContentId));
            }

            if (!Enum.TryParse <MessageAction>(messageAction, out var action))
            {
                throw new ArgumentOutOfRangeException(nameof(messageAction), $"Invalid message action '{messageAction}' received, should be one of '{string.Join(",", Enum.GetNames(typeof(MessageAction)))}'");
            }

            var jobProfileMessage = JsonConvert.DeserializeObject <JobProfileMessage>(message);
            var jobProfile        = mapper.Map <JobProfileModel>(jobProfileMessage);

            jobProfile.SequenceNumber = sequenceNumber;

            switch (action)
            {
            case MessageAction.Draft:
            case MessageAction.Published:
                var result = await httpClientService.PatchAsync(jobProfile).ConfigureAwait(false);

                if (result == HttpStatusCode.NotFound)
                {
                    return(await httpClientService.PostAsync(jobProfile).ConfigureAwait(false));
                }

                return(result);

            case MessageAction.Deleted:
                return(await httpClientService.DeleteAsync(jobProfile.JobProfileId).ConfigureAwait(false));

            default:
                throw new ArgumentOutOfRangeException(nameof(messageAction), $"Invalid message action '{messageAction}' received, should be one of '{string.Join(",", Enum.GetNames(typeof(MessageAction)))}'");
            }
        }
Esempio n. 6
0
        public async Task <APIMessage <bool> > DeletePersonAsync(int id = -1)
        {
            if (id != -1)
            {
                try
                {
                    var response = await httpClient.DeleteAsync <bool>(APIEndPoints.DeletePersonEndPoint + id);

                    return(response);
                }
                catch (Exception ex)
                {
                    ErrorLogger.Instance.LogException(ex);
                }
            }
            return(null);
        }
        private async Task <HttpStatusCode> ProcessJobProfileMessageAsync(string message, MessageAction actionType, long sequenceNumber)
        {
            var jobProfile = mappingService.MapToSegmentModel(message, sequenceNumber);

            switch (actionType)
            {
            case MessageAction.Draft:
            case MessageAction.Published:
                var result = await httpClientService.PutAsync(jobProfile).ConfigureAwait(false);

                if (result == HttpStatusCode.NotFound)
                {
                    return(await httpClientService.PostAsync(jobProfile).ConfigureAwait(false));
                }

                return(result);

            case MessageAction.Deleted:
                return(await httpClientService.DeleteAsync(jobProfile.DocumentId).ConfigureAwait(false));
            }

            return(HttpStatusCode.InternalServerError);
        }
        private async Task <HttpStatusCode> ProcessJobProfileMessageAsync(string message, MessageActionType messageAction, long sequenceNumber)
        {
            var jobProfile = mappingService.MapToSegmentModel(message, sequenceNumber);

            switch (messageAction)
            {
            case MessageActionType.Draft:
            case MessageActionType.Published:
                var result = await httpClientService.PutAsync(jobProfile).ConfigureAwait(false);

                if (result == HttpStatusCode.NotFound)
                {
                    return(await httpClientService.PostAsync(jobProfile).ConfigureAwait(false));
                }

                return(result);

            case MessageActionType.Deleted:
                return(await httpClientService.DeleteAsync(jobProfile.DocumentId).ConfigureAwait(false));

            default:
                throw new ArgumentOutOfRangeException(nameof(messageAction), $"Invalid message action '{messageAction}' received, should be one of '{string.Join(",", Enum.GetNames(typeof(MessageActionType)))}'");
            }
        }
Esempio n. 9
0
        public void Clear()
        {
            var response = _httpClientService.DeleteAsync <T>("api/energyobservations/clearing").Result;

            CheckResponse(response, $"Exception occurred during clearing API storage.");
        }
Esempio n. 10
0
        public void DeleteDeployment(string deploymentId)
        {
            var deleteDeploymentHttpRequest = new HttpClientRequest <NullOrVoid>("deployment/" + deploymentId + "?cascade=true", default(NullOrVoid));

            _httpClientService.DeleteAsync <NullOrVoid>(deleteDeploymentHttpRequest);
        }
Esempio n. 11
0
 public async Task DeleteNotificationAsync(int id, CancellationToken cancellationToken)
 {
     var url = $"{_baseUrl}/api/service-message/{id}";
     await _httpClientService.DeleteAsync(url, cancellationToken);
 }