public StoryService(IHackerRestClient hackerClient, IConfiguration configuration, IStoryRepo storyRepo) { this.storyRepo = storyRepo; this.hackerClient = hackerClient; this.configuration = configuration; this.postfix = this.configuration["HackerApi:PathPostfix"]; this.storyDetailPathPrefix = this.configuration["HackerApi:StoryDetailPathPrefix"]; this.storiesPath = this.BuildStoriesPath(); Task.Run(() => this.StartAutoRetrieveStories()); }
public async Task GetAll_T_Null_path_Generates_AssertionException() { // Arrange var dummyList = new List <T>(); this.sut = new HackerRestClient(this.mockRestClient.Object, this.mockConfig.Object); // Act / Assert Assert.ThrowsAsync <NUnit.Framework.AssertionException>(async() => await this.sut.GetAll <T>(null)); }
public async Task GetAll_T_ExecuteAsync_Is_Called_Once() { // Arrange var dummyList = new List <T>(); var dummyResponse = new RestResponse <IList <T> > { Data = dummyList }; this.mockRestClient.Setup(x => x.ExecuteAsync <IList <T> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>())).ReturnsAsync(dummyResponse); this.sut = new HackerRestClient(this.mockRestClient.Object, this.mockConfig.Object); // Act var result = await this.sut.GetAll <T>(base.DummyUrl); // Assert this.mockRestClient.Verify(x => x.ExecuteAsync <IList <T> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Once()); }
public async Task GetAll_T_Returns_Expected_List_T() { // Arrange var dummyList = new List <T>(); var dummyResponse = new RestResponse <IList <T> > { Data = dummyList }; this.mockRestClient.Setup(x => x.ExecuteAsync <IList <T> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>())).ReturnsAsync(dummyResponse); this.sut = new HackerRestClient(this.mockRestClient.Object, this.mockConfig.Object); // Act var result = await this.sut.GetAll <T>(base.DummyUrl); // Assert Assert.IsTrue(result is List <T>); Assert.AreEqual(result, dummyList); }
public void TestInit() { this.mockConfig.SetupGet(x => x[Constants.BaseUrlConfigKey]).Returns(base.config[Constants.BaseUrlConfigKey]); this.mockConfig.SetupGet(x => x[Constants.PathPostfixConfigKey]).Returns(base.config[Constants.PathPostfixConfigKey]); this.sut = new HackerRestClient(new RestClient(), this.mockConfig.Object); }