예제 #1
0
 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());
 }
예제 #2
0
        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));
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }
예제 #5
0
 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);
 }