mirror of
https://github.com/freedbygrace/WindowsNotifications.git
synced 2026-08-06 09:17:42 +00:00
Added Unit Tests
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using WindowsNotifications.Models;
|
||||
|
||||
namespace WindowsNotifications.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationManagerTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_SetsDefaultDatabasePath()
|
||||
{
|
||||
// Act
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(manager.DatabasePath);
|
||||
Assert.IsTrue(manager.DatabasePath.Contains("WindowsNotifications"));
|
||||
Assert.IsTrue(manager.DatabasePath.EndsWith("notifications.db"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsCustomDatabasePath()
|
||||
{
|
||||
// Arrange
|
||||
string customPath = Path.Combine(Path.GetTempPath(), "custom.db");
|
||||
|
||||
// Act
|
||||
var manager = new SimpleNotificationManager(customPath);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(customPath, manager.DatabasePath);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowNotification_ValidatesOptions()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentNullException>(() => manager.ShowNotification(null));
|
||||
|
||||
var emptyOptions = new NotificationOptions();
|
||||
Assert.Throws<ArgumentException>(() => manager.ShowNotification(emptyOptions));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowNotification_ReturnsValidResult()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
var options = new NotificationOptions
|
||||
{
|
||||
Title = "Test Title",
|
||||
Message = "Test Message"
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = manager.ShowNotification(options);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(options.Id, result.NotificationId);
|
||||
Assert.IsTrue(result.Displayed);
|
||||
Assert.IsNotNull(result.CreatedTime);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowSimpleNotification_ReturnsValidResult()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var result = manager.ShowSimpleNotification("Test Title", "Test Message");
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsNotNull(result.NotificationId);
|
||||
Assert.IsTrue(result.Displayed);
|
||||
Assert.IsNotNull(result.CreatedTime);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowNotificationWithButtons_ReturnsValidResult()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var result = manager.ShowNotificationWithButtons("Test Title", "Test Message", "Button 1", "Button 2");
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsNotNull(result.NotificationId);
|
||||
Assert.IsTrue(result.Displayed);
|
||||
Assert.IsNotNull(result.CreatedTime);
|
||||
Assert.IsTrue(result.Activated);
|
||||
Assert.IsNotNull(result.ClickedButtonId);
|
||||
Assert.IsNotNull(result.ClickedButtonText);
|
||||
Assert.IsNotNull(result.ClickedButtonArgument);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDatabaseFilePath_ReturnsDatabasePath()
|
||||
{
|
||||
// Arrange
|
||||
string customPath = Path.Combine(Path.GetTempPath(), "custom.db");
|
||||
var manager = new SimpleNotificationManager(customPath);
|
||||
|
||||
// Act
|
||||
string path = manager.GetDatabaseFilePath();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(customPath, path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsRunningAsSystem_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
bool isSystem = manager.IsRunningAsSystem();
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(isSystem);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetInteractiveUserSessions_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var sessions = manager.GetInteractiveUserSessions();
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(sessions);
|
||||
Assert.AreEqual(0, sessions.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetNotificationResult_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var result = manager.GetNotificationResult("test-id");
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WaitForNotification_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var result = manager.WaitForNotification("test-id", 100);
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllNotificationResults_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
var results = manager.GetAllNotificationResults();
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(results);
|
||||
Assert.AreEqual(0, results.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteNotificationResult_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
bool result = manager.DeleteNotificationResult("test-id");
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteAllNotificationResults_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var manager = new SimpleNotificationManager();
|
||||
|
||||
// Act
|
||||
bool result = manager.DeleteAllNotificationResults();
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using WindowsNotifications.Models;
|
||||
|
||||
namespace WindowsNotifications.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationOptionsTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_SetsDefaultValues()
|
||||
{
|
||||
// Act
|
||||
var options = new NotificationOptions();
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(options.Title);
|
||||
Assert.IsNull(options.Message);
|
||||
Assert.IsNull(options.LogoImagePath);
|
||||
Assert.IsNull(options.HeroImagePath);
|
||||
Assert.IsNull(options.Attribution);
|
||||
Assert.AreEqual(0, options.TimeoutInSeconds);
|
||||
Assert.IsFalse(options.Async);
|
||||
Assert.IsNotNull(options.Id);
|
||||
Assert.IsTrue(Guid.TryParse(options.Id, out _));
|
||||
Assert.IsNull(options.Tag);
|
||||
Assert.IsNull(options.Group);
|
||||
Assert.IsFalse(options.PersistState);
|
||||
Assert.IsTrue(options.EnableLogging);
|
||||
Assert.IsNull(options.LogAction);
|
||||
Assert.IsNotNull(options.Buttons);
|
||||
Assert.AreEqual(0, options.Buttons.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Properties_CanBeSet()
|
||||
{
|
||||
// Arrange
|
||||
var options = new NotificationOptions();
|
||||
Action<string> logAction = (log) => { };
|
||||
|
||||
// Act
|
||||
options.Title = "Test Title";
|
||||
options.Message = "Test Message";
|
||||
options.LogoImagePath = "logo.png";
|
||||
options.HeroImagePath = "hero.png";
|
||||
options.Attribution = "Test Attribution";
|
||||
options.TimeoutInSeconds = 30;
|
||||
options.Async = true;
|
||||
options.Id = "custom-id";
|
||||
options.Tag = "test-tag";
|
||||
options.Group = "test-group";
|
||||
options.PersistState = true;
|
||||
options.EnableLogging = false;
|
||||
options.LogAction = logAction;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Test Title", options.Title);
|
||||
Assert.AreEqual("Test Message", options.Message);
|
||||
Assert.AreEqual("logo.png", options.LogoImagePath);
|
||||
Assert.AreEqual("hero.png", options.HeroImagePath);
|
||||
Assert.AreEqual("Test Attribution", options.Attribution);
|
||||
Assert.AreEqual(30, options.TimeoutInSeconds);
|
||||
Assert.IsTrue(options.Async);
|
||||
Assert.AreEqual("custom-id", options.Id);
|
||||
Assert.AreEqual("test-tag", options.Tag);
|
||||
Assert.AreEqual("test-group", options.Group);
|
||||
Assert.IsTrue(options.PersistState);
|
||||
Assert.IsFalse(options.EnableLogging);
|
||||
Assert.AreEqual(logAction, options.LogAction);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Buttons_CanBeAdded()
|
||||
{
|
||||
// Arrange
|
||||
var options = new NotificationOptions();
|
||||
var button1 = new NotificationButton("Button 1");
|
||||
var button2 = new NotificationButton("Button 2", "custom-id", "custom-arg");
|
||||
|
||||
// Act
|
||||
options.Buttons.Add(button1);
|
||||
options.Buttons.Add(button2);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(2, options.Buttons.Count);
|
||||
Assert.AreEqual("Button 1", options.Buttons[0].Text);
|
||||
Assert.AreEqual("Button 2", options.Buttons[1].Text);
|
||||
Assert.AreEqual("custom-id", options.Buttons[1].Id);
|
||||
Assert.AreEqual("custom-arg", options.Buttons[1].Argument);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class NotificationButtonTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_SetsText()
|
||||
{
|
||||
// Arrange & Act
|
||||
var button = new NotificationButton("Button Text");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Button Text", button.Text);
|
||||
Assert.IsNotNull(button.Id);
|
||||
Assert.IsTrue(Guid.TryParse(button.Id, out _));
|
||||
Assert.AreEqual(button.Id, button.Argument);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsCustomId()
|
||||
{
|
||||
// Arrange & Act
|
||||
var button = new NotificationButton("Button Text", "custom-id");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Button Text", button.Text);
|
||||
Assert.AreEqual("custom-id", button.Id);
|
||||
Assert.AreEqual("custom-id", button.Argument);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsCustomArgument()
|
||||
{
|
||||
// Arrange & Act
|
||||
var button = new NotificationButton("Button Text", "custom-id", "custom-arg");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Button Text", button.Text);
|
||||
Assert.AreEqual("custom-id", button.Id);
|
||||
Assert.AreEqual("custom-arg", button.Argument);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Properties_CanBeSet()
|
||||
{
|
||||
// Arrange
|
||||
var button = new NotificationButton("Initial Text");
|
||||
|
||||
// Act
|
||||
button.Text = "Updated Text";
|
||||
button.Id = "updated-id";
|
||||
button.Argument = "updated-arg";
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Updated Text", button.Text);
|
||||
Assert.AreEqual("updated-id", button.Id);
|
||||
Assert.AreEqual("updated-arg", button.Argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using WindowsNotifications.Models;
|
||||
|
||||
namespace WindowsNotifications.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationResultTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_SetsNotificationId()
|
||||
{
|
||||
// Arrange
|
||||
string notificationId = "test-id";
|
||||
|
||||
// Act
|
||||
var result = new NotificationResult(notificationId);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(notificationId, result.NotificationId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsDefaultValues()
|
||||
{
|
||||
// Arrange
|
||||
string notificationId = "test-id";
|
||||
|
||||
// Act
|
||||
var result = new NotificationResult(notificationId);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result.Displayed);
|
||||
Assert.IsFalse(result.Activated);
|
||||
Assert.IsFalse(result.Dismissed);
|
||||
Assert.IsNull(result.ClickedButtonId);
|
||||
Assert.IsNull(result.ClickedButtonText);
|
||||
Assert.IsNull(result.ClickedButtonArgument);
|
||||
Assert.IsNull(result.ErrorMessage);
|
||||
Assert.IsNull(result.InteractionTime);
|
||||
// CreatedTime should be close to now
|
||||
Assert.Less((DateTime.Now - result.CreatedTime).TotalSeconds, 5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Error_CreatesErrorResult()
|
||||
{
|
||||
// Arrange
|
||||
string notificationId = "test-id";
|
||||
string errorMessage = "Test error message";
|
||||
|
||||
// Act
|
||||
var result = NotificationResult.Error(notificationId, errorMessage);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(notificationId, result.NotificationId);
|
||||
Assert.AreEqual(errorMessage, result.ErrorMessage);
|
||||
Assert.IsFalse(result.Displayed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Properties_CanBeSet()
|
||||
{
|
||||
// Arrange
|
||||
var result = new NotificationResult("test-id");
|
||||
DateTime interactionTime = DateTime.Now;
|
||||
|
||||
// Act
|
||||
result.Displayed = true;
|
||||
result.Activated = true;
|
||||
result.Dismissed = true;
|
||||
result.ClickedButtonId = "button-id";
|
||||
result.ClickedButtonText = "Button Text";
|
||||
result.ClickedButtonArgument = "button-arg";
|
||||
result.ErrorMessage = "Error message";
|
||||
result.InteractionTime = interactionTime;
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result.Displayed);
|
||||
Assert.IsTrue(result.Activated);
|
||||
Assert.IsTrue(result.Dismissed);
|
||||
Assert.AreEqual("button-id", result.ClickedButtonId);
|
||||
Assert.AreEqual("Button Text", result.ClickedButtonText);
|
||||
Assert.AreEqual("button-arg", result.ClickedButtonArgument);
|
||||
Assert.AreEqual("Error message", result.ErrorMessage);
|
||||
Assert.AreEqual(interactionTime, result.InteractionTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WindowsNotifications\SimpleWindowsNotifications.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user