[stylecop] program plugin/unit test first pass (#5908)

* initial pass

* multiple whitespace fixes
This commit is contained in:
Clint Rutkas
2020-08-12 11:46:11 -07:00
committed by GitHub
parent 8888739867
commit 95e82ca359
36 changed files with 351 additions and 273 deletions

View File

@@ -1,12 +1,9 @@
using Microsoft.Plugin.Program.Storage;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Threading.Tasks;
using Windows.Media.Capture;
using NUnit.Framework;
using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
@@ -18,51 +15,51 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
[Test]
public void ContainsShouldReturnTrueWhenListIsInitializedWithItem()
{
//Arrange
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
//Act
// Act
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsTrue(result);
}
[Test]
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{
//Arrange
// Arrange
IRepository<string> repository = new ListRepository<string>();
//Act
// Act
var itemName = "newItem";
repository.Add(itemName);
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsTrue(result);
}
[Test]
public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove()
{
//Arrange
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
//Act
// Act
repository.Remove(itemName);
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsFalse(result);
}
[Test]
public async Task AddShouldNotThrowWhenBeingIterated()
{
//Arrange
// Arrange
ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000;
for (var i = 0; i < numItems; ++i)
@@ -70,7 +67,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}");
}
//Act - Begin iterating on one thread
// Act - Begin iterating on one thread
var iterationTask = Task.Run(() =>
{
var remainingIterations = 10000;
@@ -78,7 +75,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
foreach (var item in repository)
{
//keep iterating
// keep iterating
}
--remainingIterations;
@@ -86,7 +83,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
});
//Act - Insert on another thread
// Act - Insert on another thread
var addTask = Task.Run(() =>
{
for (var i = 0; i < numItems; ++i)
@@ -95,14 +92,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
});
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
// Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
}
[Test]
public async Task RemoveShouldNotThrowWhenBeingIterated()
{
//Arrange
// Arrange
ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000;
for (var i = 0; i < numItems; ++i)
@@ -110,7 +107,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}");
}
//Act - Begin iterating on one thread
// Act - Begin iterating on one thread
var iterationTask = Task.Run(() =>
{
var remainingIterations = 10000;
@@ -118,7 +115,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
foreach (var item in repository)
{
//keep iterating
// keep iterating
}
--remainingIterations;
@@ -126,7 +123,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
});
//Act - Remove on another thread
// Act - Remove on another thread
var addTask = Task.Run(() =>
{
for (var i = 0; i < numItems; ++i)
@@ -135,7 +132,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}
});
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
// Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
}
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Program.UnitTests.Storage
{

View File

@@ -1,15 +1,18 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage;
using System.IO;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure.FileSystemHelper;
using System.Diagnostics;
using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
@@ -47,7 +50,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name,
ExecutableName = exename,
FullPath = fullPath,
Description = description1
Description = description1,
};
Win32Program item2 = new Win32Program
@@ -55,7 +58,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name,
ExecutableName = exename,
FullPath = fullPath,
Description = description2
Description = description2,
};
// Act
@@ -357,7 +360,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
ExecutableName = "path.exe",
ParentDirectory = "directory",
FullPath = "directory\\path.exe",
LnkResolvedPath = "directory\\path.lnk" // This must be equal for lnk applications
LnkResolvedPath = "directory\\path.lnk", // This must be equal for lnk applications
};
_win32ProgramRepository.Add(item);