Skip to content

Commit

Permalink
- Change TemplateOutliningTaggerProvider to fail fast in the injectio…
Browse files Browse the repository at this point in the history
…n constructor.
  • Loading branch information
olegsych committed Jun 15, 2015
1 parent 8de75f6 commit 57df56c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ internal sealed class TemplateOutliningTaggerProvider : ITaggerProvider

public TemplateOutliningTaggerProvider(ITemplateEditorOptions options)
{
// TODO: throw ArgumentNullException
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

this.options = options;
}

public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
throw new ArgumentNullException(nameof(buffer));
}

if (this.options.TemplateOutliningEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace T4Toolbox.VisualStudio.Editor
{
using System;
using System.ComponentModel.Composition;
using System.Reflection;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
using NSubstitute;
Expand Down Expand Up @@ -52,6 +52,21 @@ public void TemplateOutliningTaggerProviderAppliesOnlyToTextTemplateContentType(
Assert.Equal(TemplateContentType.Name, contentType.ContentTypes);
}

[Fact]
public void ConstructorThrowsArgumentNullExceptionWhenOptionsIsNullToFailFast()
{
var e = Assert.Throws<ArgumentNullException>(() => new TemplateOutliningTaggerProvider(null));
Assert.Equal("options", e.ParamName);
}

[Fact]
public void CreateTaggerThrowsArgumentNullExceptionWhenBufferIsNullToFailFast()
{
var provider = new TemplateOutliningTaggerProvider(Substitute.For<ITemplateEditorOptions>());
var e = Assert.Throws<ArgumentNullException>(() => provider.CreateTagger<OutliningRegionTag>(null));
Assert.Equal("buffer", e.ParamName);
}

[Fact]
public void CreateTaggerReturnsTemplateOutliningTagger()
{
Expand Down

0 comments on commit 57df56c

Please sign in to comment.