Beispiel #1
0
        public void Should_Create_Item()
        {
            // Arrange
            var newLabel = new Label()
            {
                Id     = 10,
                Color  = "#ffffff",
                Title  = "testItem",
                UserId = "testID"
            };

            var repository = new Mock <IRepository <Label> >();

            repository.Setup(u => u.Update(newLabel));

            // Act
            var service = new LabelService(_mapper, repository.Object);

            service.Create(_mapper.Map <Label, LabelDTO>(newLabel));

            // Assert
            repository.Verify(t => t.Create(It.Is <Label>(dto =>
                                                          dto.Id == newLabel.Id &&
                                                          dto.Color == newLabel.Color &&
                                                          dto.Title == newLabel.Title &&
                                                          dto.UserId == newLabel.UserId
                                                          )));
            repository.Verify(t => t.SaveChanges());
            repository.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public IActionResult Create([FromForm] LabelDTO label)
        {
            if (ModelState.IsValid)
            {
                _labelService.Create(label);
            }

            return(RedirectToAction(nameof(List)));
        }
Beispiel #3
0
        public void Should_ArgumentNullException_When_Create_Item()
        {
            // Arrange
            var repository = new Mock <IRepository <Label> >();

            repository.Setup(u => u.Create(null));

            // Act
            var service = new LabelService(_mapper, repository.Object);

            //Assert
            Assert.Throws <ArgumentNullException>(() => service.Create(null));
            repository.VerifyNoOtherCalls();
        }