public void MessageOlderThanRetentionDateWillBeDeleted(string specificSettings) { // Arrange: Insert a "retired" OutMessage with a referenced Reception Awareness. OverrideWithSpecificSettings(specificSettings); IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); string outReferenceId = GenId(), outStandaloneId = GenId(), inMessageId = GenId(), outExceptionId = GenId(), inExceptionId = GenId(); var spy = new DatabaseSpy(config); OutMessage om = CreateOutMessage(outReferenceId, insertionTime: DayBeforeYesterday, type: MessageType.Error); spy.InsertOutMessage(om); spy.InsertRetryReliability(RetryReliability.CreateForOutMessage(om.Id, maxRetryCount: 0, retryInterval: default(TimeSpan), type: RetryType.Send)); spy.InsertOutMessage(CreateOutMessage(outStandaloneId, insertionTime: DayBeforeYesterday, type: MessageType.Receipt)); spy.InsertInMessage(CreateInMessage(inMessageId, DayBeforeYesterday)); spy.InsertOutException(CreateOutException(outExceptionId, DayBeforeYesterday)); spy.InsertInException(CreateInException(inExceptionId, DayBeforeYesterday)); // Act: AS4.NET Component will start the Clean Up Agent. ExerciseStartCleaning(); // Assert: No OutMessage or Reception Awareness entries must be found for a given EbmsMessageId. Assert.Empty(spy.GetOutMessages(outReferenceId, outStandaloneId)); Assert.Null(spy.GetRetryReliabilityFor(r => r.RefToOutMessageId == om.Id)); Assert.Empty(spy.GetInMessages(inMessageId)); Assert.Empty(spy.GetOutExceptions(outExceptionId)); Assert.Empty(spy.GetInExceptions(inExceptionId)); }
public async Task ThenResponseWithError_IfNRReceiptHasInvalidHashes() { // Arrange string ebmsMessageId = Guid.NewGuid().ToString(); int CorruptHash(int hash) => hash + 10; // Act HttpResponseMessage response = await TestSendNRReceiptWith(ebmsMessageId, CorruptHash); // Assert Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); InMessage insertedReceipt = _databaseSpy.GetInMessageFor(m => m.EbmsRefToMessageId == ebmsMessageId); Assert.Equal(InStatus.Exception, insertedReceipt.Status.ToEnum <InStatus>()); Assert.NotEmpty(_databaseSpy.GetInExceptions(m => m.EbmsRefToMessageId == insertedReceipt.EbmsMessageId)); }
public async Task ThenDatabaseContainsInException() { var invalidSubmitMessage = GetInvalidSubmitMessage(); using (var response = await StubSender.SendRequest(HttpSubmitAgentUrl, Encoding.UTF8.GetBytes(invalidSubmitMessage), "application/xml")) { Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } var spy = new DatabaseSpy(_as4Msh.GetConfiguration()); var loggedException = spy.GetInExceptions(x => String.IsNullOrWhiteSpace(x.EbmsRefToMessageId)).FirstOrDefault(); Assert.NotNull(loggedException); Assert.NotNull(loggedException.MessageLocation); }
public async Task ThenUpdateReceiptWithException_IfNRReceiptHasInvalidHashes() { // Arrange string ebmsMessageId = Guid.NewGuid().ToString(); int CorruptHash(int hash) => hash + 10; // Act TestReceiveNRReceiptWith(ebmsMessageId, CorruptHash); // Assert IEnumerable <InException> inExceptions = await PollUntilPresent( () => _databaseSpy.GetInExceptions(m => m.EbmsRefToMessageId == ebmsMessageId), timeout : TimeSpan.FromSeconds(5)); Assert.NotEmpty(inExceptions); }
public void NoExceptionsAreLoggedWhenPullSenderIsNotAvailable() { // Arrange string pullSenderUrl = RetrievePullingUrlFromConfig(); _databaseSpy.ClearDatabase(); // Act var waiter = new ManualResetEvent(false); StubHttpServer.StartServer(pullSenderUrl, _ => throw new InvalidOperationException(), waiter); waiter.WaitOne(timeout: TimeSpan.FromSeconds(5)); // Assert _as4Msh.Dispose(); Assert.Empty(_databaseSpy.GetInExceptions(r => true)); }
public async Task InException_Is_Set_To_Notified_When_Retry_Happen_Within_Allowed_MaxRetry( HttpStatusCode secondAttempt, Operation expected) { await TestComponentWithSettings( "inexception_notify_reliability_settings.xml", async (settings, as4Msh) => { // Arrange var handler = new InboundExceptionHandler( () => new DatastoreContext(as4Msh.GetConfiguration()), as4Msh.GetConfiguration(), Registry.Instance.MessageBodyStore); const string url = "http://localhost:7071/business/inexception/"; string ebmsMessageId = $"entity-{Guid.NewGuid()}"; // Act await handler.HandleExecutionException( new Exception("This is an test exception"), new MessagingContext( new ReceivedEntityMessage(new InMessage(ebmsMessageId)), MessagingContextMode.Deliver) { ReceivingPMode = NotifyExceptionReceivePMode(url) }); // Assert SimulateNotifyFailureOnFirstAttempt(url, secondAttempt); var spy = new DatabaseSpy(as4Msh.GetConfiguration()); InException notified = await PollUntilPresent( () => spy.GetInExceptions( ex => ex.Operation == expected).FirstOrDefault(), timeout: TimeSpan.FromSeconds(10)); Entities.RetryReliability referenced = await PollUntilPresent( () => spy.GetRetryReliabilityFor(r => r.RefToInExceptionId == notified.Id), timeout: TimeSpan.FromSeconds(5)); Assert.Equal(RetryStatus.Completed, referenced.Status); }); }