Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial unit tests #71

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a1388eb
Add initial tests
networkfusion Jul 28, 2022
6349b81
Remove unused usings.
networkfusion Jul 28, 2022
8d89960
Move tests to Primitives
networkfusion Jul 28, 2022
bc14d24
Add folders for future tests.
networkfusion Jul 28, 2022
7abb506
Merge branch 'main' into add-unit-tests
networkfusion Apr 22, 2023
cd5eb8c
Move test folder to root
networkfusion Apr 24, 2023
1c72ccd
Update assembily info for tests.
networkfusion Apr 24, 2023
9f3f6e8
Fix build
networkfusion Apr 24, 2023
ab247a8
Windows fix temp
networkfusion Apr 24, 2023
f976caa
Windows fix folder case
networkfusion Apr 24, 2023
af9f565
Fix test package requirements.
networkfusion Apr 24, 2023
5526eb6
Remove un-needed packages.
networkfusion Apr 24, 2023
f17497d
Revert "Remove un-needed packages."
networkfusion Apr 24, 2023
7e899ad
Fix deprecation warnings
networkfusion Apr 24, 2023
baf1385
Comment out unused attributes
networkfusion Apr 26, 2023
237a904
Minor fixes and comment improvements
networkfusion Apr 26, 2023
ac35f50
Update azure-pipelines.yml
networkfusion Apr 26, 2023
9cc64db
Add set check for file attributes.
networkfusion Apr 26, 2023
93eddfd
Fixes for nuspec
networkfusion Apr 26, 2023
45a417a
Update version json
networkfusion Apr 26, 2023
9d2e7a9
Revert CI changes
networkfusion Apr 26, 2023
1a3978b
Target nF only
networkfusion Apr 26, 2023
c2e4e27
Update 1 NuGet dependencies
nfbot May 3, 2023
759da61
Add initial tests
networkfusion Jul 28, 2022
d7bf1a1
Remove unused usings.
networkfusion Jul 28, 2022
a498118
Move tests to Primitives
networkfusion Jul 28, 2022
f3a6aed
Add folders for future tests.
networkfusion Jul 28, 2022
6d57d64
Move test folder to root
networkfusion Apr 24, 2023
29167fb
Update assembily info for tests.
networkfusion Apr 24, 2023
da5e2f1
Fix build
networkfusion Apr 24, 2023
1b23cc8
Windows fix temp
networkfusion Apr 24, 2023
93245b5
Windows fix folder case
networkfusion Apr 24, 2023
91824b2
Fix test package requirements.
networkfusion Apr 24, 2023
aba8cd7
Remove un-needed packages.
networkfusion Apr 24, 2023
318ca12
Revert "Remove un-needed packages."
networkfusion Apr 24, 2023
262392b
Fix deprecation warnings
networkfusion Apr 24, 2023
e3a3e48
Comment out unused attributes
networkfusion Apr 26, 2023
e502f1d
Minor fixes and comment improvements
networkfusion Apr 26, 2023
a3af1bd
Update azure-pipelines.yml
networkfusion Apr 26, 2023
9e78cb3
Add set check for file attributes.
networkfusion Apr 26, 2023
d02ae67
Fixes for nuspec
networkfusion Apr 26, 2023
565fba3
Update version json
networkfusion Apr 26, 2023
fd05c8a
Revert CI changes
networkfusion Apr 26, 2023
500da60
Target nF only
networkfusion Apr 26, 2023
dbc5fd6
Update test nuget
networkfusion May 8, 2023
b4482ee
Merge branch 'add-unit-tests' of https://github.com/nanoframework/Sys…
networkfusion May 8, 2023
a1e2e3c
part revert pipeline change
networkfusion May 8, 2023
6746cf6
Fixes for latest test nuget.
networkfusion May 8, 2023
726d4c1
Add write file test skeleton.
networkfusion May 8, 2023
8e51d34
Add some minor comment improvements.
networkfusion May 8, 2023
e87eb14
Re-align FileAttribures
networkfusion May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory -->
<TestSessionTimeout>120000</TestSessionTimeout><!-- Milliseconds -->
<TargetFrameworkVersion>net48</TargetFrameworkVersion>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<nanoFrameworkAdapter>
<Logging>None</Logging>
<IsRealHardware>False</IsRealHardware>
</nanoFrameworkAdapter>
</RunSettings>
4 changes: 2 additions & 2 deletions System.IO.FileSystem/Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class Directory
/// <summary>
/// Determines a list of available logical drives.
/// </summary>
/// <returns>String[] of available drives, ex. "D:\\"</returns>
/// <returns>A String[] of available storage drive letters."</returns>
public static string[] GetLogicalDrives()
{
return GetLogicalDrivesNative();
Expand Down Expand Up @@ -82,7 +82,7 @@ public static string[] GetFiles(string path)
/// <summary>
/// List directories from the specified folder.
/// </summary>
/// <param name="path"></param>
/// <param name="path">The specified folder.</param>
/// <returns>
/// When this method completes successfully, it returns an array of absolute paths to the subfolders in the specified directory.
/// </returns>
Expand Down
12 changes: 6 additions & 6 deletions System.IO.FileSystem/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void Copy(
using (FileStream writer = new FileStream(destFileName, writerMode, FileAccess.Write))
{
long fileLength = reader.Length;
//writer.SetLength(fileLength);
////writer.SetLength(fileLength);

byte[] buffer = new byte[_defaultCopyBufferSize];

Expand Down Expand Up @@ -198,12 +198,12 @@ public static void Move(
#pragma warning restore S112 // General exceptions should never be thrown
}

// TODO: File Handling missing
// FIXME: File Handling missing

// Check the volume of files
if (Path.GetPathRoot(sourceFileName) != Path.GetPathRoot(destFileName))
{
// Cross Volume move (FAT_FS move not working)
// FIXME: Cross Volume move (FAT_FS move not working)
Copy(sourceFileName, destFileName);
Delete(sourceFileName);
}
Expand All @@ -215,7 +215,7 @@ public static void Move(
}

/// <summary>
/// Gets the FileAttributes of the file on the path.
/// Gets the <see cref="FileAttributes"/> of the file on the path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <returns>The FileAttributes of the file on the path.</returns>
Expand All @@ -237,7 +237,7 @@ public static FileAttributes GetAttributes(string path)
}

/// <summary>
/// Sets the specified FileAttributes of the file on the specified path.
/// Sets the specified <see cref="FileAttributes"/> of the file on the specified path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="fileAttributes">A bitwise combination of the enumeration values.</param>
Expand All @@ -249,7 +249,7 @@ public static void SetAttributes(string path, FileAttributes fileAttributes)
/// <summary>
/// Determines the time of the last write/modification to file under given path.
/// </summary>
/// <param name="path"></param>
/// <param name="path">The path to the file.</param>
/// <returns>Time of the last write/modification.</returns>
/// <exception cref="IOException"> Logical drive or a file under given path does not exist. </exception>
public static DateTime GetLastWriteTime(string path)
Expand Down
13 changes: 7 additions & 6 deletions System.IO.FileSystem/FileAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ public enum FileAttributes
/// <summary>
/// The file is read-only.
/// </summary>
ReadOnly = 0x1,
ReadOnly = 0x01, // FIXME: should be uint 0x0001, to align with .Net.

/// <summary>
/// The file is hidden, and thus is not included in an ordinary directory listing.
/// </summary>
Hidden = 0x2,
Hidden = 0x02, // FIXME: should be uint 0x0002, to align with .Net.

/// <summary>
/// The file is a system file. That is, the file is part of the operating system or is used exclusively by the operating system.
/// The file is a system file.
/// That is, the file is part of the operating system or is used exclusively by the operating system.
/// </summary>
System = 0x4,
System = 0x04, // FIXME: should be uint 0x0004, to align with .Net.

/// <summary>
/// The file is a directory.
/// </summary>
Directory = 0x10,
Directory = 0x10, // FIXME: should be uint 0x0010, to align with .Net.

/// <summary>
/// This file is marked to be included in incremental backup operation.
/// </summary>
Archive = 0x20,
Archive = 0x20 // FIXME: should be uint 0x0010, to align with .Net.
}
}
10 changes: 5 additions & 5 deletions System.IO.FileSystem/FileShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.IO
{
/// <summary>
/// Contains constants for controlling file sharing options while
/// opening files. You can specify what access other processes trying
/// opening files. You can specify what access other processes trying
/// to open the same file concurrently can have.
/// </summary>
[Flags]
Expand All @@ -17,27 +17,27 @@ public enum FileShare
/// No sharing. Any request to open the file (by this process or another
/// process) will fail until the file is closed.
/// </summary>
None = 0,
None = 0x00,

/// <summary>
/// Allows subsequent opening of the file for reading. If this flag is not
/// specified, any request to open the file for reading (by this process or
/// another process) will fail until the file is closed.
/// </summary>
Read = 1,
Read = 0x01,

/// <summary>
/// Allows subsequent opening of the file for writing. If this flag is not
/// specified, any request to open the file for writing (by this process or
/// another process) will fail until the file is closed.
/// </summary>
Write = 2,
Write = 0x02,

/// <summary>
/// Allows subsequent opening of the file for writing or reading. If this flag
/// is not specified, any request to open the file for writing or reading (by
/// this process or another process) will fail until the file is closed.
/// </summary>
ReadWrite = 3,
ReadWrite = 0x03
}
}
12 changes: 8 additions & 4 deletions System.IO.FileSystem/FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public FileStream(
}

