Exemplo n.º 1
0
        public void CallSaveChanges_WhenParamsAreValid()
        {
            // Arrange
            var contextMock         = new Mock <ITravelGuideContext>();
            var storyFactoryMock    = new Mock <IStoryFactory>();
            var likesFactoryMock    = new Mock <IStoryLikeFactory>();
            var commentsFactoryMock = new Mock <IStoryCommentFactory>();

            var service = new StoryService(contextMock.Object, storyFactoryMock.Object, likesFactoryMock.Object, commentsFactoryMock.Object);

            var title              = "title";
            var content            = "content";
            var relatedDestination = "related";
            var imageUrl           = "url";
            var userId             = "id";

            var user = new User();

            contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns(user);

            var story = new Story();

            storyFactoryMock.Setup(x => x.CreateStory(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <User>())).Returns(story);
            contextMock.Setup(x => x.Stories.Add(It.IsAny <Story>()));

            // Act
            service.CreateStory(title, content, relatedDestination, imageUrl, userId);

            // Assert
            contextMock.Verify(x => x.SaveChanges(), Times.Once);
        }
Exemplo n.º 2
0
        public void ThrowArgumentNullException_WhenPassedUserIdIsNull()
        {
            // Arrange
            var contextMock         = new Mock <ITravelGuideContext>();
            var storyFactoryMock    = new Mock <IStoryFactory>();
            var likesFactoryMock    = new Mock <IStoryLikeFactory>();
            var commentsFactoryMock = new Mock <IStoryCommentFactory>();

            var service = new StoryService(contextMock.Object, storyFactoryMock.Object, likesFactoryMock.Object, commentsFactoryMock.Object);

            var title              = "title";
            var content            = "content";
            var relatedDestination = "related";
            var imageUrl           = "url";

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => service.CreateStory(title, content, relatedDestination, imageUrl, null));
        }
Exemplo n.º 3
0
        public ActionResult SubmitStory(FormCollection formCollection, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            string          storyDirectory = Server.MapPath(ConfigurationManager.AppSettings.Get("StoryDirectory"));
            List <string>   descriptions   = new List <string>();
            List <FileInfo> imageInfo      = new List <FileInfo>();
            int             index          = 0;
            string          filename;

            foreach (var file in fileUpload)
            {
                descriptions.Add(formCollection["description-" + index.ToString()]);
                filename = Path.GetFileName(file.FileName);
                filename = Path.Combine(storyDirectory, filename);

                if (System.IO.File.Exists(filename))
                {
                    filename = StoryService.Service.GetNewPathForFile(filename);
                }

                imageInfo.Add(new FileInfo(filename));
                file.SaveAs(filename);
                index++;
            }

            string       storyTitle = formCollection["story-title"];
            StoryService service    = new StoryService();

            filename = storyTitle.Substring(0, Math.Min(storyTitle.Length, 5)) + ".jpg";

            FileInfo Story = service.CreateStory(descriptions, imageInfo, filename, storyDirectory);

            UserContent newContent = new UserContent
            {
                StoryTitle = storyTitle,
                StoryName  = Path.GetFileName(Story.FullName),
            };

            string userId = formCollection["user-id"];

            ContentService.Service.AddNewContent(newContent, userId, userId, null);

            return(RedirectToAction("UserStories", "Profile", new { id = userId }));
        }