public static void GetShowsShouldReturnProperCollection() { var mockProvider = new Mock <ITVMazeDataProvider>(); var shows = MockedShows(); var members1 = MockedCastMembers(1); var members2 = MockedCastMembers(2); mockProvider.Setup(s => s.GetShows(0)).Returns(shows); mockProvider.Setup(s => s.GetCastMembers(1)).Returns(members1); mockProvider.Setup(s => s.GetCastMembers(2)).Returns(members2); var manager = new ShowManager(mockProvider.Object); var returnedShows = manager.GetShows(0); Assert.NotEmpty(returnedShows); var ageSortedProperly = false; foreach (var s in returnedShows) { var a1 = s.Cast[0]; var a2 = s.Cast[1]; ageSortedProperly = a2.Birthdate > a1.Birthdate; break; } Assert.True(ageSortedProperly); }
public static void GetShowsShouldPauzeWhen429Occurrs() { var mockProvider = new Mock <ITVMazeDataProvider>(); var shows = MockedShows(); var members1 = MockedCastMembers(1); var members2 = MockedCastMembers(2); var count = 0; mockProvider.Setup(s => s.GetShows(0)).Returns(shows); mockProvider.Setup(s => s.GetCastMembers(1)).Callback(() => { count++; if (count == 1) { throw new DataSourceOverloadException(); } }).Returns(members1); mockProvider.Setup(s => s.GetCastMembers(2)).Returns(members2); var manager = new ShowManager(mockProvider.Object); var stopwatch = Stopwatch.StartNew(); var returnedShows = manager.GetShows(0); var duration = stopwatch.ElapsedMilliseconds; Assert.NotEmpty(returnedShows); Assert.True(duration > 5000); var ageSortedProperly = false; foreach (var s in returnedShows) { var a1 = s.Cast[0]; var a2 = s.Cast[1]; ageSortedProperly = a2.Birthdate > a1.Birthdate; break; } Assert.True(ageSortedProperly); }