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

            var labels = new List <Models.Label>()
            {
                new Models.Label {
                    Name = "LabelA"
                }, 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 {
                Name = "LabelA"
            };
            var response = controller.PostAsync(label);

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

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label '{label.Name}' already exists, cannot create.");
        }
        public void PostAsync_Failed_LabelIsNull()
        {
            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 response = controller.PostAsync(null);

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

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label object from body is null.");
        }
        public void PostAsync_Failed_LabelIsNullOrWhiteSpace(string labelName)
        {
            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 {
                Name = labelName
            };
            var response = controller.PostAsync(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 PostAsync_Succeed()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            //var mockMapper = new Mock<IMapper>();
            var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(new Mappings.MappingProfile())));

            var labelModel = new Models.Label {
                Name = "NewLabel"
            };
            var labels = new List <Models.Label>()
            {
                new Models.Label {
                    Name = "LabelA"
                }, new Models.Label {
                    Name = "LabelB"
                }
            };

            mockLabelRepo.Setup(x => x.GetLabelsAsync()).Returns(Task.FromResult(labels.AsEnumerable()));
            mockLabelRepo.Setup(x => x.AddLabelAsync(It.IsAny <Models.Label>())).Returns(Task.FromResult(labelModel));
            //mockMapper.Setup(x => x.Map<Models.Label, DTOs.Label>(It.IsAny<Models.Label>())).Returns(labelDTO);

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

            // Act
            var labelDTO = new DTOs.Label {
                Name = "NewLabel"
            };
            var response = controller.PostAsync(labelDTO);

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

            result.StatusCode.ShouldBe(201);
            var returnedLabel = result.Value as DTOs.Label;

            returnedLabel.Name.ShouldBe(labelDTO.Name);
        }