public void ServiceIntegrationTest() { var test = CreateTestObject(); var xmlResult = new BuildDocument().ReturnDocumentXML(test); var response = new MoEcfServiceRepo().SendRequest(xmlResult); Assert.IsTrue(response.MoExchangeStructuredDataPayload.MoExchangeStructuredData.Contains("RECEIVED")); }
/// <summary> /// Sets the delegate used for converting a <see cref="DumpedDocument" /> to an instance of a class implementing <see cref="IDocument" />, /// while reading index data from a permanent storage. /// </summary> /// <param name="buildDocument">The delegate (cannot be <c>null</c>).</param> /// <remarks>This method must be called before invoking <see cref="InitializeData" />.</remarks> /// <exception cref="ArgumentNullException">If <paramref name="buildDocument"/> is <c>null</c>.</exception> public void SetBuildDocumentDelegate(BuildDocument buildDocument) { if (buildDocument == null) { throw new ArgumentNullException("buildDocument"); } lock (this) { this.buildDocument = buildDocument; } }
public void BuildDocument() { var test = CreateTestObject(); var xmlResult = new BuildDocument().ReturnDocumentXML(test); var expected = File.ReadAllText("ExampleFile.XML"); var myDiff = DiffBuilder.Compare(expected).WithTest(xmlResult) //.WithDifferenceEvaluator(new IgnoreAttributeDifferenceEvaluator("attr").Evaluate) .CheckForSimilar() .Build(); Assert.IsFalse(myDiff.HasDifferences(), myDiff.ToString()); }
public void LoadIndexAndModifications() { IInMemoryIndex index = MockInMemoryIndex(); IDocument doc1 = MockDocument("doc1", "Document", "doc", DateTime.Now); IDocument doc2 = MockDocument2("doc2", "Article", "doc", DateTime.Now); BuildDocument buildDoc = new BuildDocument(delegate(DumpedDocument d) { return(d.Name == doc1.Name ? doc1 : doc2); }); index.SetBuildDocumentDelegate(buildDoc); IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); index.StoreDocument(doc1, null, "", null); index.StoreDocument(doc2, null, "", null); Assert.AreEqual(2, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(12, index.TotalWords, "Wrong word count"); Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count"); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(2, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(12, index.TotalWords, "Wrong word count"); Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count"); SearchResultCollection res = index.Search(new SearchParameters("document content article")); Assert.AreEqual(2, res.Count, "Wrong result count"); Assert.AreEqual(2, res[0].Matches.Count, "Wrong matches count"); Assert.AreEqual(1, res[1].Matches.Count, "Wrong matches count"); Assert.AreEqual("document", res[0].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location"); Assert.AreEqual("content", res[0].Matches[1].Text, "Wrong match text"); Assert.AreEqual(13, res[0].Matches[1].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(3, res[0].Matches[1].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Content, res[0].Matches[1].Location, "Wrong match location"); Assert.AreEqual("article", res[1].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[1].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[1].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[1].Matches[0].Location, "Wrong match location"); index.RemoveDocument(doc1, null); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(1, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(7, index.TotalWords, "Wrong word count"); Assert.AreEqual(7, index.TotalOccurrences, "Wrong occurrence count"); res = index.Search(new SearchParameters("document content article")); Assert.AreEqual(1, res.Count, "Wrong result count"); Assert.AreEqual(1, res[0].Matches.Count, "Wrong matches count"); Assert.AreEqual("article", res[0].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location"); index.Clear(null); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(0, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(0, index.TotalWords, "Wrong word count"); Assert.AreEqual(0, index.TotalOccurrences, "Wrong occurrence count"); Assert.AreEqual(0, index.Search(new SearchParameters("document")).Count, "Wrong result count"); }
/// <summary> /// Sets the delegate used for converting a <see cref="DumpedDocument" /> to an instance of a class implementing <see cref="IDocument" />, /// while reading index data from a permanent storage. /// </summary> /// <param name="buildDocument">The delegate (cannot be <c>null</c>).</param> /// <remarks>This method must be called before invoking <see cref="InitializeData" />.</remarks> /// <exception cref="ArgumentNullException">If <paramref name="buildDocument"/> is <c>null</c>.</exception> public void SetBuildDocumentDelegate(BuildDocument buildDocument) { if(buildDocument == null) throw new ArgumentNullException("buildDocument"); lock(this) { this.buildDocument = buildDocument; } }
public void LoadIndexAndModifications() { IInMemoryIndex index = MockInMemoryIndex(); IDocument doc1 = MockDocument("doc1", "Document", "doc", DateTime.Now); IDocument doc2 = MockDocument2("doc2", "Article", "doc", DateTime.Now); BuildDocument buildDoc = new BuildDocument(delegate(DumpedDocument d) { return d.Name == doc1.Name ? doc1 : doc2; }); index.SetBuildDocumentDelegate(buildDoc); IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); index.StoreDocument(doc1, null, "", null); index.StoreDocument(doc2, null, "", null); Assert.AreEqual(2, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(12, index.TotalWords, "Wrong word count"); Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count"); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(2, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(12, index.TotalWords, "Wrong word count"); Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count"); SearchResultCollection res = index.Search(new SearchParameters("document content article")); Assert.AreEqual(2, res.Count, "Wrong result count"); Assert.AreEqual(2, res[0].Matches.Count, "Wrong matches count"); Assert.AreEqual(1, res[1].Matches.Count, "Wrong matches count"); Assert.AreEqual("document", res[0].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location"); Assert.AreEqual("content", res[0].Matches[1].Text, "Wrong match text"); Assert.AreEqual(13, res[0].Matches[1].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(3, res[0].Matches[1].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Content, res[0].Matches[1].Location, "Wrong match location"); Assert.AreEqual("article", res[1].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[1].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[1].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[1].Matches[0].Location, "Wrong match location"); index.RemoveDocument(doc1, null); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(1, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(7, index.TotalWords, "Wrong word count"); Assert.AreEqual(7, index.TotalOccurrences, "Wrong occurrence count"); res = index.Search(new SearchParameters("document content article")); Assert.AreEqual(1, res.Count, "Wrong result count"); Assert.AreEqual(1, res[0].Matches.Count, "Wrong matches count"); Assert.AreEqual("article", res[0].Matches[0].Text, "Wrong match text"); Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index"); Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index"); Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location"); index.Clear(null); storer.Dispose(); storer = null; index = MockInMemoryIndex(); index.SetBuildDocumentDelegate(buildDoc); storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index); storer.LoadIndex(); Assert.AreEqual(0, index.TotalDocuments, "Wrong document count"); Assert.AreEqual(0, index.TotalWords, "Wrong word count"); Assert.AreEqual(0, index.TotalOccurrences, "Wrong occurrence count"); Assert.AreEqual(0, index.Search(new SearchParameters("document")).Count, "Wrong result count"); }
public ActionResult Diff(int id, int fileToDiff = -1, string direction = "next") { BuildEvent original = Db.BuildEvents.Where(b => b.EventLogId == id).FirstOrDefault(); BuildEvent next = null; ExceptionEvent originalEx = null; //Even though we were passed a specific event log id in our parameter list, we really only //want to show "interesting" items. We consider a build event to be interesting if // a) it has a build exception // b) it happened after a runtime exception if (direction == "next") { //check for exception events originalEx = (from ex in Db.ExceptionEvents where ex.EventLogId >= id && ex.EventLog.SenderId == original.EventLog.SenderId && ex.SolutionName.CompareTo(original.SolutionName) == 0 orderby ex.EventLogId ascending select ex) .Take(1) .FirstOrDefault(); //check for build events original = (from build in Db.BuildEvents where build.EventLogId >= id && build.ErrorItems.Count > 0 && original.EventLog.SenderId == original.EventLog.SenderId && original.SolutionName.CompareTo(original.SolutionName) == 0 orderby build.Id ascending select build) .Take(1) .FirstOrDefault(); //compare event log Ids between build and exception events. Take whichever is earlier if (originalEx != null) { if (original != null) { //we need to take care of the exception if (originalEx.EventLogId < original.EventLogId) { original = (from build in Db.BuildEvents where build.EventLogId >= originalEx.EventLogId && build.ErrorItems.Count > 0 && original.EventLog.SenderId == original.EventLog.SenderId && original.SolutionName.CompareTo(original.SolutionName) == 0 orderby build.Id ascending select build) .Take(1) .FirstOrDefault(); } else { //build event came first originalEx = null; } } } //set up next if we can if (original != null) { next = GetNextEvent(original.EventLogId); } } else { //check for exception events originalEx = (from ex in Db.ExceptionEvents where ex.EventLogId <= id && ex.EventLog.SenderId == original.EventLog.SenderId && ex.SolutionName.CompareTo(original.SolutionName) == 0 orderby ex.EventLogId descending select ex) .Take(1) .FirstOrDefault(); //user is wanting to go to the previous build original = (from build in Db.BuildEvents where build.EventLogId <= id && build.ErrorItems.Count > 0 && original.EventLog.SenderId == original.EventLog.SenderId && original.SolutionName.CompareTo(original.SolutionName) == 0 orderby build.Id descending select build) .Take(1) .FirstOrDefault(); //compare event log Ids between build and exception events. Take whichever is earlier if (originalEx != null) { if (original != null) { //we need to take care of the exception if (originalEx.EventLogId > original.EventLogId) { original = (from build in Db.BuildEvents where build.EventLogId >= originalEx.EventLogId && build.ErrorItems.Count > 0 && original.EventLog.SenderId == original.EventLog.SenderId && original.SolutionName.CompareTo(original.SolutionName) == 0 orderby build.Id ascending select build) .Take(1) .FirstOrDefault(); } else { //build event came first originalEx = null; } } } if (original != null) { next = GetNextEvent(original.EventLogId); } } //just in case we messed up in the previous if/else block if (original == null) { original = Db.BuildEvents.Where(b => b.EventLogId == id).FirstOrDefault(); next = GetNextEvent(original.EventLogId); } //if next endedu up being NULL if (next == null) { next = new BuildEvent(); next.EventLogId = -1; next.Id = -1; next.EventLog = new EventLog(); next.EventLog.DateReceived = original.EventLog.DateReceived; } //sanity check before we begin processing if (original == null) { return(RedirectToAction("Index", "Home")); } ViewBag.PreviousLogId = GetPreviousDiffId(original.EventLogId); ViewBag.OriginalLog = original; ViewBag.NextLog = next; //build our view model BuildDiffViewModel vm = BuildViewModel(original, next, originalEx); //check for a requested file name. If none exists, set to the first file listed (alphabetically) if (fileToDiff > 0) { BuildDocument activeDoc = original.Documents.Where(d => d.DocumentId == fileToDiff).FirstOrDefault(); if (activeDoc != null) { vm.ActiveFileId = fileToDiff; } } //no file was specified, try something else if (vm.ActiveFileId == 0) { //start with null document vm.ActiveFileId = -1; //and try to find a document that has errors List <string> documentErrors = original.CriticalErrorItems.Select(e => e.ErrorListItem.File).ToList(); if (originalEx != null) { documentErrors.Add(originalEx.DocumentName); } foreach (string error in documentErrors) { string errorFileName = Path.GetFileName(error).ToLower(); foreach (BuildDocument doc in original.Documents) { string docFileName = Path.GetFileName(doc.Document.FileName); if (errorFileName.CompareTo(docFileName) == 0) { vm.ActiveFileId = doc.DocumentId; break; } } } if (vm.ActiveFileId == -1) { if (original.Documents.Count > 0) { vm.ActiveFileId = original.Documents.FirstOrDefault().DocumentId; } } } return(View(vm)); }
public override void OnBuildDone(vsBuildScope Scope, vsBuildAction Action) { base.OnBuildDone(Scope, Action); //this might take a while, so throw it in its own thread //System.Threading.Tasks.Task.Factory.StartNew( // () => // { BuildEvent build = new BuildEvent(); List <string> filesWithErrors = new List <string>(); build.SolutionName = dte.Solution.FullName; build.EventDate = DateTime.UtcNow; //start at 1 when iterating through Error List for (int i = 1; i <= dte.ToolWindows.ErrorList.ErrorItems.Count; i++) { ErrorItem item = dte.ToolWindows.ErrorList.ErrorItems.Item(i); BuildEventErrorListItem beli = new BuildEventErrorListItem(); beli.BuildEvent = build; beli.ErrorListItem = ErrorListItem.FromErrorItem(item); //only worry about critical errors if (beli.ErrorListItem.CriticalErrorName.Length > 0) { build.ErrorItems.Add(beli); //add the file with the error to our list of items that have errors if (filesWithErrors.Contains(beli.ErrorListItem.File.ToLower()) == false) { filesWithErrors.Add(beli.ErrorListItem.File.ToLower()); } } } //add in breakpoint information for (int i = 1; i <= dte.Debugger.Breakpoints.Count; i++) { BreakPoint bp = new BreakPoint(dte.Debugger.Breakpoints.Item(i)); BuildEventBreakPoint bebp = new BuildEventBreakPoint(); bebp.BreakPoint = bp; bebp.BuildEvent = build; build.Breakpoints.Add(bebp); } //get all files in the solution List <CodeDocument> files = build.GetSolutionFiles(dte.Solution); //add in associated documents foreach (CodeDocument file in files) { BuildDocument bd = new BuildDocument(); bd.Build = build; bd.Document = file; build.Documents.Add(bd); } byte[] data = EventFactory.ToZippedBinary(build); //let others know that we have created a new event NotifyEventCreated(this, new EventCreatedArgs(build)); //} //); }