24 changed files with 741 additions and 3 deletions
@ -0,0 +1,25 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Threading; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class FoldGenerationTimer : DispatcherTimer, IFoldGenerationTimer |
||||||
|
{ |
||||||
|
public static readonly TimeSpan TwoSecondInterval = new TimeSpan(0, 0, 2); |
||||||
|
public static readonly TimeSpan DefaultInterval = TwoSecondInterval; |
||||||
|
|
||||||
|
public FoldGenerationTimer() |
||||||
|
: base(DispatcherPriority.Background) |
||||||
|
{ |
||||||
|
Interval = DefaultInterval; |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
Stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class FoldGenerator : IFoldGenerator |
||||||
|
{ |
||||||
|
ITextEditorWithParseInformationFolding textEditor; |
||||||
|
IFoldParser foldParser; |
||||||
|
|
||||||
|
public FoldGenerator( |
||||||
|
ITextEditorWithParseInformationFolding textEditor, |
||||||
|
IFoldParser foldParser) |
||||||
|
{ |
||||||
|
this.textEditor = textEditor; |
||||||
|
this.foldParser = foldParser; |
||||||
|
IsParseInformationFoldingEnabled = false; |
||||||
|
} |
||||||
|
|
||||||
|
bool IsParseInformationFoldingEnabled { |
||||||
|
get { return textEditor.IsParseInformationFoldingEnabled; } |
||||||
|
set { textEditor.IsParseInformationFoldingEnabled = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
IsParseInformationFoldingEnabled = true; |
||||||
|
} |
||||||
|
|
||||||
|
public void GenerateFolds() |
||||||
|
{ |
||||||
|
try { |
||||||
|
textEditor.UpdateFolds(GetFolds()); |
||||||
|
} catch (Exception ex) { |
||||||
|
LoggingService.Debug(ex.ToString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<NewFolding> GetFolds() |
||||||
|
{ |
||||||
|
return foldParser.GetFolds(textEditor.GetTextSnapshot()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface IFoldGenerationTimer : IDisposable |
||||||
|
{ |
||||||
|
event EventHandler Tick; |
||||||
|
void Start(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface IFoldGenerator : IDisposable |
||||||
|
{ |
||||||
|
void GenerateFolds(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface IFoldParser |
||||||
|
{ |
||||||
|
IEnumerable<NewFolding> GetFolds(string text); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface ITextEditorWithParseInformationFolding |
||||||
|
{ |
||||||
|
bool IsParseInformationFoldingEnabled { get; set; } |
||||||
|
|
||||||
|
void UpdateFolds(IEnumerable<NewFolding> folds); |
||||||
|
string GetTextSnapshot(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface ITextEditorWithParseInformationFoldingFactory |
||||||
|
{ |
||||||
|
ITextEditorWithParseInformationFolding CreateTextEditor(ITextEditor textEditor); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public interface IWebFormsFoldGeneratorFactory |
||||||
|
{ |
||||||
|
IFoldGenerator CreateFoldGenerator(ITextEditorWithParseInformationFolding textEditor); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class ScheduledFoldGenerator : IFoldGenerator |
||||||
|
{ |
||||||
|
IFoldGenerator foldGenerator; |
||||||
|
IFoldGenerationTimer timer; |
||||||
|
|
||||||
|
public ScheduledFoldGenerator(IFoldGenerator foldGenerator) |
||||||
|
: this(foldGenerator, new FoldGenerationTimer()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public ScheduledFoldGenerator( |
||||||
|
IFoldGenerator foldGenerator, |
||||||
|
IFoldGenerationTimer timer) |
||||||
|
{ |
||||||
|
this.foldGenerator = foldGenerator; |
||||||
|
this.timer = timer; |
||||||
|
|
||||||
|
GenerateFolds(); |
||||||
|
timer.Tick += TimerElapsed; |
||||||
|
timer.Start(); |
||||||
|
} |
||||||
|
|
||||||
|
void TimerElapsed(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
GenerateFolds(); |
||||||
|
} |
||||||
|
|
||||||
|
public void GenerateFolds() |
||||||
|
{ |
||||||
|
foldGenerator.GenerateFolds(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
timer.Tick -= TimerElapsed; |
||||||
|
timer.Dispose(); |
||||||
|
foldGenerator.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,72 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.AvalonEdit; |
||||||
|
using ICSharpCode.AvalonEdit.AddIn; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class TextEditorWithParseInformationFolding : ITextEditorWithParseInformationFolding |
||||||
|
{ |
||||||
|
ITextEditor textEditor; |
||||||
|
CodeEditorView codeEditorView; |
||||||
|
FoldingManager foldingManager; |
||||||
|
|
||||||
|
public TextEditorWithParseInformationFolding(ITextEditor textEditor) |
||||||
|
{ |
||||||
|
this.textEditor = textEditor; |
||||||
|
InstallFoldingManager(); |
||||||
|
} |
||||||
|
|
||||||
|
void InstallFoldingManager() |
||||||
|
{ |
||||||
|
var textEditorAdapter = textEditor as AvalonEditTextEditorAdapter; |
||||||
|
if (textEditorAdapter != null) { |
||||||
|
foldingManager = FoldingManager.Install(textEditorAdapter.TextEditor.TextArea); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsParseInformationFoldingEnabled { |
||||||
|
get { |
||||||
|
if (CodeEditorView != null) { |
||||||
|
return !CodeEditorView.DisableParseInformationFolding; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
set { |
||||||
|
if (CodeEditorView != null) { |
||||||
|
CodeEditorView.DisableParseInformationFolding = !value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
CodeEditorView CodeEditorView { |
||||||
|
get { |
||||||
|
if (codeEditorView == null) { |
||||||
|
codeEditorView = GetCodeEditorView(); |
||||||
|
} |
||||||
|
return codeEditorView; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
CodeEditorView GetCodeEditorView() |
||||||
|
{ |
||||||
|
return textEditor.GetService(typeof(TextEditor)) as CodeEditorView; |
||||||
|
} |
||||||
|
|
||||||
|
public void UpdateFolds(IEnumerable<NewFolding> folds) |
||||||
|
{ |
||||||
|
foldingManager.UpdateFoldings(folds, -1); |
||||||
|
} |
||||||
|
|
||||||
|
public string GetTextSnapshot() |
||||||
|
{ |
||||||
|
return textEditor.Document.CreateSnapshot().Text; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class TextEditorWithParseInformationFoldingFactory : ITextEditorWithParseInformationFoldingFactory |
||||||
|
{ |
||||||
|
public ITextEditorWithParseInformationFolding CreateTextEditor(ITextEditor textEditor) |
||||||
|
{ |
||||||
|
return new TextEditorWithParseInformationFolding(textEditor); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class WebFormsFoldGeneratorFactory : IWebFormsFoldGeneratorFactory |
||||||
|
{ |
||||||
|
public IFoldGenerator CreateFoldGenerator(ITextEditorWithParseInformationFolding textEditor) |
||||||
|
{ |
||||||
|
return new ScheduledFoldGenerator( |
||||||
|
new FoldGenerator(textEditor, new WebFormsHtmlFoldParser())); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class WebFormsLanguageBinding : DefaultLanguageBinding |
||||||
|
{ |
||||||
|
ITextEditorWithParseInformationFoldingFactory textEditorFactory; |
||||||
|
IWebFormsFoldGeneratorFactory foldGeneratorFactory; |
||||||
|
IFoldGenerator foldGenerator; |
||||||
|
|
||||||
|
public WebFormsLanguageBinding() |
||||||
|
: this( |
||||||
|
new TextEditorWithParseInformationFoldingFactory(), |
||||||
|
new WebFormsFoldGeneratorFactory()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public WebFormsLanguageBinding( |
||||||
|
ITextEditorWithParseInformationFoldingFactory textEditorFactory, |
||||||
|
IWebFormsFoldGeneratorFactory foldGeneratorFactory) |
||||||
|
{ |
||||||
|
this.textEditorFactory = textEditorFactory; |
||||||
|
this.foldGeneratorFactory = foldGeneratorFactory; |
||||||
|
} |
||||||
|
|
||||||
|
public override IFormattingStrategy FormattingStrategy { |
||||||
|
get { return new DefaultFormattingStrategy(); } |
||||||
|
} |
||||||
|
|
||||||
|
public override LanguageProperties Properties { |
||||||
|
get { return LanguageProperties.None; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Attach(ITextEditor editor) |
||||||
|
{ |
||||||
|
Attach(textEditorFactory.CreateTextEditor(editor)); |
||||||
|
} |
||||||
|
|
||||||
|
void Attach(ITextEditorWithParseInformationFolding editor) |
||||||
|
{ |
||||||
|
foldGenerator = foldGeneratorFactory.CreateFoldGenerator(editor); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Detach() |
||||||
|
{ |
||||||
|
foldGenerator.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,111 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.AspNet.Mvc.Folding; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
using NUnit.Framework; |
||||||
|
using Rhino.Mocks; |
||||||
|
using Rhino.Mocks.Constraints; |
||||||
|
|
||||||
|
namespace AspNet.Mvc.Tests.Folding |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class FoldGeneratorTests |
||||||
|
{ |
||||||
|
FoldGenerator foldGenerator; |
||||||
|
ITextEditorWithParseInformationFolding fakeTextEditor; |
||||||
|
IFoldParser fakeFoldParser; |
||||||
|
|
||||||
|
void CreateFakeTextEditor() |
||||||
|
{ |
||||||
|
fakeTextEditor = MockRepository.GenerateStub<ITextEditorWithParseInformationFolding>(); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateFoldGenerator() |
||||||
|
{ |
||||||
|
fakeFoldParser = MockRepository.GenerateStub<IFoldParser>(); |
||||||
|
foldGenerator = new FoldGenerator(fakeTextEditor, fakeFoldParser); |
||||||
|
} |
||||||
|
|
||||||
|
void SetFoldsToReturnFromFoldParserForHtml(NewFolding[] expectedFolds, string html) |
||||||
|
{ |
||||||
|
fakeFoldParser.Stub(parser => parser.GetFolds(html)) |
||||||
|
.Return(expectedFolds); |
||||||
|
} |
||||||
|
|
||||||
|
void SetTextInTextEditor(string text) |
||||||
|
{ |
||||||
|
fakeTextEditor.Stub(textEditor => textEditor.GetTextSnapshot()) |
||||||
|
.Return(text); |
||||||
|
} |
||||||
|
|
||||||
|
void SetExceptionToThrowFromFoldParserGetFoldsMethod(Exception ex) |
||||||
|
{ |
||||||
|
fakeFoldParser.Stub(parser => parser.GetFolds(null)) |
||||||
|
.IgnoreArguments() |
||||||
|
.Throw(ex); |
||||||
|
} |
||||||
|
|
||||||
|
void AssertTextEditorUpdateFoldsWasNotCalled() |
||||||
|
{ |
||||||
|
fakeTextEditor.AssertWasNotCalled( |
||||||
|
textEditor => textEditor.UpdateFolds(null), |
||||||
|
textEditor => textEditor.IgnoreArguments()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Constructor_TextEditor_ParseInformationIsDisabled() |
||||||
|
{ |
||||||
|
CreateFakeTextEditor(); |
||||||
|
fakeTextEditor.IsParseInformationFoldingEnabled = true; |
||||||
|
CreateFoldGenerator(); |
||||||
|
|
||||||
|
Assert.IsFalse(fakeTextEditor.IsParseInformationFoldingEnabled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Detach_TextEditor_ParseInformationIsEnabled() |
||||||
|
{ |
||||||
|
CreateFakeTextEditor(); |
||||||
|
CreateFoldGenerator(); |
||||||
|
fakeTextEditor.IsParseInformationFoldingEnabled = false; |
||||||
|
|
||||||
|
foldGenerator.Dispose(); |
||||||
|
|
||||||
|
Assert.IsTrue(fakeTextEditor.IsParseInformationFoldingEnabled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateFolds_MethodCalled_FoldsFromFoldParserUsedToUpdateTextEditor() |
||||||
|
{ |
||||||
|
CreateFakeTextEditor(); |
||||||
|
CreateFoldGenerator(); |
||||||
|
string html = "<p></p>"; |
||||||
|
SetTextInTextEditor(html); |
||||||
|
var expectedFolds = new NewFolding[] { |
||||||
|
new NewFolding() |
||||||
|
}; |
||||||
|
SetFoldsToReturnFromFoldParserForHtml(expectedFolds, html); |
||||||
|
|
||||||
|
foldGenerator.GenerateFolds(); |
||||||
|
|
||||||
|
fakeTextEditor.AssertWasCalled(textEditor => textEditor.UpdateFolds(expectedFolds)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GenerateFolds_FoldParserThrowsException_FoldsNotUpdated() |
||||||
|
{ |
||||||
|
CreateFakeTextEditor(); |
||||||
|
CreateFoldGenerator(); |
||||||
|
string html = "<p></p>"; |
||||||
|
SetTextInTextEditor(html); |
||||||
|
var expectedException = new ApplicationException("Test"); |
||||||
|
SetExceptionToThrowFromFoldParserGetFoldsMethod(expectedException); |
||||||
|
|
||||||
|
foldGenerator.GenerateFolds(); |
||||||
|
|
||||||
|
AssertTextEditorUpdateFoldsWasNotCalled(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,96 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.AspNet.Mvc.Folding; |
||||||
|
using NUnit.Framework; |
||||||
|
using Rhino.Mocks; |
||||||
|
|
||||||
|
namespace AspNet.Mvc.Tests.Folding |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ScheduledFoldGeneratorTests |
||||||
|
{ |
||||||
|
IFoldGenerationTimer fakeTimer; |
||||||
|
ScheduledFoldGenerator scheduledFoldGenerator; |
||||||
|
IFoldGenerator fakeFoldGenerator; |
||||||
|
int foldsGeneratedCount; |
||||||
|
|
||||||
|
void CreateScheduledFoldGenerator() |
||||||
|
{ |
||||||
|
fakeTimer = MockRepository.GenerateStub<IFoldGenerationTimer>(); |
||||||
|
fakeFoldGenerator = MockRepository.GenerateStub<IFoldGenerator>(); |
||||||
|
scheduledFoldGenerator = new ScheduledFoldGenerator(fakeFoldGenerator, fakeTimer); |
||||||
|
} |
||||||
|
|
||||||
|
void RegisterFoldGenerationCounter() |
||||||
|
{ |
||||||
|
foldsGeneratedCount = 0; |
||||||
|
fakeFoldGenerator.Stub(generator => generator.GenerateFolds()) |
||||||
|
.WhenCalled(generator => foldsGeneratedCount++); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void FireTimer() |
||||||
|
{ |
||||||
|
fakeTimer.Raise(timer => timer.Tick += null, fakeTimer, new EventArgs()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Constructor_FoldGeneratorPassedToBeScheduled_FoldsUpdatedBeforeTimerFires() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
|
||||||
|
fakeFoldGenerator.AssertWasCalled(generator => generator.GenerateFolds()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Constructor_FoldGeneratorPassedToBeScheduled_FoldGenerationTimerIsStarted() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
|
||||||
|
fakeTimer.AssertWasCalled(timer => timer.Start()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Dispose_FoldGeneratorPassedToBeScheduled_WrappedFoldGeneratorIsDisposed() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
scheduledFoldGenerator.Dispose(); |
||||||
|
|
||||||
|
fakeFoldGenerator.AssertWasCalled(generator => generator.Dispose()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Dispose_FoldGeneratorPassedToBeScheduled_FoldGenerationTimerIsDisposed() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
scheduledFoldGenerator.Dispose(); |
||||||
|
|
||||||
|
fakeTimer.AssertWasCalled(timer => timer.Dispose()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Constructor_TimerFires_FoldsAreUpdated() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
RegisterFoldGenerationCounter(); |
||||||
|
|
||||||
|
FireTimer(); |
||||||
|
|
||||||
|
Assert.AreEqual(1, foldsGeneratedCount); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Dispose_TimerFiresAfterDisposed_FoldsAreNotUpdated() |
||||||
|
{ |
||||||
|
CreateScheduledFoldGenerator(); |
||||||
|
RegisterFoldGenerationCounter(); |
||||||
|
scheduledFoldGenerator.Dispose(); |
||||||
|
|
||||||
|
FireTimer(); |
||||||
|
|
||||||
|
Assert.AreEqual(0, foldsGeneratedCount); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,91 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.AspNet.Mvc.Folding; |
||||||
|
using ICSharpCode.AvalonEdit.AddIn; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using NUnit.Framework; |
||||||
|
using Rhino.Mocks; |
||||||
|
|
||||||
|
namespace AspNet.Mvc.Tests.Folding |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class WebFormsLanguageBindingTests |
||||||
|
{ |
||||||
|
ITextEditorWithParseInformationFolding fakeTextEditorWithParseInformationFolding; |
||||||
|
WebFormsLanguageBinding languageBinding; |
||||||
|
ITextEditor fakeTextEditor; |
||||||
|
ITextEditorWithParseInformationFoldingFactory fakeTextEditorFactory; |
||||||
|
IWebFormsFoldGeneratorFactory fakeFoldGeneratorFactory; |
||||||
|
IFoldGenerator fakeFoldGenerator; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
CreateFakeTextEditor(); |
||||||
|
CreateFakeTextEditorWithParseInfo(); |
||||||
|
CreateFakeTextEditorWithParseInfoFoldingFactory(); |
||||||
|
AddFakeTextEditorWithParseInfoFoldingToFactory(); |
||||||
|
CreateFakeFoldGeneratorFactory(); |
||||||
|
AddFakeFoldGeneratorToFactory(); |
||||||
|
CreateLanguageBinding(); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateLanguageBinding() |
||||||
|
{ |
||||||
|
languageBinding = new WebFormsLanguageBinding(fakeTextEditorFactory, fakeFoldGeneratorFactory); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateFakeFoldGeneratorFactory() |
||||||
|
{ |
||||||
|
fakeFoldGeneratorFactory = MockRepository.GenerateStub<IWebFormsFoldGeneratorFactory>(); |
||||||
|
} |
||||||
|
|
||||||
|
void AddFakeFoldGeneratorToFactory() |
||||||
|
{ |
||||||
|
fakeFoldGenerator = MockRepository.GenerateStub<IFoldGenerator>(); |
||||||
|
fakeFoldGeneratorFactory.Stub(factory => factory.CreateFoldGenerator(fakeTextEditorWithParseInformationFolding)) |
||||||
|
.Return(fakeFoldGenerator); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateFakeTextEditorWithParseInfo() |
||||||
|
{ |
||||||
|
fakeTextEditorWithParseInformationFolding = MockRepository.GenerateStub<ITextEditorWithParseInformationFolding>(); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateFakeTextEditor() |
||||||
|
{ |
||||||
|
fakeTextEditor = MockRepository.GenerateStub<ITextEditor>(); |
||||||
|
} |
||||||
|
|
||||||
|
void CreateFakeTextEditorWithParseInfoFoldingFactory() |
||||||
|
{ |
||||||
|
fakeTextEditorFactory = MockRepository.GenerateStub<ITextEditorWithParseInformationFoldingFactory>(); |
||||||
|
} |
||||||
|
|
||||||
|
void AddFakeTextEditorWithParseInfoFoldingToFactory() |
||||||
|
{ |
||||||
|
fakeTextEditorFactory.Stub(factory => factory.CreateTextEditor(fakeTextEditor)) |
||||||
|
.Return(fakeTextEditorWithParseInformationFolding); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Attach_TextEditor_FoldGeneratorCreated() |
||||||
|
{ |
||||||
|
languageBinding.Attach(fakeTextEditor); |
||||||
|
|
||||||
|
fakeFoldGeneratorFactory.AssertWasCalled( |
||||||
|
factory => factory.CreateFoldGenerator(fakeTextEditorWithParseInformationFolding)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Detach_TextEditor_FoldGeneratorDisposed() |
||||||
|
{ |
||||||
|
languageBinding.Attach(fakeTextEditor); |
||||||
|
languageBinding.Detach(); |
||||||
|
|
||||||
|
fakeFoldGenerator.AssertWasCalled(generator => generator.Dispose()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Binary file not shown.
@ -0,0 +1,25 @@ |
|||||||
|
Copyright (c) 2005 - 2009 Ayende Rahien (ayende@ayende.com) |
||||||
|
All rights reserved. |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, |
||||||
|
are permitted provided that the following conditions are met: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
|
this list of conditions and the following disclaimer in the documentation |
||||||
|
and/or other materials provided with the distribution. |
||||||
|
* Neither the name of Ayende Rahien nor the names of its |
||||||
|
contributors may be used to endorse or promote products derived from this |
||||||
|
software without specific prior written permission. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
Loading…
Reference in new issue