public void QueryProcessor_TestExecuteQuery() { //Uses Moq to test the Query Processor logic //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = "Registrant"; //use this to return a pre-determined set of data that we control: var registrant = CreateRegistrants(); var webinar = CreateUpcomingWebinars(); //set up the fake data: var clientMoq = new Mock<IGoToWebinarClient>(); clientMoq.Setup(client => client.GetUpcomingWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"])).Returns(webinar); clientMoq.Setup(client => client.GetRegistrants(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], "1235813")).Returns(registrant); //create our the instance of the queryprocessor using our Moq class: var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable<DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: //since we're returning a predeternimed list of registrants, //we're only testing the translation of registrants to dataentities. Assert.AreEqual(2, dataEntities.Count()); Assert.IsTrue(dataEntities.Any(entity => entity.Properties.Any(field => field.Value == "jim"))); }
public void QueryProcessor_TestExecuteQuery() { //Uses Moq to test the Query Processor logic //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = "Registrant"; //use this to return a pre-determined set of data that we control: var registrant = CreateRegistrants(); var webinar = CreateUpcomingWebinars(); //set up the fake data: var clientMoq = new Mock <IGoToWebinarClient>(); clientMoq.Setup(client => client.GetUpcomingWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"])).Returns(webinar); clientMoq.Setup(client => client.GetRegistrants(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], "1235813")).Returns(registrant); //create our the instance of the queryprocessor using our Moq class: var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable <DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: //since we're returning a predeternimed list of registrants, //we're only testing the translation of registrants to dataentities. Assert.AreEqual(2, dataEntities.Count()); Assert.IsTrue(dataEntities.Any(entity => entity.Properties.Any(field => field.Value == "jim"))); }
public void QueryProcessor_TestExecuteQuery_NullQueryName() { //Test a 'bad' condition to make sure the code doesn't break: //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = null; var clientMoq = new Mock<IGoToWebinarClient>(); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable<DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: Assert.IsNotNull(dataEntities); }
public void QueryProcessor_TestExecuteQuery_UnknownEntityName() { //Test an unknown entity: //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = "UnkownEntity"; var clientMoq = new Mock <IGoToWebinarClient>(); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable <DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: Assert.IsNotNull(dataEntities); }
public void QueryProcessor_TestExecuteQuery_NullQueryName() { //Test a 'bad' condition to make sure the code doesn't break: //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = null; var clientMoq = new Mock <IGoToWebinarClient>(); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable <DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: Assert.IsNotNull(dataEntities); }
public void QueryProcessor_TestExecute_FilteredAndOrdered() { //Arrange: var connectionInfo = CreateConnectionInfo(); var registrants = CreateRegistrants(); var webinar = CreateUpcomingWebinars(); var misMatchedRegistrant = new Registrant { Email = "*****@*****.**", WebinarKey = "246810", FirstName = "john" }; registrants.Add(misMatchedRegistrant); var query = CreateFilterQuery(); //set up the fake data: var clientMoq = new Mock <IGoToWebinarClient>(); clientMoq.Setup(client => client.GetUpcomingWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"])).Returns(webinar); clientMoq.Setup(client => client.GetRegistrants(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], "1235813")).Returns(registrants); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable <DataEntity> entities = queryProcessor.ExecuteQuery(query); //Assert //check the count: Assert.AreEqual(2, entities.Count()); //check the ordering. We specified Descending, so Jim should be at the top, Bob at the bottom. DataEntity jim = entities.First(); Assert.IsTrue(jim.Properties.Any(field => field.Value == "jim")); }
public void QueryProcessor_TestExecute_DateFilteredWebinar() { //We're not testing to see if GoToWebinar filters correctly, //but that our Query Builder does the right stuff //Arrange var connectionInfo = CreateConnectionInfo(); var query = CreateDateFilterQuery(); var webinars = CreateWebinars(); var clientMoq = new Mock <IGoToWebinarClient>(); clientMoq.Setup(client => client.GetWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], new DateTime(2010, 01, 01), new DateTime(2013, 01, 01))).Returns(webinars); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable <DataEntity> entities = queryProcessor.ExecuteQuery(query); //Assert Assert.AreEqual(1, entities.Count()); }
public void QueryProcessor_TestExecuteQuery_UnknownEntityName() { //Test an unknown entity: //Arrange: var connectionInfo = CreateConnectionInfo(); var query = new Query(); query.RootEntity.ObjectDefinitionFullName = "UnkownEntity"; var clientMoq = new Mock<IGoToWebinarClient>(); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable<DataEntity> dataEntities = queryProcessor.ExecuteQuery(query); //Assert: Assert.IsNotNull(dataEntities); }
public void QueryProcessor_TestExecute_FilteredAndOrdered() { //Arrange: var connectionInfo = CreateConnectionInfo(); var registrants = CreateRegistrants(); var webinar = CreateUpcomingWebinars(); var misMatchedRegistrant = new Registrant { Email = "*****@*****.**", WebinarKey = "246810", FirstName = "john" }; registrants.Add(misMatchedRegistrant); var query = CreateFilterQuery(); //set up the fake data: var clientMoq = new Mock<IGoToWebinarClient>(); clientMoq.Setup(client => client.GetUpcomingWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"])).Returns(webinar); clientMoq.Setup(client => client.GetRegistrants(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], "1235813")).Returns(registrants); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable<DataEntity> entities = queryProcessor.ExecuteQuery(query); //Assert //check the count: Assert.AreEqual(2, entities.Count()); //check the ordering. We specified Descending, so Jim should be at the top, Bob at the bottom. DataEntity jim = entities.First(); Assert.IsTrue(jim.Properties.Any(field => field.Value == "jim")); }
public void QueryProcessor_TestExecute_DateFilteredWebinar() { //We're not testing to see if GoToWebinar filters correctly, //but that our Query Builder does the right stuff //Arrange var connectionInfo = CreateConnectionInfo(); var query = CreateDateFilterQuery(); var webinars = CreateWebinars(); var clientMoq = new Mock<IGoToWebinarClient>(); clientMoq.Setup(client => client.GetWebinars(connectionInfo["AccessToken"], connectionInfo["OrganizerKey"], new DateTime(2010, 01, 01), new DateTime(2013, 01, 01))).Returns(webinars); var queryProcessor = new QueryProcessor(connectionInfo, clientMoq.Object); //Act: IEnumerable<DataEntity> entities = queryProcessor.ExecuteQuery(query); //Assert Assert.AreEqual(1, entities.Count()); }
public ActionResult FamilySearch(string pid, string rid, string dir) { NetworkClient client = new NetworkClient(new DataProperties()); personRankConnectionPool = client.CreatePool(new ServerId[] { new ServerId("10.8.129.1:80") }, 60000, 60000); queryProcessor = new QueryProcessor(personRankConnectionPool); // Get the census year from database id int censusYear = CensusHelper.GetCensusYear(int.Parse(rid)); // Get the previous/next census year int databaseId = CensusHelper.GetDatabaseId(censusYear, dir); if (databaseId == 0) { return new JsonResult { Data = string.Empty, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } // Get the previous database id int searchCensusYear = CensusHelper.GetCensusYear(databaseId); QueryResultList results; try { results = queryProcessor.ExecuteQuery(string.Format("{0}:{1}", pid, rid)); } catch { return new JsonResult { Data = string.Empty, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } List<SimpleFamily> familyResults = new List<SimpleFamily>(); List<Family> filteredResults = null; //#region new approach //foreach (QueryResult result in results) //{ // if (result.Person.Id.DatabaseId == databaseId) // { // var familyList = results.PersonContainer.GetFamilies(result.Person.Id); // if (familyList.Count > 1) // { // foreach (Family family in familyList) // { // SimpleFamily simpleFamily = new SimpleFamily(); // simpleFamily.Id = family.Id; // simpleFamily.CensusYear = searchCensusYear; // simpleFamily.Mother = SimplePerson.CreatePerson(results.PersonContainer.GetPerson(family.MotherId), simpleFamily.CensusYear); // simpleFamily.Father = SimplePerson.CreatePerson(results.PersonContainer.GetPerson(family.FatherId), simpleFamily.CensusYear); // foreach (RelationshipPointer child in family.Children.ChildPointers) // { // simpleFamily.Children.Add(SimplePerson.CreatePerson(results.PersonContainer.GetPerson(child.Id), simpleFamily.CensusYear)); // } // simpleFamily.FindPerson(results); // familyResults.Add(simpleFamily); // } // } // else // { // SimpleFamily simpleFamily = new SimpleFamily(); // if (result.Person.Gender == GenderType.Female) // { // simpleFamily.Mother = SimplePerson.CreatePerson(result.Person, censusYear); // } // else // { // simpleFamily.Father = SimplePerson.CreatePerson(result.Person, censusYear); // } // familyResults.Add(simpleFamily); // } // } //} //return new JsonResult //{ // Data = familyResults, // JsonRequestBehavior = JsonRequestBehavior.AllowGet //}; //#endregion ////////////////////////////////////////////////////// filteredResults = results.PersonContainer.GetFamilies().Where(x => x.Id.Contains(databaseId.ToString())).Take(5).ToList(); foreach (Family family in filteredResults) { SimpleFamily simpleFamily = new SimpleFamily(); simpleFamily.Id = family.Id; simpleFamily.CensusYear = searchCensusYear; //simpleFamily.Version = family.Version; simpleFamily.Mother = SimplePerson.CreatePerson(results.PersonContainer.GetPerson(family.MotherId), simpleFamily.CensusYear); simpleFamily.Father = SimplePerson.CreatePerson(results.PersonContainer.GetPerson(family.FatherId), simpleFamily.CensusYear); foreach (RelationshipPointer child in family.Children.ChildPointers) { simpleFamily.Children.Add(SimplePerson.CreatePerson(results.PersonContainer.GetPerson(child.Id), simpleFamily.CensusYear)); } simpleFamily.FindPerson(results); familyResults.Add(simpleFamily); } List<QueryResult> singlePeople = results.Where(x => results.PersonContainer.GetFamilies(x.Person.Id).Count == 0 && x.Person.Id.DatabaseId == databaseId).ToList(); foreach (QueryResult single in singlePeople) { SimpleFamily simpleFamily = new SimpleFamily(); simpleFamily.Id = ""; simpleFamily.CensusYear = searchCensusYear; simpleFamily.IsSingleHouseHold = true; simpleFamily.SinglePerson = SimplePerson.CreatePerson(single.Person, censusYear); simpleFamily.SinglePerson.Selected = true; simpleFamily.FindPerson(results); familyResults.Add(simpleFamily); } return new JsonResult { Data = familyResults, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public ActionResult RecordLink(string pid, string rid, string familyId, string compareFamilyId) { DefaultComparisonEngineConfigurationFileLocation = Path.Combine(Request.PhysicalApplicationPath, DefaultComparisonEngineConfigurationFileLocation); NetworkClient client = new NetworkClient(new DataProperties()); personRankConnectionPool = client.CreatePool(new ServerId[] { new ServerId("10.8.129.1:80") }, 60000, 60000); queryProcessor = new QueryProcessor(personRankConnectionPool); // TODO: Send person id int censusYear = CensusHelper.GetCensusYear(int.Parse(rid)); int databaseId = CensusHelper.GetDatabaseId(censusYear, "prev"); int searchCensusYear = CensusHelper.GetCensusYear(databaseId); QueryResultList results; try { results = queryProcessor.ExecuteQuery(string.Format("{0}:{1}", pid, rid)); } catch { return new JsonResult { Data = string.Empty, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } Family family = results.PersonContainer.GetFamilies().Where(x => x.Id == familyId).FirstOrDefault(); Family compareFamily = results.PersonContainer.GetFamilies().Where(x => x.Id == compareFamilyId).FirstOrDefault(); // TODO: loop through the family IList<PersonModel.Person> personList = new List<PersonModel.Person>(); IList<PersonModel.Person> personList2 = new List<PersonModel.Person>(); foreach (RelationshipPointer child in family.Children.ChildPointers) { PersonModel.Person person = results.PersonContainer.GetPerson(child.Id); foreach (RelationshipPointer compareChild in compareFamily.Children.ChildPointers) { PersonModel.Person comparePerson = results.PersonContainer.GetPerson(child.Id); FeatureComparisonEngine comparisonEngine = new FeatureComparisonEngine(DefaultComparisonEngineConfigurationFileLocation); ComparisonResult result = comparisonEngine.ComparePeople(results.PersonContainer, person, comparePerson); } } return new JsonResult { Data = string.Empty, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }