public void TryGetFromBuffer_PrefersVisualStudioRazorParserIfRazorEditorParserIsAvailable() { // Arrange var properties = new PropertyCollection(); var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World"); var parser = new DefaultVisualStudioRazorParser(expectedCodeDocument); properties.AddProperty(typeof(VisualStudioRazorParser), parser); var unexpectedCodeDocument = TestRazorCodeDocument.Create("Unexpected"); var legacyParser = new RazorEditorParser(unexpectedCodeDocument); properties.AddProperty(typeof(RazorEditorParser), legacyParser); var textBuffer = new Mock <ITextBuffer>(); textBuffer.Setup(buffer => buffer.Properties) .Returns(properties); var provider = new LegacyTextBufferCodeDocumentProvider(); // Act var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument); // Assert Assert.True(result); Assert.Same(expectedCodeDocument, codeDocument); }
public void AddProperty(object key, object value) { if (_properties == null) { _properties = new PropertyCollection(); } _properties.AddProperty(key, value); }
public void TryGetPropertySafe_WrongType() { var col = new PropertyCollection(); var key = new object(); col.AddProperty(key, this); Assert.False(col.TryGetPropertySafe(key, out string value)); }
public void TryGetPropertySafe_WrongType() { var col = new PropertyCollection(); var key = new object(); col.AddProperty(key, this); string value; Assert.IsFalse(col.TryGetPropertySafe(key, out value)); }
private void TextBufferMockHelper(Mock <ITextBuffer> textBuffer, string script, Token[] tokens) { PropertyCollection pc = new PropertyCollection(); pc.AddProperty(BufferProperties.Tokens, tokens); textBuffer.Setup(m => m.Properties).Returns(pc); textBuffer.Setup(m => m.CurrentSnapshot.Length) .Returns(() => script.Length); }
public FakeTextBuffer(string text, string filePath) { _propertyCollection = new PropertyCollection(); if (!string.IsNullOrWhiteSpace(filePath)) { _propertyCollection.AddProperty(typeof(ITextDocument), new FakeTextDocument(filePath, this)); } _textSnapshot = new FakeTextSnapshot(this, text); }
public void TryGetPropertySafe_Found() { var col = new PropertyCollection(); var key = new object(); col.AddProperty(key, "target"); string value; Assert.IsTrue(col.TryGetPropertySafe(key, out value)); Assert.AreEqual("target", value); }
public void TryGetPropertySafe_Found() { var col = new PropertyCollection(); var key = new object(); col.AddProperty(key, "target"); Assert.True(col.TryGetPropertySafe(key, out string value)); Assert.Equal("target", value); }
IPeekSession CreatePeekSession() { var document = Substitute.For <ITextDocument>(); document.FilePath.Returns(FullPath); var propertyCollection = new PropertyCollection(); propertyCollection.AddProperty(typeof(ITextDocument), document); var result = Substitute.For <IPeekSession>(); result.TextView.TextBuffer.Properties.Returns(propertyCollection); return(result); }
public void GetOrCreate_CachesCompletionSource() { // Arrange var expectedParser = Mock.Of <VisualStudioRazorParser>(); var properties = new PropertyCollection(); properties.AddProperty(typeof(VisualStudioRazorParser), expectedParser); var textView = CreateTextView(RazorContentType, properties); var completionSourceProvider = new RazorDirectiveCompletionSourceProvider(Dispatcher, CompletionFactsService); // Act var completionSource1 = completionSourceProvider.GetOrCreate(textView); var completionSource2 = completionSourceProvider.GetOrCreate(textView); // Assert Assert.Same(completionSource1, completionSource2); }
public void CreateCompletionSource_ReturnsNullIfParserHasNotBeenAssocitedWithRazorBuffer() { // Arrange var expectedParser = Mock.Of <VisualStudioRazorParser>(); var properties = new PropertyCollection(); properties.AddProperty(typeof(VisualStudioRazorParser), expectedParser); var razorBuffer = Mock.Of <ITextBuffer>(buffer => buffer.ContentType == RazorContentType && buffer.Properties == properties); var completionSourceProvider = new RazorDirectiveCompletionSourceProvider(Dispatcher, CompletionFactsService); // Act var completionSource = completionSourceProvider.CreateCompletionSource(razorBuffer); // Assert var completionSourceImpl = Assert.IsType <RazorDirectiveCompletionSource>(completionSource); Assert.Same(expectedParser, completionSourceImpl._parser); }
public void Setup() { _bookmark = new Bookmark(BookmarkType.Local, number: 1, line: 12, column: 34); // line # must be less than # of lines in the snapshot _bookmarksServiceMock = new Mock <IBookmarksService>(); _bookmarksServiceMock.Setup(b => b.RegisterCallback(It.IsNotNull <IBookmarkCallbackClient>(), It.IsNotNull <string>())).Verifiable(); _bookmarksServiceMock.Setup(b => b.UnregisterCallback(It.IsNotNull <IBookmarkCallbackClient>())).Verifiable(); _bookmarksServiceMock.Setup(b => b.GetCallbackFileName(It.IsAny <IBookmarkCallbackClient>())).Returns("test").Verifiable(); _bookmarksServiceMock.Setup(b => b.UpdateBookmark("test", It.IsAny <int>(), It.IsAny <BookmarkType>())).Verifiable(); _bookmarksServiceMock.Setup(b => b.RemoveBookmark("test", It.IsAny <int>(), It.IsAny <BookmarkType>())).Verifiable(); _sharedServiceProviderMock = new Mock <ISharedServiceProvider>(); _sharedServiceProviderMock.Setup(s => s.GetService(typeof(IBookmarksService))).Returns(_bookmarksServiceMock.Object).Verifiable(); _sharedServiceProviderMock.Setup(s => s.GetService(typeof(ILog))).Returns(new Mock <ILog>().Object).Verifiable(); _textDocumentMock = new Mock <ITextDocument>(); _textDocumentMock.SetupGet(d => d.FilePath).Returns("test").Verifiable(); var properties = new PropertyCollection(); properties.AddProperty(typeof(ITextDocument), _textDocumentMock.Object); var snapshotMock = new Mock <ITextSnapshot>(); var lineSnapshotMock = new Mock <ITextSnapshotLine>(); var trackingSpanMock = new Mock <ITrackingSpan>(); snapshotMock.SetupGet(s => s.Length).Returns(100); snapshotMock.SetupGet(s => s.LineCount).Returns(20); lineSnapshotMock.SetupGet(l => l.LineNumber).Returns(_bookmark.Line - 1); // line is stored 0-based lineSnapshotMock.SetupGet(l => l.Start).Returns(new SnapshotPoint(snapshotMock.Object, 56)); snapshotMock.Setup(s => s.GetLineFromLineNumber(It.IsAny <int>())).Returns(lineSnapshotMock.Object); snapshotMock.Setup(s => s.GetLineFromPosition(It.IsAny <int>())).Returns(lineSnapshotMock.Object); snapshotMock.Setup(s => s.CreateTrackingSpan(It.IsAny <Span>(), It.IsAny <SpanTrackingMode>())).Returns(trackingSpanMock.Object); _textBufferMock = new Mock <ITextBuffer>(); _textBufferMock.SetupGet(b => b.Properties).Returns(properties).Verifiable(); _textBufferMock.SetupGet(b => b.CurrentSnapshot).Returns(snapshotMock.Object).Verifiable(); var point = new SnapshotPoint(_textBufferMock.Object.CurrentSnapshot, 56); trackingSpanMock.SetupGet(s => s.TextBuffer).Returns(_textBufferMock.Object).Verifiable(); trackingSpanMock.Setup(s => s.GetStartPoint(It.IsAny <ITextSnapshot>())).Returns(point).Verifiable(); }
private void InitProperties() { _properties.AddProperty(typeof(ITextDocument), new MockTextDocument(_filename)); }
private void InitProperties() { _classProvider.GetClassifier(this); _properties.AddProperty(typeof(ITextDocument), new MockTextDocument("C:\\foo.py")); }
public static void AddProperty <T>(this PropertyCollection collection, T property) { collection.AddProperty(property.GetType(), property); }
public static void AddTypedProperty <T>(this PropertyCollection col, T value) { col.AddProperty(typeof(T), value); }
public PROPERTY AddProperty <PROPERTY>(PropertyType type, PROPERTY prop) where PROPERTY : Property => _props.AddProperty(type, prop);
public Unit(string name) { _name = name; _props = new PropertyCollection(); _triggers = new TriggerCollection(); _skills = new Dictionary <string, Skill>(); _alive = _props.AddProperty(PropertyType.Alive, new BoolProperty("活着", true)); _props.AddProperty(PropertyType.Level, new IntProperty("等级", 1)); _props.AddProperty(PropertyType.Vitality, new ValueProperty("体力", 10)); _props.AddProperty(PropertyType.Strength, new ValueProperty("力量", 10)); _props.AddProperty(PropertyType.Intelligence, new ValueProperty("智力", 10)); _props.AddProperty(PropertyType.Agility, new ValueProperty("敏捷", 10)); // BattleProperties _health = _props.AddProperty(PropertyType.Health, new MaxValueProperty("生命", 100)); _props.AddProperty(PropertyType.PhysicAttack, new ValueProperty("物理攻击", 10, 1)); _props.AddProperty(PropertyType.MagicAttack, new ValueProperty("魔法攻击", 10, 1)); _props.AddProperty(PropertyType.PhysicDefense, new ValueProperty("物理防御", 0)); _props.AddProperty(PropertyType.MagicDefense, new ValueProperty("魔法防御", 0)); _props.AddProperty(PropertyType.Speed, new ValueProperty("速度", 100, max: 2000)); _props.AddProperty(PropertyType.CriticalRate, new ValueProperty("暴击率", 0.00f, max: 1.00f, format: "P0")); _props.AddProperty(PropertyType.CriticalDamage, new ValueProperty("暴击伤害", 1.50f, 1.00f, format: "P0")); _props.AddProperty(PropertyType.CooldownReduction, new ValueProperty("冷却时间降低", 0, -10.0f, 0.80f, format: "P0")); _props.AddProperty(PropertyType.BattleForce, new IntProperty("战斗势力", 0)); _props.AddProperty(PropertyType.BattleForceAllyMask, new IntProperty("战斗势力掩码", 0)); _props.AddProperty(PropertyType.BattleGroup, new IntProperty("战斗组", 0)); UpdateBattleProperties(); }