Example #1
0
        public async void Delete_InvalidId400_Test(string id)
        {
            // 1: Call PUT Action passing body request with an updated release
            var query = await releasesController.Delete(id);

            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));
        }
Example #2
0
        public async void Delete_Returns406_NotAcknowledged_Test()
        {
            // 1: Request body
            string id = "5dcaad2526235a471cfcccad";

            // 2: Mocking GetById Method to return fake data
            var fakeRelease = new Release {
                Id                = id,
                Date              = "06/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m,
                CreatedAt         = DateTime.Now,
                UpdatedAt         = DateTime.Now
            };

            var releasesServiceMock = new Mock <ReleasesService>(dbSettings);

            releasesServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ReturnsAsync(fakeRelease);

            var deleteResultWrapper = new DeleteResultWrapper();

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

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesServiceMock.Object, establishmentService, controllerMessages);

            var query = await releasesControllerLocal.Delete(id);

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

            Assert.Equal(406, result.StatusCode);
            Assert.Equal(controllerMessages.CantRemove, result.Message);
        }
        public async Task DeleteGet_ShouldCallRepositoryToGetEntityAndReturnViewWithData()
        {
            // Arrange

            // Act
            var result = await _controller.Delete(_existingRelease.ReleaseId);

            var viewResult = (ViewResult)result;
            var model      = (Release)viewResult.Model;

            // Assert
            _mockReleaseRepository.Verify(mr => mr.GetById(_existingRelease.ReleaseId), Times.Once);
            Assert.Null(viewResult.ViewName);
            Assert.NotNull(viewResult.ViewData);
            Assert.Equal(_existingRelease, model);
        }
Example #4
0
        public async void Delete_ThrowsException_Test()
        {
            // 1: Request id
            string id = "5dcaad2526235a471cfcccad";

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

            releasesServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ThrowsAsync(new InvalidOperationException());

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesServiceMock.Object, establishmentService, controllerMessages);

            // 3: Call POST Action and Expects to throws
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await releasesControllerLocal.Delete(id));
        }