public void Discogs2FinderTester_ProblemWithInternet() { //Arrange IWebUserSettings iwsb = Substitute.For<IWebUserSettings>(); iwsb.DiscogsActivated.Returns(true); IInternetProvider wrb = Substitute.For<IInternetProvider>(); IHttpWebRequest wr = Substitute.For<IHttpWebRequest>(); wr.Headers.Returns(new System.Collections.Specialized.NameValueCollection()); IHttpWebResponse wres = Substitute.For<IHttpWebResponse>(); wres.StatusCode.Returns(HttpStatusCode.BadRequest); wr.GetResponse().Returns(wres); wrb.CreateHttpRequest(Arg.Any<string>()).Returns(wr); InternetProvider.InternetHelper = wrb; IWebQuery wq = Substitute.For<IWebQuery>(); wq.Type.Returns(QueryType.FromAlbumInfo); IAlbumDescriptor iad = Substitute.For<IAlbumDescriptor>(); wq.AlbumDescriptor.Returns(iad); //Act CancellationToken ct = new CancellationToken(false); Discogs2Finder target = new Discogs2Finder(iwsb); target.MonitorEvents(); ; //Assert var res = target.Search(wq, ct); res.Should().NotBeNull(); var listres = res.ToList(); listres.Should().BeEmpty(); target.ShouldRaise("OnInternetError").WithSender(target); }
public void Discogs2FinderTester_PartialResult() { //new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(myPage)); //Arrange IWebUserSettings iwsb = Substitute.For<IWebUserSettings>(); iwsb.DiscogsActivated.Returns(true); IInternetProvider wrb = Substitute.For<IInternetProvider>(); IHttpWebRequest wrFirst = Substitute.For<IHttpWebRequest>(); wrFirst.Headers.Returns(new System.Collections.Specialized.NameValueCollection()); IHttpWebResponse wresok = Substitute.For<IHttpWebResponse>(); wresok.StatusCode.Returns(HttpStatusCode.OK); wresok.GetResponseStream().Returns(new MemoryStream(Encoding.UTF8.GetBytes(_FakeAnswer))); wrFirst.GetResponse().Returns(wresok); IHttpWebRequest wrSecond = Substitute.For<IHttpWebRequest>(); wrSecond.Headers.Returns(new System.Collections.Specialized.NameValueCollection()); IHttpWebResponse wresko = Substitute.For<IHttpWebResponse>(); wresko.StatusCode.Returns(HttpStatusCode.BadRequest); wresko.GetResponseStream().Returns((Stream)null); wrSecond.GetResponse().Returns(wresko); wrb.CreateHttpRequest(Arg.Any<string>()).Returns(wrFirst, wrSecond, wrSecond); InternetProvider.InternetHelper = wrb; IWebQuery wq = Substitute.For<IWebQuery>(); wq.Type.Returns(QueryType.FromAlbumInfo); IAlbumDescriptor iad = Substitute.For<IAlbumDescriptor>(); wq.AlbumDescriptor.Returns(iad); //Act CancellationToken ct = new CancellationToken(false); Discogs2Finder target = new Discogs2Finder(iwsb); target.MonitorEvents(); ; //Assert var res = target.Search(wq, ct); res.Should().NotBeNull(); var listres = res.ToList(); listres.Should().BeEmpty(); target.ShouldRaise("OnInternetError").WithSender(target); }