public void CallAddMethodOfPersonService_WhenModelStateIsValid()
        {
            // Arrange
            var genreServiceMock  = new Mock <IGenreService>();
            var movieServiceMock  = new Mock <IMovieService>();
            var personServiceMock = new Mock <IPersonService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            var personViewModel = new PersonViewModel()
            {
                FirstName   = "Ivan",
                LastName    = "Stanev",
                Nationality = "Bulgarian",
                DateOfBirth = DateTime.UtcNow,
                Gender      = Gender.Male
            };

            var personDbModel = new Person()
            {
                FirstName   = personViewModel.FirstName,
                LastName    = personViewModel.LastName,
                Nationality = personViewModel.Nationality,
                DateOfBirth = personViewModel.DateOfBirth,
                Gender      = personViewModel.Gender
            };

            var validationContext =
                new System.ComponentModel.DataAnnotations.ValidationContext(personViewModel, null, null);

            var results = new List <ValidationResult>();

            var isModelValid = Validator.TryValidateObject(personViewModel, validationContext, results);

            mapperMock.Setup(x => x.Map <Person>(personViewModel)).Returns(personDbModel);

            var panelController = new PanelController(
                genreServiceMock.Object,
                movieServiceMock.Object,
                personServiceMock.Object,
                fileConverterMock.Object,
                mapperMock.Object);

            var contextMock = new Mock <HttpContextBase>();
            var requestMock = new Mock <HttpRequestBase>();
            var filesMock   = new Mock <HttpFileCollectionBase>();

            contextMock.Setup(c => c.Request).Returns(requestMock.Object);
            filesMock.Setup(f => f.Count).Returns(0);
            requestMock.Setup(r => r.Files).Returns(filesMock.Object);
            panelController.ControllerContext =
                new ControllerContext(contextMock.Object, new RouteData(), panelController);

            // Act
            panelController.AddPerson(personViewModel);

            // Assert
            Assert.IsTrue(isModelValid);
            personServiceMock.Verify(ps => ps.AddPerson(personDbModel), Times.Once);
        }
        public void NotCallAddMethodOfPersonService_WhenModelStateIsInvalid()
        {
            // Arrange
            var genreServiceMock  = new Mock <IGenreService>();
            var movieServiceMock  = new Mock <IMovieService>();
            var personServiceMock = new Mock <IPersonService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            var personViewModel = new PersonViewModel()
            {
            };

            var personDbModel = new Person()
            {
            };

            var validationContext =
                new System.ComponentModel.DataAnnotations.ValidationContext(personViewModel, null, null);

            var results = new List <ValidationResult>();

            var isModelValid = Validator.TryValidateObject(personViewModel, validationContext, results);

            var panelController = new PanelController(
                genreServiceMock.Object,
                movieServiceMock.Object,
                personServiceMock.Object,
                fileConverterMock.Object,
                mapperMock.Object);

            panelController.ModelState.AddModelError("name", "No person name!");

            // Act
            panelController.AddPerson(personViewModel);

            // Assert
            Assert.IsFalse(isModelValid);
            personServiceMock.Verify(ps => ps.AddPerson(personDbModel), Times.Never);
        }