Exemplo n.º 1
0
        public void Import(OpmlImporterIndexDto dto)
        {
            var toRssChannelList = this.ParseToRssChannelList(dto);

            this.AddNewChannelsToGlobalSpace(toRssChannelList);
            var existingChannels = toRssChannelList.Where(c => c.Id == 0).ToList();

            var existingChannelsIds =
                this.rssChannelsRepository
                .GetIdByChannelUrl(existingChannels.Select(c => c.Url)
                                   .ToList());

            var newChannelsIds = toRssChannelList.Where(c => c.Id != 0).Select(c => c.Id).ToList();

            existingChannelsIds.AddRange(newChannelsIds);

            var currentUserId = this.sessionProvider.GetCurrentUserId();

            var alreadySubscribedToChannelsId = this.rssSubscriptionsRepository.GetChannelIdSubscriptionsForUser(currentUserId);

            alreadySubscribedToChannelsId.ForEach(c => existingChannelsIds.Remove(c));

            existingChannelsIds.ForEach(
                c => this.rssSubscriptionsRepository.CreateNewSubscriptionForUserAndChannel(currentUserId, c));
        }
Exemplo n.º 2
0
        public void T007_When_When_Node_List_Contains_Valid_Node_Then_All_Of_Then_Must_Be_Returned_From_Parsing_As_Channels()
        {
            // arrange
            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);

            var x = new Mock <HttpPostedFileBase>();

            var opmlImporterIndexDto = new OpmlImporterIndexDto
            {
                ImportFile = x.Object
            };

            // act
            var rssList = this.sut.ParseToRssChannelList(opmlImporterIndexDto);

            // arrange
            Assert.AreEqual(1, rssList.Count);
        }
Exemplo n.º 3
0
        public List <RssSourceWithUrlAndTitle> ParseToRssChannelList(OpmlImporterIndexDto dto)
        {
            var outlines = this.importer.GetOutlines(dto.ImportFile.InputStream);
            var ot       = this.importer.FilterOutInvalidOutlines(outlines);
            var urls     = this.importer.SelectUrls(ot);

            return(urls);
        }
Exemplo n.º 4
0
        public virtual ActionResult Import(OpmlImporterIndexDto dto)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View("Import", null));
            }

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

            this.opmlImporterService.Import(dto);
            return this.RedirectToAction("My", "RssChannel");
        }
Exemplo n.º 6
0
        public ActionResult Index(OpmlImporterIndexDto dto)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View("Index", null));
            }

            this.opmlImporterService.Import(dto);
            return(this.RedirectToAction("My", "RssChannel"));
        }
Exemplo n.º 7
0
        public List <RssChannel> ParseToRssChannelList(OpmlImporterIndexDto dto)
        {
            var outlines = this.opmlHandler.GetOutlines(dto.ImportFile.InputStream);
            var ot       = this.FilterOutInvalidOutlines(outlines);
            var urls     = ot.Select(o =>
                                     new RssChannel(
                                         o.Attributes.GetNamedItem("xmlUrl").Value,
                                         o.Attributes.GetNamedItem("title").Value))
                           .ToList();

            return(urls);
        }
Exemplo n.º 8
0
        public void Import(OpmlImporterIndexDto dto)
        {
            var toRssChannelList = this.ParseToRssChannelList(dto);

            this.AddNewChannelsToGlobalSpace(toRssChannelList);
            var idByChannelUrl = this.entityRepository.GetIdByChannelUrl(
                toRssChannelList.Select(c => c.Url)
                .ToList());
            var currentUserId            = this.infrastructure.GetCurrentUserId();
            var channelsSubscribedByUser = this.entityRepository.GetChannelIdSubscriptionsForUser(currentUserId);

            channelsSubscribedByUser.ForEach(id => idByChannelUrl.Remove(id));
            idByChannelUrl.ForEach(c => this.entityRepository.CreateNewSubscriptionForUserAndChannel(currentUserId, c));
        }
Exemplo n.º 9
0
        public void T002_When_New_Channel_Was_Added_By_User_One_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> {
                1
            });

            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.Once);
        }
Exemplo n.º 10
0
        public void T004_When_Importing_RssChannels_From_Opml_File_Then_Must_Load_Nodes_Using_Opml_Importer()
        {
            // arrange
            this.mockOpmlReader
            .Setup(s => s.GetOutlines(It.IsAny <Stream>()))
            .Returns(new List <XmlNode>());

            var x = new Mock <HttpPostedFileBase>();


            var opmlImporterIndexDto = new OpmlImporterIndexDto
            {
                ImportFile = x.Object
            };

            // act
            this.sut.ParseToRssChannelList(opmlImporterIndexDto);

            // arrange
            this.mockOpmlReader
            .Verify(v => v.GetOutlines(It.IsAny <Stream>()),
                    Times.Once());
        }