Ejemplo n.º 1
0
        public async void Post_NotAccepted406_Test()
        {
            // 1: Creating testing objects
            Establishment testEstablishment = new Establishment()
            {
                Name = "Test 1",
                Type = "Alimentação"
            };

            // 2: Adding to database synchronously
            await establishmentService.CreateItem(testEstablishment);

            // 3: Call POST Action passing body request with an establishment which already exists
            var query = await establishmentsController.Post(new EstablishmentRequest {
                Name = "Test 1",
                Type = "Alimentação"
            });

            var  result     = query.Result.GetType().GetProperty("Value").GetValue(query.Result);
            Type resultType = result.GetType();

            Assert.Equal(406, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.NotAccepted.Replace("$", "estabelecimento"), (string)resultType.GetProperty("Message").GetValue(result));
        }
Ejemplo n.º 2
0
        public async void Post_ThrowsException_Test()
        {
            // 0: Remove all establishments from database
            await establishmentService.RemoveAll();

            // 1: Request body
            var requestBody = new EstablishmentRequest {
                Name = "Test 1",
                Type = "Alimentação"
            };

            // 2: Mocking GetByName Method to throws
            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

            establishmentServiceMock.Setup(es => es.GetByName(It.IsAny <string>())).ThrowsAsync(new InvalidOperationException());

            var establishmentsControllerLocal = new EstablishmentsController(loggerWrapper, establishmentServiceMock.Object, controllerMessages);

            // 3: Call POST Action and Expects to throws
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await establishmentsControllerLocal.Post(requestBody));
        }