Skip to content

Commit

Permalink
Fix for failing stats test.
Browse files Browse the repository at this point in the history
  • Loading branch information
samjudson committed Jul 3, 2015
1 parent 353c99f commit 7e39125
Showing 1 changed file with 136 additions and 124 deletions.
260 changes: 136 additions & 124 deletions FlickrNetTest/Async/StatsAsyncTests.cs
Original file line number Diff line number Diff line change
@@ -1,124 +1,136 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using FlickrNet;
using System.Reactive.Subjects;
using System.Reactive.Linq;

namespace FlickrNetTest.Async
{
[TestFixture]
[Category("AccessTokenRequired")]
public class StatsAsyncTests
{
[Test]
public void StatsGetCollectionDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetCollectionDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotoDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotoDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotostreamDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotostreamDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotosetDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotosetDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}


[Test]
public void StatsGetCollectionStatsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

var collection = f.CollectionsGetTree().First();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetCollectionStatsAsync(d, collection.CollectionId, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);

}

[Test]
public void StatsGetPhotoStatsAsyncTest()
{
Flickr.CacheDisabled = true;

Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetPhotoStatsAsync(d, "7176125763", r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
if (result.HasError) throw result.Error;

Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotostreamStatsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetPhotostreamStatsAsync(d, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);

Assert.IsTrue(result.Result.Views > 0, "Views should be greater than 0");
}
}
}
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using FlickrNet;
using System.Reactive.Subjects;
using System.Reactive.Linq;
using Shouldly;

namespace FlickrNetTest.Async
{
[TestFixture]
[Category("AccessTokenRequired")]
public class StatsAsyncTests
{
[Test]
public void StatsGetCollectionDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetCollectionDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotoDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotoDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotostreamDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotostreamDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotosetDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotosetDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);
}


[Test]
public void StatsGetCollectionStatsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

var collection = f.CollectionsGetTree().First();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetCollectionStatsAsync(d, collection.CollectionId, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
Assert.IsFalse(result.HasError);

}

[Test]
public void StatsGetPhotoStatsAsyncTest()
{
Flickr.CacheDisabled = true;

Flickr f = TestData.GetAuthInstance();

DateTime d = DateTime.Today.AddDays(-7);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetPhotoStatsAsync(d, "7176125763", r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();
if (result.HasError) throw result.Error;

Assert.IsFalse(result.HasError);
}

[Test]
public void StatsGetPhotostreamStatsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();

var range = Enumerable.Range(7, 5);
var list = new List<Stats>();

foreach(var i in range)
{
var d = DateTime.Today.AddDays(-i);

var w = new AsyncSubject<FlickrResult<Stats>>();
f.StatsGetPhotostreamStatsAsync(d, r => { w.OnNext(r); w.OnCompleted(); });

var result = w.Next().First();

result.HasError.ShouldBe(false);
result.Result.ShouldNotBe(null);

list.Add(result.Result);
}

list.Count.ShouldBe(5);
list.ShouldContain(s => s.Views > 0);
}
}
}

0 comments on commit 7e39125

Please sign in to comment.