public void Backend_DbAccess_CreateOneGovBodyTest() { // ARRANGE // Database.SetInitializer( // new DropCreateDatabaseAlways<MeetingContext>()); GovernmentBody BodyWritten = new GovernmentBody() { Name = "U.S. Senate", Country = "U.S.A.", Meetings = new List <Meeting>() }; // ACT using (var context = new ApplicationDbContext()) { //if (context.Database.Exists()) context.Database.Delete(); context.GovernmentBodies.Add(BodyWritten); context.SaveChanges(); // ASSERT var query = from g in context.GovernmentBodies select g; var BodyRetrieved = query.SingleOrDefault(); Assert.That(BodyRetrieved, Is.Not.Null); Assert.That(BodyRetrieved.Name, Is.EqualTo(BodyWritten.Name)); Assert.That(BodyRetrieved.Country, Is.EqualTo(BodyWritten.Country)); } }
public GovernmentBody Get(string country, string state, string county, string municipality) { GovernmentBody g = testGovBodies.Find(element => (element.Country == country) && (element.County == county) && (element.State == state) && (element.Municipality == municipality) ); return(g); }
/// <summary> /// Gets an existing government body in the database. /// </summary> /// <param name="govBody">The gov body.</param> /// <returns>existing government body or null.</returns> public GovernmentBody GetExistingBody(GovernmentBody govBody) { GovernmentBody gBody; var query = from g in applicationDbContext.GovernmentBodies where g.Name == govBody.Name && g.Country == govBody.Country && g.State == govBody.State && g.County == govBody.County && govBody.Municipality == govBody.Municipality select g; gBody = query.SingleOrDefault(); return(gBody); }
public string GetWorkFolderPath(long meetingId) { Meeting meeting = meetingRepository.Get(meetingId); GovernmentBody g = govBodyRepository.Get(meeting.GovernmentBodyId); string language = g.Languages[0].Name; MeetingFolder meetingFolder = new MeetingFolder(g.Country, g.State, g.County, g.Municipality, meeting.Date, g.Name, language); string meetingFolderPath = meetingFolder.path; string workFolder = _config.DatafilesPath + "\\PROCESSING\\" + meetingFolderPath + "\\" + WORK_FOLDER_NAME; //string workFolderPath = Path.Combine(_config.DatafilesPath,workFolder); return(workFolder); }
private string GetPartFolder(long meetingId, int part) { Meeting meeting = meetingRepository.Get(meetingId); GovernmentBody g = govBodyRepository.Get(meeting.GovernmentBodyId); string language = g.Languages[0].Name; MeetingFolder meetingFolder = new MeetingFolder(g.Country, g.State, g.County, g.Municipality, meeting.Date, g.Name, language); string meetingFolderPath = meetingFolder.path; string workFolder = datafiles + @"\PROCESSING\" + meetingFolderPath + @"\" + WORK_FOLDER_NAME + $"\\part{part:D2}"; //string partFolder = workFolder + $"\\part{part:D2}"; //string partFolderPath = Path.Combine(datafiles, partFolder); return(workFolder); }
/// <summary> /// Gets an existing government body if it is in the database. /// Otherwise it add the one that is passed /// </summary> /// <param name="govBody">The gov body.</param> /// <returns>existing government body already exists in the database, return that one. Otherwise /// return null so that call will use the one that was passed to this routine.</returns> public GovernmentBody GetOrAddGovernmentBody(GovernmentBody govBody) { GovernmentBody gBody = GetExistingBody(govBody); // If the government body is already in the database, use it. if (gBody != null) { return(gBody); } else { // Otherwise add the new one that the caller created. // Create an empty meeting list. govBody.Meetings = new List <Meeting>(); applicationDbContext.GovernmentBodies.Add(govBody); return(null); } }
public MeetingFolder(IGovBodyRepository govBodyRepository, Meeting meeting) { try { GovernmentBody g = govBodyRepository.Get(meeting.GovernmentBodyId); language = g.Languages[0].Name; country = g.Country; state = g.State; county = g.County; municipality = g.Municipality; date = date = string.Format("{0:yyyy-MM-dd}", meeting.Date); SetCalculatedFields(); valid = true; } catch { valid = false; } }
/// <summary> /// Call methods on the ReadTranscriptFile object in the correct sequence to read and parse the data. /// When reading and parsing is complete, write the data to the database. /// </summary> /// <param name="readTranscript">The load transcript.</param> public void LoadAndSave(ReadTranscriptFile readTranscript) { //using (dBOperations dbOps = new dBOperations()) //{ List <Category> categories = dbOps.GetCategories(); // Get the governent body info from the transcipt header GovernmentBody govBody = readTranscript.LoadHeadingInfo(); if (govBody != null) { GovernmentBody gBody; List <Topic> topics; // See if that government body already exists in the database // If it is present, get the existing topics if ((gBody = dbOps.GetOrAddGovernmentBody(govBody)) != null) { topics = dbOps.GetExistingTopics(govBody.Id); } // otherwise create a new empty list of topics else { topics = new List <Topic>(); } // Add new topics from new transcript to the topic list // Get the meeting body info from the transcript Meeting meeting = readTranscript.LoadMeetingData(categories, topics); if (meeting != null) { // Add the meeting to the database govBody.Meetings.Add(meeting); } dbOps.WriteChanges(); } //} }
public GovernmentBody Get(long governmentBodyId) { GovernmentBody govBody = dBOperations.GetGovernmentBody(governmentBodyId); return(govBody); }
public GovernmentBody Get(long governmentBodyId) { GovernmentBody location = GetTestMeeting(governmentBodyId); return(location); }
private GovernmentBody GetTestMeeting(long govBodyId) { GovernmentBody govBody = testGovBodies.Single(m => m.Id == govBodyId); return(govBody); }
public GovernmentBody Get(int govBodyId) { GovernmentBody ret = govBodies.Get(govBodyId); return(ret); }
public void Backend_DbAccess_CreateOneGovBodyAndMeetingTest() { // ARRANGE TopicDiscussion topicDiscussion1 = new TopicDiscussion() { Topic = new Topic() { Name = "Bill #124643", Categories = new List <Category>() { new Category() { Name = "Health" } } }, Sequence = 1, Talks = new List <Talk>() { new Talk() { Text = "I disagree.", Sequence = 1, Speaker = new Citizen() { Name = "Harry" } }, new Talk() { Text = "I agree.", Sequence = 1, Speaker = new Official() { Name = "Town Manager Sally" } } } }; TopicDiscussion topicDiscussion2 = new TopicDiscussion() { Topic = new Topic() { Name = "Bill #987698", Categories = new List <Category>() { new Category() { Name = "Defense" } } }, Sequence = 2, Talks = new List <Talk>() { new Talk() { Text = "I agree.", Sequence = 1, Speaker = new Citizen() { Name = "Mary" } }, new Talk() { Text = "I disagree.", Sequence = 2, Speaker = new Representative() { Name = "Assemblyman Pete" } } } }; GovernmentBody BodyWritten = new GovernmentBody() { Name = "U.S. Congress", Country = "U.S.A.", Meetings = new List <Meeting>() { new Meeting() { Name = "Regular Session Meeting", Date = DateTime.Parse("Nov 1, 1945 10:11 GMT"), TopicDiscussions = new List <TopicDiscussion>() { topicDiscussion1, topicDiscussion2 } } } }; // ACT using (var context = new ApplicationDbContext()) { //if (context.Database.Exists()) context.Database.Delete(); context.GovernmentBodies.Add(BodyWritten); context.SaveChanges(); } // ASSERT // Re-create the context. using (var context = new ApplicationDbContext()) { Assert.That(context.GovernmentBodies.Local.Count, Is.EqualTo(0)); // Re-load the context from the database. //context.GovernmentBodies.Load(); //context.Meetings.Load(); //context.TopicDiscussions.Load(); //context.Talks.Load(); //context.Topics.Load(); //context.Speakers.Load(); //context.Categories.Load(); var query = from g in context.GovernmentBodies select g; var BodyRetrieved = query.SingleOrDefault(); Assert.That(BodyRetrieved, Is.Not.Null); Assert.That(BodyRetrieved.Name, Is.EqualTo(BodyWritten.Name)); Assert.That(BodyRetrieved.Meetings[0], Is.Not.Null); // Check meeting object. Meeting meetingWritten = BodyWritten.Meetings[0]; Meeting meetingRetrieved = BodyRetrieved.Meetings[0]; Assert.That(meetingRetrieved.Name, Is.EqualTo(meetingWritten.Name)); Assert.That(meetingRetrieved.Date, Is.EqualTo(meetingWritten.Date)); Assert.That(meetingRetrieved.TopicDiscussions[0], Is.Not.Null); Assert.That(meetingRetrieved.TopicDiscussions.Count, Is.EqualTo(2)); for (int i = 0; i < 2; i++) { TopicDiscussion tdWritten = meetingWritten.TopicDiscussions[i]; TopicDiscussion tdRetrieved = meetingRetrieved.TopicDiscussions[i]; Assert.That(tdRetrieved.Sequence, Is.EqualTo(tdWritten.Sequence)); // Check topic. Assert.That(tdRetrieved.Topic, Is.Not.Null); Assert.That(tdRetrieved.Topic.Name, Is.EqualTo(tdWritten.Topic.Name)); // Check categories. Assert.That(tdRetrieved.Topic.Categories, Is.Not.Null); List <Category> cWritten = tdWritten.Topic.Categories; List <Category> cRetrieved = tdRetrieved.Topic.Categories; Assert.That(cRetrieved.Count, Is.EqualTo(1)); Assert.That(cRetrieved[0].Name, Is.EqualTo(cWritten[0].Name)); // Check talks and speakers Assert.That(tdRetrieved.Talks, Is.Not.Null); List <Talk> tkWritten = tdWritten.Talks; List <Talk> tkRetrieved = tdRetrieved.Talks; Assert.That(tkRetrieved.Count, Is.EqualTo(2)); // talk 0 Assert.That(tkRetrieved[0].Text, Is.EqualTo(tkWritten[0].Text)); Assert.That(tkRetrieved[0].Speaker, Is.Not.Null); Assert.That(tkRetrieved[0].Speaker.Name, Is.EqualTo(tkWritten[0].Speaker.Name)); // talk 1 Assert.That(tkRetrieved[1].Text, Is.EqualTo(tkWritten[1].Text)); Assert.That(tkRetrieved[1].Speaker, Is.Not.Null); Assert.That(tkRetrieved[1].Speaker.Name, Is.EqualTo(tkWritten[1].Speaker.Name)); } } }