public async void GetPathway_should_return_a_single_pathway_by_id_before_adding_to_cache() { //Arrange var id = "PW123"; var pathway = new Pathway { Title = "pathway1", Id = "PW12" }; var expectedCacheKey = new PathwayCacheKey(id); _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty); var response = new Mock <IRestResponse <Pathway> >(); response.Setup(_ => _.Data).Returns(pathway); _restClient.Setup(x => x.ExecuteAsync <Pathway>(It.IsAny <IRestRequest>())) .ReturnsAsync(response.Object); var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock); //Act var result = await sut.GetPathway(id); //Assert _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Once); _configuration.Verify(x => x.GetDomainApiPathwayUrl(id), Times.Once); _restClient.Verify(x => x.ExecuteAsync <Pathway>(It.IsAny <IRestRequest>()), Times.Once); Assert.AreEqual(result.Title, "pathway1"); }
public async void GetPathway_should_return_a_single_pathway_by_id() { //Arrange var url = "http://mytest.com/"; var id = "PW123"; var pathway = new Pathway { Title = "pathway1" }; var response = new Mock <IRestResponse <Pathway> >(); response.Setup(_ => _.Data).Returns(pathway); _configuration.Setup(x => x.GetDomainApiPathwayUrl(id)).Returns(url); _restClient.Setup(x => x.ExecuteAsync <Pathway>(It.IsAny <IRestRequest>())) .ReturnsAsync(response.Object); var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock); //Act var result = await sut.GetPathway(id); //Assert _configuration.Verify(x => x.GetDomainApiPathwayUrl(id), Times.Once); _restClient.Verify(x => x.ExecuteAsync <Pathway>(It.IsAny <IRestRequest>()), Times.Once); Assert.AreEqual(result.Title, "pathway1"); }
public async void should_return_a_single_pathway_by_id() { //Arrange var url = "http://mytest.com/"; var id = "PW123"; var resultString = "pathway1"; _configuration.Setup(x => x.GetDomainApiPathwayUrl(id)).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.GetPathway(id); //Assert _configuration.Verify(x => x.GetDomainApiPathwayUrl(id), Times.Once); _restfulHelper.Verify(x => x.GetAsync(url), Times.Once); Assert.That(result.Split(new string[] { "},{" }, StringSplitOptions.None).Count(), Is.EqualTo(1)); Assert.That(result, Is.EqualTo(resultString)); }
private List <ReportView> ConvertToReportView(List <Report> reports) { List <ReportView> reportView = new List <ReportView> (); if (reports != null && reports.Count > 0) { inspectionTransactionService = new InspectionTransactionService(AppDelegate.DatabaseContext); pathwayService = new PathwayService(AppDelegate.DatabaseContext); inspectionService = new InspectionService(AppDelegate.DatabaseContext); foreach (var report in reports) { if (reportView.Where(rv => rv.InspectionTransactionID == report.InspectionTransID).Count() <= 0) { var inspection = inspectionTransactionService.GetInspectionProjectID(report.InspectionTransID); if (inspection != null) { switch (inspection.PathwayTypeID) { case (0): inspection.PathwayTypeID = 1; break; case (1): inspection.PathwayTypeID = 2; break; case (2): inspection.PathwayTypeID = 3; break; default: break; } var pathway = pathwayService.GetPathway(inspection.PathwayTypeID); var inspectionType = inspectionService.GetInspection(Convert.ToInt32(inspection.InspectionID)); if ((report.ReportType.ToUpper() == ReportType.Pass.ToString().ToUpper()) || (report.ReportType.ToUpper() == ReportType.Fail.ToString().ToUpper())) { } else { report.ReportType = string.Empty; } reportView.Add(new ReportView() { AppID = inspection.ProjectID.ToString(), InspectionType = inspectionType.InspectionType, PathwayType = (pathway != null) ? pathway.PathwayDesc : "", ReportDesc = null, ReportType = report.ReportType, InspectionTransactionID = report.InspectionTransID, }); } } } } return(reportView); }