public async void should_return_an_identified_pathway()
        {
            //Arrange

            var url = "http://mytest.com/";

            var pathwayNo = "PW755";
            var gender    = "Male";
            var age       = 35;

            var resultString = "identified pathway";

            _configuration.Setup(x => x.GetDomainApiIdentifiedPathwayUrl(pathwayNo, gender, age)).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.GetIdentifiedPathway(pathwayNo, gender, age);

            //Assert
            _configuration.Verify(x => x.GetDomainApiIdentifiedPathwayUrl(pathwayNo, gender, age), Times.Once);
            _restfulHelper.Verify(x => x.GetAsync(url), Times.Once);

            Assert.That(result, Is.EqualTo(resultString));
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        public async void should_return_an_identified_pathway()
        {
            //Arrange

            var url = "http://mytest.com/";

            var pathwayNo = "PW755";
            var gender    = "Male";
            var age       = 35;
            var pathway   = new Pathway {
                Title = "identified pathway"
            };

            var response = new Mock <IRestResponse <Pathway> >();

            response.Setup(_ => _.Data).Returns(pathway);

            _configuration.Setup(x => x.GetDomainApiIdentifiedPathwayUrl(pathwayNo, gender, age)).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.GetIdentifiedPathway(pathwayNo, gender, age);

            //Assert
            _configuration.Verify(x => x.GetDomainApiIdentifiedPathwayUrl(pathwayNo, gender, age), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <Pathway>(It.IsAny <IRestRequest>()), Times.Once);
            Assert.AreEqual(result.Title, "identified pathway");
        }
Esempio n. 5
0
        public async void GetPathwayMetaData_should_return_a_single_pathway_metadata_by_id_before_adding_to_cache()
        {
            //Arrange
            var id      = "PW123";
            var pathway = new PathwayMetaData()
            {
                DigitalTitle = "pathway1"
            };
            var expectedCacheKey = new PathwayMetaDataCacheKey(id);


            var response = new Mock <IRestResponse <PathwayMetaData> >();

            response.Setup(_ => _.Data).Returns(pathway);

            _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty);
            _restClient.Setup(x => x.ExecuteAsync <PathwayMetaData>(It.IsAny <IRestRequest>()))
            .ReturnsAsync(response.Object);

            var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock);

            //Act
            var result = await sut.GetPathwayMetaData(id);

            //Assert
            _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Once);
            _configuration.Verify(x => x.GetDomainApiPathwayMetadataUrl(id), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <PathwayMetaData>(It.IsAny <IRestRequest>()), Times.Once);
            Assert.AreEqual(result.DigitalTitle, "pathway1");
        }
Esempio n. 6
0
        public async void GetPathwayMetaData_should_return_a_single_pathway_metadata_by_id()
        {
            //Arrange

            var url     = "http://mytest.com/";
            var id      = "PW123";
            var pathway = new PathwayMetaData()
            {
                DigitalTitle = "pathway1"
            };

            var response = new Mock <IRestResponse <PathwayMetaData> >();

            response.Setup(_ => _.Data).Returns(pathway);

            _configuration.Setup(x => x.GetDomainApiPathwayMetadataUrl(id)).Returns(url);
            _restClient.Setup(x => x.ExecuteAsync <PathwayMetaData>(It.IsAny <IRestRequest>()))
            .ReturnsAsync(response.Object);

            var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock);

            //Act
            var result = await sut.GetPathwayMetaData(id);

            //Assert
            _configuration.Verify(x => x.GetDomainApiPathwayMetadataUrl(id), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <PathwayMetaData>(It.IsAny <IRestRequest>()), Times.Once);
            Assert.AreEqual(result.DigitalTitle, "pathway1");
        }
        public override void Given()
        {
            SeedTlevelTestData(EnumAwardingOrganisation.Pearson);
            CreateMapper();

            _logger  = Substitute.For <ILogger <IRepository <TlPathway> > >();
            _service = new PathwayService(Repository, _mapper);
        }
Esempio n. 8
0
        public override void Given()
        {
            SeedTlevelTestData();
            CreateMapper();

            _logger  = Substitute.For <ILogger <IRepository <TlPathway> > >();
            _service = new PathwayService(Repository, _mapper);
        }
        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));
        }
        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));
        }
Esempio n. 11
0
        public async void GetGroupedPathways_should_return_a_collection_of_pathways_by_age_and_gender_before_adding_to_cache()
        {
            //Arrange

            var grouped         = true;
            var groupedPathways = new List <GroupedPathways>()
            {
                new GroupedPathways()
                {
                    Group = "TestGroup", PathwayNumbers = new List <string>()
                    {
                        "pathway1", "pathway2"
                    }
                }
            };

            string gender   = "Male";
            var    response = new Mock <IRestResponse <IEnumerable <GroupedPathways> > >();

            response.Setup(_ => _.Data).Returns(groupedPathways);
            var expectedCacheKey = new GroupedPathwaysCacheKey(grouped, true);

            _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty);
            _restClient.Setup(x => x.ExecuteAsync <IEnumerable <GroupedPathways> >(It.IsAny <IRestRequest>()))
            .ReturnsAsync(response.Object);

            var sut = new PathwayService(_configuration.Object, _restClient.Object, _cacheStoreMock);

            //Act
            var result = await sut.GetGroupedPathways(grouped, true);

            //Assert
            _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Once);
            _configuration.Verify(x => x.GetDomainApiGroupedPathwaysUrl(grouped, true), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <IEnumerable <GroupedPathways> >(It.IsAny <IRestRequest>()), Times.Once);
            Assert.AreEqual(result.First().Group, "TestGroup");
        }
        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);
        }