示例#1
0
        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 AddDomainNotificationSuccess_Ok()
        {
            var faker = new Faker();

            var message = faker.Lorem.Sentence();

            var handler = new DomainNotificationHandler();

            var domainNotification = DomainNotification.Success(message);

            await handler.Handle(domainNotification, new CancellationToken());

            var notifications = handler.GetNotificationsSuccess();

            Assert.True(handler.HasNotificationsSucess());

            Assert.True(notifications.Count == 1);
        }
        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);
        }