示例#1
0
        public void CallEditArticleMethod_WhenPassedModelIsValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var model = new CreateEditArticleViewModel();

            var article = new Article();

            articleServiceMock.Setup(x => x.EditArticle(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));

            // Act
            controller.EditArticle(model);

            // Assert
            articleServiceMock.Verify(x => x.EditArticle(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
示例#2
0
        public void CallMappingServiceMethod_WhenPassedIdIsNull()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var id      = Guid.NewGuid();
            var article = new Article();
            var model   = new CreateEditArticleViewModel();

            articleServiceMock.Setup(x => x.GetArticleById(id)).Returns(article);
            mappingServiceMock.Setup(x => x.Map <CreateEditArticleViewModel>(article)).Returns(model);

            // Act
            controller.EditArticle(id);

            // Assert
            mappingServiceMock.Verify(x => x.Map <CreateEditArticleViewModel>(article), Times.Once);
        }