public void Remove() { var feeds = Create(); var cache = Get(nameof(Remove), "Cache"); using (var src = new RssCacheDictionary { Directory = cache }) { src.Capacity = 3; foreach (var e in feeds) { src.Add(e); } Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(3)); src.Remove(feeds[0].Uri); Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(3)); src.Remove(feeds[1].Uri, true); Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(2)); src.Remove(new KeyValuePair <Uri, RssFeed>(feeds[2].Uri, feeds[2])); Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(2)); } }
public void Stash() { var feeds = Create(); var cache = Get(nameof(Stash), "Cache"); using (var src = new RssCacheDictionary { Directory = cache }) { src.Capacity = 3; foreach (var feed in feeds) { src.Add(feed); } Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(3)); } Assert.That(IO.GetFiles(cache).Count(), Is.EqualTo(6)); }
public void Contains() { var feeds = Create(); var cache = Get(nameof(Contains), "Cache"); using (var src = new RssCacheDictionary { Directory = cache }) { foreach (var e in feeds) { src.Add(e); } var q = feeds[0]; Assert.That(src.ContainsKey(q.Uri), Is.True); Assert.That(src.Contains(new KeyValuePair <Uri, RssFeed>(q.Uri, q)), Is.True); Assert.That(src.Contains(new KeyValuePair <Uri, RssFeed>(q.Uri, null)), Is.False); } }
public void Monitor_RssCacheDictionary() { var start = DateTime.Now; var uris = new[] { new Uri("https://blog.cube-soft.jp/?feed=rss2"), new Uri("https://blogs.msdn.microsoft.com/dotnet/feed"), }; var files = new[] { "872e24035276c7104afd116c2052172b", "3a9c5f4a720884dddb53fb356680ef82", }; using (var src = new RssCacheDictionary()) { src.Directory = Results; foreach (var uri in uris) { src.Add(uri, default(RssFeed)); } using (var mon = Create()) { var count = 0; var cts = new CancellationTokenSource(); var asm = Assembly.GetExecutingAssembly().GetReader(); var agent = $"CubeRssMonitorTest/{asm.Version}"; mon.Timeout = TimeSpan.FromSeconds(5); mon.UserAgent = agent; Assert.That(mon.UserAgent, Is.EqualTo(agent)); mon.Register(uris); mon.Register(uris); // ignore mon.Subscribe(_ => throw new ArgumentException("Test")); mon.Subscribe(e => { src[e.Uri] = e; if (++count >= 2) { cts.Cancel(); } }); mon.Start(); Assert.That(Wait.For(cts.Token), "Timeout"); mon.Stop(); } foreach (var item in src) { Assert.That(item.Value, Is.Not.Null); } Assert.That(src.TryGetValue(uris[0], out var feed0), Is.True); Assert.That(feed0.Title, Is.EqualTo("CubeSoft Blog")); Assert.That(feed0.LastChecked, Is.GreaterThan(start), uris[0].ToString()); Assert.That(feed0.Items.Count, Is.GreaterThan(0), uris[0].ToString()); Assert.That(src.TryGetValue(uris[1], out var feed1), Is.True); Assert.That(feed1.Title, Is.EqualTo(".NET Blog")); Assert.That(feed1.LastChecked, Is.GreaterThan(start), uris[1].ToString()); Assert.That(feed1.Items.Count, Is.GreaterThan(0), uris[1].ToString()); Assert.That(src.TryGetValue(new Uri("http://www.example.com/"), out var feed2), Is.False); } Assert.That(IO.Get(GetResultsWith(files[0])).Length, Is.GreaterThan(0), files[0]); Assert.That(IO.Get(GetResultsWith(files[1])).Length, Is.GreaterThan(0), files[1]); }