コード例 #1
0
        public async void Delete_InvalidId400_Test(string id)
        {
            // 1: Call DELETE Action passing id of establishment to be deleted
            var query = await establishmentsController.Delete(id);

            ResponseDetails result = (ResponseDetails)query.Result.GetType().GetProperty("Value").GetValue(query.Result);

            Assert.Equal(400, result.StatusCode);
            Assert.Equal(controllerMessages.IncorretIdFormat, result.Message);
        }
コード例 #2
0
        public async void Delete_Returns406_NotAcknowledged_Test()
        {
            // 0: Remove all establishments from database
            await establishmentService.RemoveAll();

            // 1: Request body
            string id = "5dcaad2526235a471cfcccad";

            // 2: Mocking GetById Method to return fake data
            var fakeEstablishment = new Establishment {
                Id   = id,
                Name = "Test 1",
                Type = "Tipo 1"
            };

            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

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

            var deleteResultWrapper = new DeleteResultWrapper();

            establishmentServiceMock.Setup(es => es.RemoveById(It.IsAny <string>())).ReturnsAsync(deleteResultWrapper);

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

            var query = await establishmentsControllerLocal.Delete(id);

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

            Assert.Equal(406, result.StatusCode);
            Assert.Equal(controllerMessages.CantRemove, result.Message);
        }
コード例 #3
0
        public async void Delete_ThrowsException_Test()
        {
            // 1: Request id
            string id = "5dcaad2526235a471cfcccad";

            // 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.Delete(id));
        }