Exemplo n.º 1
0
        public void GetGroups_OnError_LogError()
        {
            // Arrange
            ShimDirectoryEntry.ConstructorString = (_, __) =>
            {
                throw new Exception(DummyError);
            };
            ShimDirectorySearcher.ConstructorDirectoryEntry = (_, __) =>
            {
                throw new Exception(DummyError);
            };
            ShimSearchResult.AllInstances.GetDirectoryEntry = _ =>
            {
                throw new Exception(DummyError);
            };

            // Act
            var result = _testObj.GetGroups(DummyString);

            // Assert
            var executionLogs = (List <string>)_privateObj.GetFieldOrProperty(ExecutionLogsProperty);

            this.ShouldSatisfyAllConditions(
                () => result.Count.ShouldBe(0),
                () => executionLogs.ShouldContain($"     WARNING -- Location: GetGroups() -- Path:{DummyString} -- Message:{DummyError}"));
        }
        public void GetGroups_Called_DirectoryDisposed()
        {
            // Arrange
            var directoryShims = DirectoryShims.ShimDirectoryCalls();

            directoryShims.DirectoryEntryShim.NameGet = () => SampleName;

            // Act
            var result = _adSync.GetGroups(string.Empty);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SampleName, result[0]);
            Assert.IsTrue(directoryShims.DirectorySearchersDisposed.Any());
            Assert.IsTrue(directoryShims.DirectoryEntriesDisposed.Any());
        }