Exemple #1
0
        public async void Post_SuccessStatus201_Test()
        {
            // 1: Add Existing establishment to validate name param on request body
            await establishmentService.CreateItem(new Establishment()
            {
                Name = "Test 1",
                Type = "Alimentação"
            });

            // 2: Request body
            ReleaseRequest requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 3: Call POST Action passing body request with a new release
            var query = await releasesController.Post(requestBody);

            var resultStatusCode = query.Result.GetType().GetProperty("StatusCode").GetValue(query.Result);
            var resultValue      = (Release)query.Result.GetType().GetProperty("Value").GetValue(query.Result);

            // 4: Remove all establishments and releases from database
            await establishmentService.RemoveAll();

            await releasesService.RemoveAll();

            Assert.Equal(201, (int)resultStatusCode);
            Assert.Equal("Test 1", resultValue.EstablishmentName);
            Assert.NotNull(resultValue.Id);
        }
Exemple #2
0
        private async void AddNewEstablishment(EstablishmentCreatedEvent establishment)
        {
            var newEstablishment = new Establishment()
            {
                Id        = establishment.Id,
                Name      = establishment.Name,
                Type      = establishment.Type,
                CreatedAt = establishment.CreatedAt,
                UpdatedAt = establishment.UpdatedAt
            };

            await establishmentService.CreateItem(newEstablishment);
        }
Exemple #3
0
        public async Task <ActionResult <Establishment> > Post([FromBody] EstablishmentRequest body)
        {
            Establishment resultEstablishment;

            try {
                logger.LogInformation("Trying to verify if establishment with given Name exists");
                var establishment = await establishmentService.GetByName(body.Name.FirstCharToUpper());

                if (establishment != null)
                {
                    string errorMessage = responseMessages.NotAccepted.Replace("$", "estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 406));
                }

                logger.LogInformation("Inserting establishment into database");
                var newEstablishment = new Establishment()
                {
                    Name      = body.Name.FirstCharToUpper(),
                    Type      = body.Type.FirstCharToUpper(),
                    CreatedAt = DateTime.Now
                };

                resultEstablishment = await establishmentService.CreateItem(newEstablishment);

                //Send to RabbitMQ to event handler observer pattern
                Emitter.EstablishmentCreated(resultEstablishment, rabbitConnector.ConnectionString);
            } catch (Exception ex) {
                logger.LogInformation($"Message: {ex.Message}");
                logger.LogTrace($"Stack Trace: {ex.StackTrace}");
                throw;
            }

            logger.LogInformation("Action POST for /api/establishments returns 201");
            return(Created("", resultEstablishment));
        }