Skip to content

Commit

Permalink
PR review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Feb 15, 2023
1 parent d9806f4 commit b092b15
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 180 deletions.
127 changes: 62 additions & 65 deletions Frends.Files.Delete/Frends.Files.Delete.Tests/ImpersonationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,83 @@
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;

namespace Frends.Files.Delete.Tests;

namespace Frends.Files.Delete.Tests
[TestFixture]
class ImpersonationTests
{
[TestFixture]
class ImpersonationTests
{
/// <summary>
/// Impersonation tests needs to be run as administrator so that the OneTimeSetup can create a local test user. Impersonation tests can only be run in Windows OS.
/// </summary>
private readonly string _dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../TestData/");
Input? _input;
Options? _options;

private readonly string _domain = Environment.MachineName;
private readonly string _name = "test";
private readonly string _pwd = "pas5woRd!";
/// <summary>
/// Impersonation tests needs to be run as administrator so that the OneTimeSetup can create a local test user. Impersonation tests can only be run in Windows OS.
/// </summary>
private readonly string _dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../TestData/");
Input? _input;
Options? _options;

private readonly string _domain = Environment.MachineName;
private readonly string _name = "test";
private readonly string _pwd = "pas5woRd!";

[OneTimeSetUp]
public void OneTimeSetup()
{
Helper.CreateTestUser(_domain, _name, _pwd);

_input = new Input
{
Directory = _dir,
Pattern = "*"
};

_options = new Options
{
UseGivenUserCredentialsForRemoteConnections = true,
UserName = $"{_domain}\\{_name}",
Password = _pwd
};
}
[OneTimeSetUp]
public void OneTimeSetup()
{
Helper.CreateTestUser(_domain, _name, _pwd);

[OneTimeTearDown]
public void OneTimeTearDown()
_input = new Input
{
Helper.DeleteTestUser(_name);
}
Directory = _dir,
Pattern = "*"
};

[SetUp]
public void Setup()
_options = new Options
{
Helper.CreateTestFiles(_dir);
}
UseGivenUserCredentialsForRemoteConnections = true,
UserName = $"{_domain}\\{_name}",
Password = _pwd
};
}

[TearDown]
public void TearDown()
{
Helper.DeleteTestFolder(_dir);
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
Helper.DeleteTestUser(_name);
}

[Test]
public void FileDeleteTestWithCredentials()
{
var result = Files.Delete(
_input,
_options, default);
[SetUp]
public void Setup()
{
Helper.CreateTestFiles(_dir);
}

Assert.AreEqual(7, result.Files.Count);
Assert.IsFalse(File.Exists(result.Files[0].Path));
}
[TearDown]
public void TearDown()
{
Helper.DeleteTestFolder(_dir);
}

[Test]
public void FileDeleteTestWithUsernameWithoutDomain()
[Test]
public void FileDeleteTestWithCredentials()
{
var result = Files.Delete(
_input,
_options, default);

Assert.AreEqual(7, result.Files.Count);
Assert.IsFalse(File.Exists(result.Files[0].Path));
}

[Test]
public void FileDeleteTestWithUsernameWithoutDomain()
{
var options = new Options
{
var options = new Options
{
UseGivenUserCredentialsForRemoteConnections = true,
UserName = "test",
Password = _pwd
};
UseGivenUserCredentialsForRemoteConnections = true,
UserName = "test",
Password = _pwd
};

var ex = Assert.Throws<ArgumentException>(() => Files.Delete(_input, options, default));
Assert.AreEqual($@"UserName field must be of format domain\username was: {options.UserName}", ex.Message);
}
var ex = Assert.Throws<ArgumentException>(() => Files.Delete(_input, options, default));
Assert.AreEqual($@"UserName field must be of format domain\username was: {options.UserName}", ex.Message);
}
}
2 changes: 0 additions & 2 deletions Frends.Files.Delete/Frends.Files.Delete.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;


namespace Frends.Files.Delete.Tests;

Expand Down
37 changes: 18 additions & 19 deletions Frends.Files.Delete/Frends.Files.Delete/Definitions/Input.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Frends.Files.Delete.Definitions
namespace Frends.Files.Delete.Definitions;

/// <summary>
/// Input parameters.
/// </summary>
public class Input
{
/// <summary>
/// Input parameters.
/// Source directory.
/// </summary>
public class Input
{
/// <summary>
/// Source directory.
/// </summary>
/// <example>c:\temp</example>
[DisplayFormat(DataFormatString = "Text")]
public string Directory { get; set; }
/// <example>c:\temp</example>
[DisplayFormat(DataFormatString = "Text")]
public string Directory { get; set; }

/// <summary>
/// Pattern to match for files. The file mask uses regular expressions, but for convenience, it has special handling for * and ? wildcards.
/// </summary>
/// <example>test.txt, test*.txt, test?.txt, test.(txt|xml), test.[^t][^x][^t], &lt;regex&gt;^(?!prof).*_test.txt</example>
[DisplayFormat(DataFormatString = "Text")]
[DefaultValue("\"**\\Folder\\*.xml\"")]
public string Pattern { get; set; }
}
}
/// <summary>
/// Pattern to match for files. The file mask uses regular expressions, but for convenience, it has special handling for * and ? wildcards.
/// </summary>
/// <example>test.txt, test*.txt, test?.txt, test.(txt|xml), test.[^t][^x][^t], &lt;regex&gt;^(?!prof).*_test.txt</example>
[DisplayFormat(DataFormatString = "Text")]
[DefaultValue("\"**\\Folder\\*.xml\"")]
public string Pattern { get; set; }
}
Loading

0 comments on commit b092b15

Please sign in to comment.