mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-26 02:38:15 +02:00
SMBLibrary.Tests: Added NTFileStoreTests, NTDirectoryFileSystemTests
This commit is contained in:
parent
ea3e2c1974
commit
187135c412
4 changed files with 91 additions and 0 deletions
27
SMBLibrary.Tests/NTFileStore/NTDirectoryFileSystemTests.cs
Normal file
27
SMBLibrary.Tests/NTFileStore/NTDirectoryFileSystemTests.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SMBLibrary;
|
||||
using SMBLibrary.Win32;
|
||||
|
||||
namespace SMBLibrary.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class NTDirectoryFileSystemTests : NTFileStoreTests
|
||||
{
|
||||
private static readonly string TestDirectoryPath = @"C:\Tests";
|
||||
|
||||
static NTDirectoryFileSystemTests()
|
||||
{
|
||||
if (!Directory.Exists(TestDirectoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(TestDirectoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
public NTDirectoryFileSystemTests() : base(new NTDirectoryFileSystem(TestDirectoryPath))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
60
SMBLibrary.Tests/NTFileStore/NTFileStoreTests.cs
Normal file
60
SMBLibrary.Tests/NTFileStore/NTFileStoreTests.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SMBLibrary;
|
||||
using SMBLibrary.Win32;
|
||||
|
||||
namespace SMBLibrary.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public abstract class NTFileStoreTests
|
||||
{
|
||||
private INTFileStore m_fileStore;
|
||||
private readonly string TestDirName = "Dir";
|
||||
|
||||
private NTStatus? m_notifyChangeStatus;
|
||||
|
||||
public NTFileStoreTests(INTFileStore fileStore)
|
||||
{
|
||||
m_fileStore = fileStore;
|
||||
|
||||
object handle;
|
||||
FileStatus fileStatus;
|
||||
NTStatus status = m_fileStore.CreateFile(out handle, out fileStatus, TestDirName, AccessMask.GENERIC_ALL, FileAttributes.Directory, ShareAccess.Read, CreateDisposition.FILE_OPEN_IF, CreateOptions.FILE_DIRECTORY_FILE, null);
|
||||
Assert.IsTrue(status == NTStatus.STATUS_SUCCESS);
|
||||
status = m_fileStore.CloseFile(handle);
|
||||
Assert.IsTrue(status == NTStatus.STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestCancel()
|
||||
{
|
||||
object handle;
|
||||
FileStatus fileStatus;
|
||||
m_fileStore.CreateFile(out handle, out fileStatus, TestDirName, AccessMask.GENERIC_ALL, FileAttributes.Directory, ShareAccess.Read, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
|
||||
|
||||
object ioRequest = null;
|
||||
NTStatus status = m_fileStore.NotifyChange(out ioRequest, handle, NotifyChangeFilter.FileName | NotifyChangeFilter.LastWrite | NotifyChangeFilter.DirName, false, 8192, OnNotifyChangeCompleted, null);
|
||||
Assert.IsTrue(status == NTStatus.STATUS_PENDING);
|
||||
|
||||
m_fileStore.Cancel(ioRequest);
|
||||
m_fileStore.CloseFile(handle);
|
||||
while (m_notifyChangeStatus == null)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.IsTrue(m_notifyChangeStatus.Value == NTStatus.STATUS_CANCELLED);
|
||||
}
|
||||
|
||||
private void OnNotifyChangeCompleted(NTStatus status, byte[] buffer, object context)
|
||||
{
|
||||
m_notifyChangeStatus = status;
|
||||
}
|
||||
|
||||
public void TestAll()
|
||||
{
|
||||
TestCancel();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ namespace SMBLibrary.Tests
|
|||
new NetBiosTests().TestAll();
|
||||
new RPCTests().TestAll();
|
||||
new SMB2SigningTests().TestAll();
|
||||
|
||||
new NTDirectoryFileSystemTests().TestAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NetBiosTests.cs" />
|
||||
<Compile Include="NTFileStore\NTDirectoryFileSystemTests.cs" />
|
||||
<Compile Include="NTFileStore\NTFileStoreTests.cs" />
|
||||
<Compile Include="NTLM\NTLMAuthenticationTests.cs" />
|
||||
<Compile Include="NTLM\NTLMSigningTests.cs" />
|
||||
<Compile Include="NTLM\RC4Tests.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue