Пример #1
0
        public async void Put_InvalidId400_Test(string id)
        {
            // 1: Request body
            var requestBody = new EstablishmentRequest {
                Name = "Test 1",
                Type = "alimentação"
            };

            // 2: Call PUT Action passing body request with an updated establishment
            var query = await establishmentsController.Put(id, requestBody);

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

            Assert.Equal(400, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.IncorretIdFormat, (string)resultType.GetProperty("Message").GetValue(result));
        }
Пример #2
0
        public async void Put_ThrowsException_Test()
        {
            // 0: Remove all establishments from database
            await establishmentService.RemoveAll();

            // 1: Request body
            string id          = "5dcaad2526235a471cfcccad";
            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.GetById(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.Put(id, requestBody));
        }
Пример #3
0
        public async void Put_Returns406_NotAcknowledged_Test()
        {
            // 0: Remove all establishments from database
            await establishmentService.RemoveAll();

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

            // 2: Mocking GetById Method to return fake data
            var fakeEstablishment = new Establishment {
                Id   = id,
                Name = requestBody.Name,
                Type = requestBody.Type
            };
            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

            establishmentServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ReturnsAsync(fakeEstablishment);

            var replaceOneResultWrapper = new ReplaceOneResultWrapper();

            establishmentServiceMock.Setup(es => es.UpdateById(It.IsAny <string>(), It.IsAny <Establishment>())).ReturnsAsync(replaceOneResultWrapper);

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

            var query = await establishmentsControllerLocal.Put(id, requestBody);

            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.CantUpdate, (string)resultType.GetProperty("Message").GetValue(result));
        }