public async void GetPathways_should_return_a_collection_of_pathways_by_age_and_gender_before_adding_to_cache() { //Arrange var url = "http://mytest.com/"; var unique = true; var pathways = new[] { new Pathway { Title = "pathway1" }, new Pathway { Title = "pathway2" }, }; var age = 22; string gender = "Male"; var response = new Mock <IRestResponse <IEnumerable <Pathway> > >(); response.Setup(_ => _.Data).Returns(pathways); var expectedCacheKey = new PathwaysCacheKey(unique, false, gender, age); _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty); _configuration.Setup(x => x.GetDomainApiPathwaysUrl(unique, false)).Returns(url); _restClient.Setup(x => x.ExecuteAsync <IEnumerable <Pathway> >(It.IsAny <IRestRequest>())) .ReturnsAsync(response.Object); var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock); //Act var result = await sut.GetPathways(unique, false, gender, age); //Assert _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Once); _configuration.Verify(x => x.GetDomainApiPathwaysUrl(unique, false, gender, age), Times.Once); _restClient.Verify(x => x.ExecuteAsync <IEnumerable <Pathway> >(It.IsAny <IRestRequest>()), Times.Once); Assert.AreEqual(result.Count(), 2); Assert.AreEqual(result.First().Title, "pathway1"); }
public async void should_return_a_collection_of_pathways() { //Arrange var url = "http://mytest.com/"; var unique = true; var pathways = new[] { new Pathway { Title = "pathway1" }, new Pathway { Title = "pathway2" }, }; var response = new Mock <IRestResponse <IEnumerable <Pathway> > >(); response.Setup(_ => _.Data).Returns(pathways); _configuration.Setup(x => x.GetDomainApiPathwaysUrl(unique, false)).Returns(url); _restClient.Setup(x => x.ExecuteAsync <IEnumerable <Pathway> >(It.IsAny <IRestRequest>())) .ReturnsAsync(response.Object); var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock); //Act var result = await sut.GetPathways(unique, false); //Assert _configuration.Verify(x => x.GetDomainApiPathwaysUrl(unique, false), Times.Once); _restClient.Verify(x => x.ExecuteAsync <IEnumerable <Pathway> >(It.IsAny <IRestRequest>()), Times.Once); Assert.AreEqual(result.Count(), 2); Assert.AreEqual(result.First().Title, "pathway1"); }
public async void should_return_a_collection_of_pathways() { //Arrange var url = "http://mytest.com/"; var unique = true; var resultString = "pathway1, pathway2"; _configuration.Setup(x => x.GetDomainApiPathwaysUrl(unique)).Returns(url); _restfulHelper.Setup(x => x.GetAsync(url)).Returns(Task.FromResult(resultString)); var sut = new PathwayService(_configuration.Object, _restfulHelper.Object); //Act var result = await sut.GetPathways(unique); //Assert _configuration.Verify(x => x.GetDomainApiPathwaysUrl(unique), Times.Once); _restfulHelper.Verify(x => x.GetAsync(url), Times.Once); Assert.That(result.Split(new string[] { "," }, StringSplitOptions.None).Count(), Is.EqualTo(2)); Assert.That(result, Is.EqualTo(resultString)); }