/// <summary>
/// Destructor
/// Destructor.
/// </summary>
~FileStream()
{
Expand Down Expand Up @@ -345,7 +345,7 @@ protected override void Dispose(bool disposing)
/// </summary>
public override void Flush()
{
// Already everything flushed/sync after every Read/Write operation, nothing to do here.
// Everything is flushed/sync already after every Read/Write operation, nothing to do here.
}

/// <summary>
Expand Down Expand Up @@ -378,7 +378,7 @@ public override int Read(

if (buffer.Length < offset + count)
{
throw new IndexOutOfRangeException("Buffer size is smaller then offset + byteCount.");
throw new IndexOutOfRangeException("Buffer size is smaller than 'offset' + 'byteCount'.");
}

// Create buffer for read Data
Expand All @@ -405,7 +405,7 @@ public override int Read(
}

/// <summary>
/// Reads a byte from the file and advances the read position one byte.
/// Reads a byte from the file and advances the read position by one byte.
/// </summary>
/// <returns></returns>
public override int ReadByte()
Expand Down Expand Up @@ -558,6 +558,10 @@ public override void WriteByte(byte value)
[MethodImpl(MethodImplOptions.InternalCall)]
private extern long GetLengthNative(string path, string fileName);

/// <summary>
/// Reads bytes from the file stream.
/// </summary>
/// <param name="buffer">Bytes to read from the stream.</param>
public override int Read(SpanByte buffer)
{
throw new NotImplementedException();
Expand Down
14 changes: 8 additions & 6 deletions System.IO.FileSystem/System.IO.FileSystem.nfproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.props" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.props')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.props" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.props')" />
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
Expand Down Expand Up @@ -68,9 +68,8 @@
<HintPath>..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.Runtime.Events, Version=1.11.6.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.Runtime.Events">
<HintPath>..\packages\nanoFramework.Runtime.Events.1.11.6\lib\nanoFramework.Runtime.Events.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.System.Text, Version=1.2.37.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.System.Text.1.2.37\lib\nanoFramework.System.Text.dll</HintPath>
Expand All @@ -81,6 +80,9 @@
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="packages.lock.json" />
</ItemGroup>
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
Expand All @@ -91,8 +93,8 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.props'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.props'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.targets'))" />
</Target>
<Import Project="..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.6.128\build\Nerdbank.GitVersioning.targets')" />
</Project>
2 changes: 1 addition & 1 deletion System.IO.FileSystem/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<package id="nanoFramework.Runtime.Events" version="1.11.6" targetFramework="netnano1.0" />
<package id="nanoFramework.System.IO.Streams" version="1.1.38" targetFramework="netnano1.0" />
<package id="nanoFramework.System.Text" version="1.2.37" targetFramework="netnano1.0" />
<package id="Nerdbank.GitVersioning" version="3.5.119" developmentDependency="true" targetFramework="netnano1.0" />
<package id="Nerdbank.GitVersioning" version="3.6.128" developmentDependency="true" targetFramework="netnano1.0" />
</packages>
6 changes: 3 additions & 3 deletions System.IO.FileSystem/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[3.5.119, 3.5.119]",
"resolved": "3.5.119",
"contentHash": "x8k4zV6YKZA5Rr810439lG9NngdbyPtFv0QpIYz32m1Im59kvSbEHO8gKGZoNvsfZSquayjEDUCa8acbut372g=="
"requested": "[3.6.128, 3.6.128]",
"resolved": "3.6.128",
"contentHash": "zeA+Ho3XlPgt6P9MRALlkEvfOOzDQdNseV0xia/nSfC1lSrl0+gizlWyixaHvSYUw2ru7pBIKnK451bYOjPRjA=="
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions Tests/System.IO.FileSystem.Tests/Primitives/FileAccessTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using nanoFramework.TestFramework;

namespace System.IO.FileSystem.Tests.Primitives
{
[TestClass]
public static class FileAccessTests
{
[TestMethod]
public static void ValueTest()
{
Assert.AreEqual(1, (int)FileAccess.Read);
Assert.AreEqual(2, (int)FileAccess.Write);
Assert.AreEqual(3, (int)FileAccess.ReadWrite);
}
}
}
22 changes: 22 additions & 0 deletions Tests/System.IO.FileSystem.Tests/Primitives/FileAttributesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using nanoFramework.TestFramework;

namespace System.IO.FileSystem.Tests.Primitives
{
[TestClass]
public static class FileAttributesTests
{
[TestMethod]
public static void ValueTest()
{
Assert.AreEqual(0x0001, (int)FileAttributes.ReadOnly);
Assert.AreEqual(0x0002, (int)FileAttributes.Hidden);
Assert.AreEqual(0x0004, (int)FileAttributes.System);
Assert.AreEqual(0x0010, (int)FileAttributes.Directory);
Assert.AreEqual(0x0020, (int)FileAttributes.Archive);
}

}
}
22 changes: 22 additions & 0 deletions Tests/System.IO.FileSystem.Tests/Primitives/FileModeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using nanoFramework.TestFramework;

namespace System.IO.FileSystem.Tests.Primitives
{
[TestClass]
public static class FileModeTests
{
[TestMethod]
public static void ValueTest()
{
Assert.AreEqual(1, (int)FileMode.CreateNew);
Assert.AreEqual(2, (int)FileMode.Create);
Assert.AreEqual(3, (int)FileMode.Open);
Assert.AreEqual(4, (int)FileMode.OpenOrCreate);
Assert.AreEqual(5, (int)FileMode.Truncate);
Assert.AreEqual(6, (int)FileMode.Append);
}
}
}
20 changes: 20 additions & 0 deletions Tests/System.IO.FileSystem.Tests/Primitives/FileShareTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using nanoFramework.TestFramework;

namespace System.IO.FileSystem.Tests.Primitives
{
[TestClass]
public static class FileShareTests
{
[TestMethod]
public static void ValueTest()
{
Assert.AreEqual(0, (int)FileShare.None);
Assert.AreEqual(1, (int)FileShare.Read);
Assert.AreEqual(2, (int)FileShare.Write);
Assert.AreEqual(3, (int)FileShare.ReadWrite);
}
}
}
29 changes: 29 additions & 0 deletions Tests/System.IO.FileSystem.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("nanoFramework.System.IO.FileSystem.Tests")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyProduct("nanoFramework.System.IO.FileSystem.Tests")]
[assembly: AssemblyCopyright("Copyright (c) .NET Foundation and Contributors")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading