public void ErrorListTableDataSource_AddEntriesVerifyEntryExists()
        {
            // Arrange
            var errorList    = Mock.Of <IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            var entry = new ErrorListTableEntry("test", Common.LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            // Assert
            Assert.Equal(entry, source.GetEntries().Single());
        }
        public void CanSetValue_AlwaysReturnsFalse(string key)
        {
            // Arrange & Act
            var entry = new ErrorListTableEntry(_testMessage, LogLevel.Debug);

            // Assert
            entry.Should().NotBeNull();
            entry.CanSetValue(key).Should().BeFalse();
        }
        public void ErrorListTableDataSource_SubscribeDisposeAndVerifyResult()
        {
            // Arrange
            var errorList    = Mock.Of <IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();
            var sink         = Mock.Of <ITableDataSink>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));


            var removeCalled = new HashSet <ITableDataSink>();
            var addCalled    = new HashSet <ITableDataSink>();

            Mock.Get(sink)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink));

            Mock.Get(sink)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            var subscription = source.Subscribe(sink);

            var entry = new ErrorListTableEntry("test", Common.LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            source.ClearNuGetEntries();

            // Assert no errors.
            subscription.Dispose();

            // Assert
            Assert.Contains(sink, addCalled);
            Assert.Contains(sink, removeCalled);
        }
        public void StringConstructor_CreatesLogMessage()
        {
            // Arrange & Act
            var entry = new ErrorListTableEntry(_testMessage, LogLevel.Debug);

            // Assert
            entry.Should().NotBeNull();
            entry.Message.Should().NotBeNull();
            entry.Message.Message.Should().Be(_testMessage);
            entry.Message.Code.Should().Be(NuGetLogCode.Undefined);
            entry.Message.Level.Should().Be(LogLevel.Debug);
        }
        public void LogMessageConstructor_KeepsLogMessage()
        {
            // Arrange
            var logMessage = new LogMessage(LogLevel.Debug, _testMessage, _testCode);

            // Act
            var entry = new ErrorListTableEntry(logMessage);

            // Assert
            entry.Should().NotBeNull();
            entry.Message.Should().Be(logMessage);
        }
        public void TryGetValue_IntContentNotAvailable_ReturnsZero(string key)
        {
            // Arrange
            var logMessage = new LogMessage(LogLevel.Error, _testMessage, _testCode);

            // Act
            var entry = new ErrorListTableEntry(logMessage);

            // Assert
            entry.Should().NotBeNull();
            entry.TryGetValue(key, out var result).Should().BeFalse();
            result.Should().BeNull();
        }
        public void TryGetValue_StringContent_ReturnsValues(string key, string content)
        {
            // Arrange
            var logMessage = new RestoreLogMessage(LogLevel.Error, _testCode, _testMessage)
            {
                ProjectPath = _testProjectPath
            };

            // Act
            var entry = new ErrorListTableEntry(logMessage);

            // Assert
            entry.Should().NotBeNull();
            entry.TryGetValue(key, out var result).Should().BeTrue();
            (result is string).Should().BeTrue();
            (result as string).Should().Be(content);
        }
        public void TryGetValue_IntContent_ReturnsValues(string key, int content)
        {
            // Arrange
            var logMessage = new RestoreLogMessage(LogLevel.Error, _testCode, _testMessage)
            {
                StartLineNumber   = _testLineNumber,
                StartColumnNumber = _testColumnNumber
            };

            // Act
            var entry = new ErrorListTableEntry(logMessage);

            // Assert
            entry.Should().NotBeNull();
            entry.TryGetValue(key, out var result).Should().BeTrue();
            (result is int).Should().BeTrue();
            ((int)result).Should().Be(content);
        }
예제 #9
0
        public void ErrorListTableDataSource_AddMultipleEntriesVerifyEntriesExists()
        {
            // Arrange
            var errorList    = Mock.Of <Microsoft.VisualStudio.Shell.IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            var entry = new ErrorListTableEntry("test", LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            var entry2 = new ErrorListTableEntry("test2", LogLevel.Minimal);

            source.AddNuGetEntries(entry2);

            // Assert
            Assert.Equal(2, source.GetEntries().Length);
            Assert.Equal(entry, source.GetEntries().First());
            Assert.Equal(entry2, source.GetEntries().Skip(1).First());
        }
예제 #10
0
        public void ReportError(ILogMessage message)
        {
            var errorListEntry = new ErrorListTableEntry(message);

            RunTaskOnUI(() => ErrorListTableDataSource.Value.AddNuGetEntries(errorListEntry));
        }
예제 #11
0
        public void ReportError(string message)
        {
            var errorListEntry = new ErrorListTableEntry(message, LogLevel.Error);

            RunTaskOnUI(() => ErrorListTableDataSource.Value.AddNuGetEntries(errorListEntry));
        }
        public void ErrorListTableDataSource_VerifyExistingEntriesAreAddedToNewSinks()
        {
            // Arrange
            var errorList    = Mock.Of <IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();
            var sink         = Mock.Of <ITableDataSink>();
            var sink2        = Mock.Of <ITableDataSink>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));

            var removeCalled = new HashSet <ITableDataSink>();
            var addCalled    = new HashSet <ITableDataSink>();

            Mock.Get(sink)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink));

            Mock.Get(sink)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink));

            Mock.Get(sink2)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink2));

            Mock.Get(sink2)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink2));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            var s1 = source.Subscribe(sink);

            var entry = new ErrorListTableEntry("test", Common.LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            var s2 = source.Subscribe(sink2);

            // Assert
            Assert.Contains(sink, addCalled);
            Assert.Contains(sink2, addCalled);
        }
        public void ErrorListTableDataSource_WithAllDisposedSinksVerifyNoCalls()
        {
            // Arrange
            var errorList    = Mock.Of <IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();
            var sink         = Mock.Of <ITableDataSink>();
            var sink2        = Mock.Of <ITableDataSink>();
            var sink3        = Mock.Of <ITableDataSink>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));

            var removeCalled = new HashSet <ITableDataSink>();
            var addCalled    = new HashSet <ITableDataSink>();

            Mock.Get(sink)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink));

            Mock.Get(sink)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink));

            Mock.Get(sink2)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink2));

            Mock.Get(sink2)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink2));

            Mock.Get(sink3)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() =>
            {
                addCalled.Add(sink3);
            });

            Mock.Get(sink3)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink3));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            var s1 = source.Subscribe(sink);
            var s2 = source.Subscribe(sink2);
            var s3 = source.Subscribe(sink3);

            s1.Dispose();
            s2.Dispose();
            s3.Dispose();

            var entry = new ErrorListTableEntry("test", Common.LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            source.ClearNuGetEntries();

            // Assert
            Assert.DoesNotContain(sink, addCalled);
            Assert.DoesNotContain(sink2, addCalled);
            Assert.DoesNotContain(sink3, addCalled);

            Assert.DoesNotContain(sink, removeCalled);
            Assert.DoesNotContain(sink2, removeCalled);
            Assert.DoesNotContain(sink3, removeCalled);
        }
예제 #14
0
        public void ErrorListTableDataSource_AddWithNoSinksVerifyAllAddedToNextSink()
        {
            // Arrange
            var errorList    = Mock.Of <Microsoft.VisualStudio.Shell.IErrorList>();
            var tableControl = Mock.Of <IWpfTableControl>();
            var tableManager = Mock.Of <ITableManager>();
            var sink         = Mock.Of <ITableDataSink>();
            var sink2        = Mock.Of <ITableDataSink>();

            Mock.Get(errorList)
            .Setup(x => x.TableControl)
            .Returns(tableControl);

            Mock.Get(tableControl)
            .Setup(x => x.SubscribeToDataSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.AddSource(
                       It.IsAny <ITableDataSource>()));

            Mock.Get(tableManager)
            .Setup(x => x.RemoveSource(
                       It.IsAny <ITableDataSource>()));

            var removeCalled = new HashSet <ITableDataSink>();
            var addCalled    = new HashSet <ITableDataSink>();

            Mock.Get(sink)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink));

            Mock.Get(sink)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink));

            Mock.Get(sink2)
            .Setup(x => x.AddEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >(),
                       It.IsAny <bool>()))
            .Callback(() => addCalled.Add(sink2));

            Mock.Get(sink2)
            .Setup(x => x.RemoveEntries(
                       It.IsAny <IReadOnlyList <ITableEntry> >()))
            .Callback(() => removeCalled.Add(sink2));

            var source = new ErrorListTableDataSource(errorList, tableManager);

            // Act
            source.ClearNuGetEntries();

            var entry = new ErrorListTableEntry("test", LogLevel.Minimal);

            source.AddNuGetEntries(entry);

            var s1 = source.Subscribe(sink);
            var s2 = source.Subscribe(sink2);

            // Assert
            Assert.Contains(sink, addCalled);
            Assert.Contains(sink2, addCalled);
        }