Ejemplo n.º 1
0
        public void DeleteRecord_Returns_OkResult()
        {
            // Arrange
            var recordServiceMock = new Mock <IRecordService>();

            recordServiceMock.Setup(service => service
                                    .GetRecordByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(GetRecord()));

            recordServiceMock.Setup(service => service
                                    .DeleteRecordByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(true));

            var loggerMock = new Mock <ILogger <RecordsController> >();

            var controller = new RecordsController(recordServiceMock.Object, loggerMock.Object);
            var id         = 1;

            // Act
            var result = controller.DeleteRecord(id).GetAwaiter().GetResult();

            // Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(result);

            Assert.IsAssignableFrom <int>(okObjectResult.Value);
        }
Ejemplo n.º 2
0
        public void DeleteRecord_WithInvalidModelId_Returns_NotFoundResult()
        {
            // Arrange
            var recordServiceMock = new Mock <IRecordService>();

            recordServiceMock.Setup(service => service
                                    .DeleteRecordByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(false));

            var loggerMock = new Mock <ILogger <RecordsController> >();

            var controller = new RecordsController(recordServiceMock.Object, loggerMock.Object);
            var recordDTO  = new RecordDTO();
            var id         = 1;

            // Act
            var result = controller.DeleteRecord(id).GetAwaiter().GetResult();

            // Assert
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.IsAssignableFrom <int>(notFoundObjectResult.Value);
        }