public void PutAsync_Failed_LabelExisted()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            var labelModel = new Models.Label {
                Id = 1, Name = "LabelA"
            };

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult(labelModel));
            var labels = new List <Models.Label>()
            {
                labelModel, new Models.Label {
                    Name = "LabelB"
                }
            };

            mockLabelRepo.Setup(x => x.GetLabelsAsync()).Returns(Task.FromResult(labels.AsEnumerable()));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 3, Name = "LabelA"
            };
            var response = controller.PutAsync(3, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label '{label.Name}' already exists, cannot update.");
        }
        public void PutAsync_Failed_LabelIsNullOrWhiteSpace(string labelName)
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            var labelModel = new Models.Label {
                Id = 1, Name = "LabelA"
            };

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult(labelModel));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 1, Name = labelName
            };
            var response = controller.PutAsync(1, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label could be neither null nor whitespace.");
        }
        public void PutAsync_Failed_LabelIdNotIdentical()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 1, Name = "LabelA"
            };
            var response = controller.PutAsync(2, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label id from url and body are not identical.");
        }
        public void PutAsync_Failed_LabelNotFound()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult <Models.Label>(null));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 1, Name = "NewLabelA"
            };
            var response = controller.PutAsync(1, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(404);
            result.Value.ShouldBe($"Label with id '{label.Id}' not found.");
        }