public ActionResult Index(OpmlImporterIndexDto dto)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View("Index", null);
            }

            this.opmlImporterService.Import(dto);
            return this.RedirectToAction("My", "RssChannel");
        }
 public List<RssSourceWithUrlAndTitle> ParseToRssChannelList(OpmlImporterIndexDto dto)
 {
     var outlines = this.opmlHandler.GetOutlines(dto.ImportFile.InputStream);
     var ot = this.FilterOutInvalidOutlines(outlines);
     var urls = ot.Select(o =>
               new RssSourceWithUrlAndTitle(
                   o.Attributes.GetNamedItem("xmlUrl").Value,
                   o.Attributes.GetNamedItem("title").Value))
         .Distinct(new RssSourceWithUrlAndTitleComparer())
         .ToList();
     return urls;
 }
        public void Import(OpmlImporterIndexDto dto)
        {
            var toRssChannelList = this.ParseToRssChannelList(dto);
            this.AddNewChannelsToGlobalSpace(toRssChannelList);

            var idByChannelUrl = this.rssChannelsRepository
                .GetIdByChannelUrl(toRssChannelList.Select(c => c.Url)
                    .ToList());

            var currentUserId = this.authentication.GetCurrentUserId();

            var channelsSubscribedByUser = this.rssSubscriptionsRepository.GetChannelIdSubscriptionsForUser(currentUserId);
            channelsSubscribedByUser.ForEach(id => idByChannelUrl.Remove(id));

            idByChannelUrl.ForEach(
                c => this.rssSubscriptionsRepository
                         .CreateNewSubscriptionForUserAndChannel(currentUserId, c));
        }
Exemple #4
0
        public void T001_When_Nothing_New_Was_Added_By_User_No_New_Subscriptions_Must_Be_Defined()
        {
            // arrange
            OpmlImporterIndexDto stub = new OpmlImporterIndexDto();
            stub.ImportFile = new Mock<HttpPostedFileBase>().Object;

            var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><body><outline><outline text=\"Programming\" title=\"Programming\"/><outline  title=\"Johnny Zraiby\" xmlUrl=\"http://jczraiby.wordpress.com/feed/\" /></outline></body>";
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xml);

            var outlines = xmlDocument.GetElementsByTagName("outline");
            var nodes = outlines.Cast<XmlNode>();

            this.mockOpmlReader
                .Setup(s => s.GetOutlines(It.IsAny<Stream>()))
                .Returns(nodes);

            this.mockSubscriptionRepository
                .Setup(s => s.LoadUrlsForAllChannels())
                .Returns(new List<string>());

            this.mockRssChannelRepository
                .Setup(s => s.GetIdByChannelUrl(It.IsAny<List<string>>()))
                .Returns(new List<long>());

            this.mockSubscriptionRepository
                .Setup(s => s.GetChannelIdSubscriptionsForUser(It.IsAny<long>()))
                .Returns(new List<long>());

            // act
            this.sut.Import(stub);

            // assert
            this.mockSubscriptionRepository
                .Verify(v => v.CreateNewSubscriptionForUserAndChannel(It.IsAny<long>(), It.IsAny<long>()),
                Times.Never);
        }