Esempio n. 1
0
        public void ThrowArgumentNullException_WhenIsPassed_InvalidArgument()
        {
            // Arrange
            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            var comicsAdministrationController = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act & Assert
            Assert.That(() => comicsAdministrationController.SearchComicByName(null),
                        Throws.ArgumentNullException.With.Message.Contain("name"));
        }
Esempio n. 2
0
        public void Call_GetComics_FromTheService()
        {
            // Arrange
            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetComic("name"));

            var comicsAdministrationController = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            comicsAdministrationController.SearchComicByName("name");

            // Assert
            mockedService.Verify(service => service.GetComic("name"), Times.Once);
        }
        public void Call_RemoveComicMethod()
        {
            // Arrange
            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();
            var viewModel     = new ComicsViewModel();

            viewModel.Title = "title";

            mockedService.Setup(service => service.RemoveComic(viewModel.Title));

            var comicsAdministrationController = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            comicsAdministrationController.RemoveComicsFromDb(viewModel);


            // Assert
            mockedService.Verify(service => service.RemoveComic(viewModel.Title), Times.Once);
        }
Esempio n. 4
0
        public void Call_AddComicMethod_FromThesService()
        {
            // Arrange
            var comicsDataModel = new ComicsDataModel();
            var comicsViewModel = new ComicsViewModel();

            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedFactory.Setup(fac => fac.CreateComics()).Returns(comicsDataModel);
            mockedService.Setup(service => service.AddComic(comicsDataModel));

            var comicsAdministrationController = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            comicsAdministrationController.AddComicsToDb(comicsViewModel);

            // Assert
            mockedService.Verify(service => service.AddComic(comicsDataModel), Times.Once);
        }
        public void Call_MapMethod_FromTheMapper()
        {
            // Arrange
            var title           = "title";
            var comicsDataModel = new ComicsDataModel();
            var comicsViewModel = new ComicsAdminViewModel();

            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetComic(title)).Returns(comicsDataModel);
            mockedMapper.Setup(mapper => mapper.Map <ComicsAdminViewModel>(comicsDataModel)).Returns(comicsViewModel);

            var comicsAdministrationController = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            comicsAdministrationController.GetComicByTitle(title);

            // Assert
            mockedMapper.Verify(mapper => mapper.Map <ComicsAdminViewModel>(comicsDataModel), Times.Once);
        }
Esempio n. 6
0
        public void Call_MapMethod_OfTheService()
        {
            // Arrange
            var comics           = new List <ComicsDataModel>();
            var comicsViewModels = new List <ComicsAdminViewModel>();

            var mockedService = new Mock <IComicsService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetComics()).Returns(comics);
            mockedMapper.Setup(mapper => mapper.Map <IEnumerable <ComicsAdminViewModel> >(comics))
            .Returns(comicsViewModels);

            var comicsAdministrationContrller = new ComicsAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            comicsAdministrationContrller.GetAllComics();

            // Assert
            mockedMapper.Verify(mapper => mapper.Map <IEnumerable <ComicsAdminViewModel> >(comics), Times.Once);
        }