-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Autofac; | ||
using Curupira.AppClient.Services; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Curupira.Tests.AppClient.Services | ||
{ | ||
[TestClass] | ||
public class AutofacHelperTests | ||
{ | ||
private IContainer _container; | ||
private AutofacHelper _autofacHelper; | ||
|
||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
var builder = new ContainerBuilder(); | ||
// Register types here | ||
builder.RegisterType<SomeImplementation>().As<ISomeInterface>().Named<ISomeInterface>("SomeName"); | ||
_container = builder.Build(); | ||
|
||
_autofacHelper = new AutofacHelper(_container); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
_container.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public void GetNamedImplementationsOfInterface_ShouldReturnCorrectImplementations() | ||
{ | ||
// Act | ||
var implementations = _autofacHelper.GetNamedImplementationsOfInterface<ISomeInterface>(); | ||
|
||
// Assert | ||
Assert.AreEqual(1, implementations.Count); | ||
Assert.AreEqual("SomeName", implementations[0].Name); | ||
Assert.AreEqual(typeof(SomeImplementation), implementations[0].ImplementationType); | ||
} | ||
|
||
public interface ISomeInterface { } | ||
|
||
public class SomeImplementation : ISomeInterface { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Curupira.Plugins.Installer; | ||
|
||
namespace Curupira.Tests.Plugins.Installer | ||
{ | ||
[TestClass] | ||
public class ProcessExecutorTests | ||
{ | ||
private IProcessExecutor _processExecutor; | ||
|
||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
_processExecutor = new ProcessExecutor(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ExecuteAsync_ShouldReturnZeroExitCode_WhenCommandSucceeds() | ||
{ | ||
// Arrange | ||
string fileName = "cmd.exe"; | ||
string arguments = "/c echo Hello, World!"; | ||
string workingDirectory = "."; | ||
|
||
// Act | ||
int exitCode = await _processExecutor.ExecuteAsync(fileName, arguments, workingDirectory); | ||
|
||
// Assert | ||
Assert.AreEqual(0, exitCode); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ExecuteAsync_ShouldReturnNonZeroExitCode_WhenCommandFails() | ||
{ | ||
// Arrange | ||
string fileName = "cmd.exe"; | ||
string arguments = "/c invalidcommand"; | ||
string workingDirectory = "."; | ||
|
||
// Act | ||
int exitCode = await _processExecutor.ExecuteAsync(fileName, arguments, workingDirectory); | ||
|
||
// Assert | ||
Assert.AreNotEqual(0, exitCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Curupira.WindowsService; | ||
using Microsoft.Owin.Testing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Curupira.Tests.WindowsService | ||
{ | ||
[TestClass] | ||
public class ApiKeyValidationTests | ||
{ | ||
private TestServer _server; | ||
private HttpClient _client; | ||
private string _validApiKey; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
_validApiKey = Guid.NewGuid().ToString(); | ||
Environment.SetEnvironmentVariable("API_KEY", _validApiKey); | ||
_server = TestServer.Create<Startup>(); | ||
_client = _server.HttpClient; | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
_client.Dispose(); | ||
_server.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetSystemUsage_WithValidApiKey_ReturnsOk() | ||
{ | ||
// Arrange | ||
var request = new HttpRequestMessage(HttpMethod.Get, "/api/v1/system/usage"); | ||
request.Headers.Add("X-Api-Key", _validApiKey); | ||
|
||
// Act | ||
var response = await _client.SendAsync(request).ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetSystemUsage_WithInvalidApiKey_ReturnsUnauthorized() | ||
{ | ||
// Arrange | ||
var request = new HttpRequestMessage(HttpMethod.Get, "/api/v1/system/usage"); | ||
request.Headers.Add("X-Api-Key", "invalidApiKey"); | ||
|
||
// Act | ||
var response = await _client.SendAsync(request).ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.AreEqual(System.Net.HttpStatusCode.Unauthorized, response.StatusCode); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetSystemUsage_WithNoApiKey_ReturnsUnauthorized() | ||
{ | ||
// Arrange | ||
var request = new HttpRequestMessage(HttpMethod.Get, "/api/v1/system/usage"); | ||
|
||
// Act | ||
var response = await _client.SendAsync(request).ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.AreEqual(System.Net.HttpStatusCode.Unauthorized, response.StatusCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters