protected ActionResult <T> ResponsePost <T>(string action, T result) { var route = GetActualRoute(); if (!IsValidOperation()) { return(BadRequest(new ValidationProblemDetails(_notifications.GetNotificationsErrorByKey()))); } if (result == null) { return(NoContent()); } var requestResponse = new RequestResponse <T>(result); //add all notifications of Error if (_notifications.HasNotificationsError()) { var errors = _notifications.GetNotificationsError(); foreach (var error in errors) { requestResponse.AddMessageFailure(error.Value); } } //add all notifications of Success if (!_notifications.HasNotificationsSucess()) { return(CreatedAtAction(action, route, requestResponse)); } var msgs = _notifications.GetNotificationsSuccess(); foreach (var msg in msgs) { requestResponse.AddMessageSucess(msg.Value); } return(CreatedAtAction(action, route, requestResponse)); }
public async void AddDomainNotificationError_Ok() { var faker = new Faker(); var message = faker.Lorem.Sentence(); var handler = new DomainNotificationHandler(); var domainNotification = DomainNotification.Fail(message); await handler.Handle(domainNotification, new CancellationToken()); var notifications = handler.GetNotificationsError(); Assert.True(handler.HasNotificationsError()); Assert.True(notifications.Count == 1); }
public async void GetNotificationsError_Ok() { var faker = new Faker(); var message = faker.Lorem.Sentence(); var handler = new DomainNotificationHandler(); var domainNotification = DomainNotification.Fail(message); await handler.Handle(domainNotification, new CancellationToken()); var notifications = handler.GetNotificationsError(); var result = notifications.Select(x => x.Value); Assert.Contains(message, result); }
public async void DomainNotificationClear_Ok() { var faker = new Faker(); var handler = new DomainNotificationHandler(); var qtError = faker.Random.Int(min: 3, max: 10); var qtSuccess = faker.Random.Int(min: 3, max: 10); for (var i = 0; i < qtError; i++) { var message = faker.Lorem.Sentence(); var domainNotification = DomainNotification.Fail(message); await handler.Handle(domainNotification, new CancellationToken()); } for (var i = 0; i < qtSuccess; i++) { var message = faker.Lorem.Sentence(); var domainNotification = DomainNotification.Success(message); await handler.Handle(domainNotification, new CancellationToken()); } handler.Clear(); var notificationsError = handler.GetNotificationsError(); var notificationsSuccess = handler.GetNotificationsSuccess(); Assert.False(handler.HasNotificationsError()); Assert.False(handler.HasNotificationsSucess()); Assert.True(notificationsError.Count == 0); Assert.True(notificationsSuccess.Count == 0); }