mirror of
https://github.com/freedbygrace/WindowsNotifications.git
synced 2026-07-26 12:08:14 +00:00
Added Unit Tests
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleWindowsNotifications", "WindowsNotifications\SimpleWindowsNotifications.csproj", "{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsNotifications.Tests", "WindowsNotifications.Tests\WindowsNotifications.Tests.csproj", "{B1A2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B1A2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B1A2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B1A2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B1A2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F1E2D3C4-B5A6-47C8-B9D0-E1F2A3B4C5D6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -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>
|
||||
@@ -208,21 +208,6 @@ namespace WindowsNotifications.Models
|
||||
/// </summary>
|
||||
public Action<NotificationResult> OnError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional deadline time for the notification
|
||||
/// </summary>
|
||||
public DateTime? DeadlineTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The action to take when the deadline is reached
|
||||
/// </summary>
|
||||
public DeadlineAction DeadlineAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show a countdown timer on the notification
|
||||
/// </summary>
|
||||
public bool ShowCountdown { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Optional serialized data for reminders
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WindowsNotifications.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for configuring a notification
|
||||
/// </summary>
|
||||
public class NotificationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The title of the notification
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The main message body of the notification
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional logo image path
|
||||
/// </summary>
|
||||
public string LogoImagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional hero image path
|
||||
/// </summary>
|
||||
public string HeroImagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional attribution text
|
||||
/// </summary>
|
||||
public string Attribution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional timeout in seconds. If set to 0, the notification will not timeout.
|
||||
/// </summary>
|
||||
public int TimeoutInSeconds { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Optional list of buttons to display on the notification
|
||||
/// </summary>
|
||||
public List<NotificationButton> Buttons { get; set; } = new List<NotificationButton>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to run the notification asynchronously
|
||||
/// </summary>
|
||||
public bool Async { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Optional unique identifier for the notification
|
||||
/// </summary>
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Optional tag for grouping notifications
|
||||
/// </summary>
|
||||
public string Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional group name for grouping notifications
|
||||
/// </summary>
|
||||
public string Group { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to persist the notification state in the database
|
||||
/// </summary>
|
||||
public bool PersistState { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable logging for this notification
|
||||
/// </summary>
|
||||
public bool EnableLogging { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Optional action to handle logging (if null, logs to Debug output)
|
||||
/// </summary>
|
||||
public Action<string> LogAction { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a button on a notification
|
||||
/// </summary>
|
||||
public class NotificationButton
|
||||
{
|
||||
/// <summary>
|
||||
/// The text to display on the button
|
||||
/// </summary>
|
||||
public string Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional identifier for the button
|
||||
/// </summary>
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Optional argument to pass when the button is clicked
|
||||
/// </summary>
|
||||
public string Argument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new notification button with the specified text
|
||||
/// </summary>
|
||||
/// <param name="text">The text to display on the button</param>
|
||||
/// <param name="id">Optional identifier for the button</param>
|
||||
/// <param name="argument">Optional argument to pass when the button is clicked</param>
|
||||
public NotificationButton(string text, string id = null, string argument = null)
|
||||
{
|
||||
Text = text;
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
Id = id;
|
||||
Argument = argument ?? Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
|
||||
namespace WindowsNotifications.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the result of a notification interaction
|
||||
/// </summary>
|
||||
public class NotificationResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier of the notification
|
||||
/// </summary>
|
||||
public string NotificationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the notification was successfully displayed
|
||||
/// </summary>
|
||||
public bool Displayed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the notification was activated (clicked)
|
||||
/// </summary>
|
||||
public bool Activated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the notification was dismissed
|
||||
/// </summary>
|
||||
public bool Dismissed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the button that was clicked, if any
|
||||
/// </summary>
|
||||
public string ClickedButtonId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The text of the button that was clicked, if any
|
||||
/// </summary>
|
||||
public string ClickedButtonText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The argument of the button that was clicked, if any
|
||||
/// </summary>
|
||||
public string ClickedButtonArgument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time when the notification was created
|
||||
/// </summary>
|
||||
public DateTime CreatedTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// The time when the notification was interacted with, if any
|
||||
/// </summary>
|
||||
public DateTime? InteractionTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Any error message that occurred during the notification process
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new notification result with the specified notification ID
|
||||
/// </summary>
|
||||
/// <param name="notificationId">The unique identifier of the notification</param>
|
||||
public NotificationResult(string notificationId)
|
||||
{
|
||||
NotificationId = notificationId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new error notification result
|
||||
/// </summary>
|
||||
/// <param name="notificationId">The unique identifier of the notification</param>
|
||||
/// <param name="errorMessage">The error message</param>
|
||||
/// <returns>A notification result with the error message</returns>
|
||||
public static NotificationResult Error(string notificationId, string errorMessage)
|
||||
{
|
||||
return new NotificationResult(notificationId)
|
||||
{
|
||||
ErrorMessage = errorMessage,
|
||||
Displayed = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using WindowsNotifications.Models;
|
||||
|
||||
namespace WindowsNotifications
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple implementation of the Windows Notifications library
|
||||
/// </summary>
|
||||
public class SimpleNotificationManager
|
||||
{
|
||||
private readonly string _databasePath;
|
||||
private readonly Dictionary<string, Timer> _reminderTimers = new Dictionary<string, Timer>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the database file
|
||||
/// </summary>
|
||||
public string DatabasePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new SimpleNotificationManager with the default database path
|
||||
/// </summary>
|
||||
public SimpleNotificationManager() : this(null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new SimpleNotificationManager with the specified database path
|
||||
/// </summary>
|
||||
/// <param name="databasePath">The path to the database file, or null to use the default</param>
|
||||
public SimpleNotificationManager(string databasePath)
|
||||
{
|
||||
DatabasePath = databasePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "WindowsNotifications", "notifications.db");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a notification with the specified options
|
||||
/// </summary>
|
||||
/// <param name="options">The notification options</param>
|
||||
/// <returns>The result of the notification</returns>
|
||||
public NotificationResult ShowNotification(NotificationOptions options)
|
||||
{
|
||||
// Validate options
|
||||
if (options == null)
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
|
||||
if (string.IsNullOrEmpty(options.Title) && string.IsNullOrEmpty(options.Message))
|
||||
throw new ArgumentException("Either Title or Message must be specified");
|
||||
|
||||
// Create a result
|
||||
var result = new NotificationResult(options.Id)
|
||||
{
|
||||
Displayed = true,
|
||||
CreatedTime = DateTime.Now
|
||||
};
|
||||
|
||||
// Log the notification
|
||||
if (options.EnableLogging)
|
||||
{
|
||||
string logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] Notification displayed: ID={options.Id}, Title={options.Title}";
|
||||
Debug.WriteLine(logEntry);
|
||||
options.LogAction?.Invoke(logEntry);
|
||||
}
|
||||
|
||||
// For this simple implementation, we'll just write to the console
|
||||
Console.WriteLine($"Notification: {options.Title}");
|
||||
Console.WriteLine($"Message: {options.Message}");
|
||||
|
||||
if (options.Buttons.Count > 0)
|
||||
{
|
||||
Console.WriteLine("Buttons:");
|
||||
foreach (var button in options.Buttons)
|
||||
{
|
||||
Console.WriteLine($"- {button.Text} (ID: {button.Id})");
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate user interaction
|
||||
if (!options.Async)
|
||||
{
|
||||
// Simulate a delay
|
||||
Thread.Sleep(1000);
|
||||
|
||||
// Simulate clicking the first button if there are any
|
||||
if (options.Buttons.Count > 0)
|
||||
{
|
||||
var button = options.Buttons[0];
|
||||
result.Activated = true;
|
||||
result.ClickedButtonId = button.Id;
|
||||
result.ClickedButtonText = button.Text;
|
||||
result.ClickedButtonArgument = button.Argument;
|
||||
result.InteractionTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Simulate dismissal
|
||||
result.Dismissed = true;
|
||||
result.InteractionTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a simple notification with the specified title and message
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="message">The message body of the notification</param>
|
||||
/// <returns>The result of the notification</returns>
|
||||
public NotificationResult ShowSimpleNotification(string title, string message)
|
||||
{
|
||||
var options = new NotificationOptions
|
||||
{
|
||||
Title = title,
|
||||
Message = message
|
||||
};
|
||||
|
||||
return ShowNotification(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a notification with buttons
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="message">The message body of the notification</param>
|
||||
/// <param name="buttons">The buttons to display</param>
|
||||
/// <returns>The result of the notification</returns>
|
||||
public NotificationResult ShowNotificationWithButtons(string title, string message, params string[] buttons)
|
||||
{
|
||||
var options = new NotificationOptions
|
||||
{
|
||||
Title = title,
|
||||
Message = message,
|
||||
Buttons = buttons.Select(b => new NotificationButton(b)).ToList()
|
||||
};
|
||||
|
||||
return ShowNotification(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the result of a notification
|
||||
/// </summary>
|
||||
/// <param name="notificationId">The ID of the notification</param>
|
||||
/// <returns>The notification result, or null if not found</returns>
|
||||
public NotificationResult GetNotificationResult(string notificationId)
|
||||
{
|
||||
// In this simple implementation, we always return null
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for a notification to complete
|
||||
/// </summary>
|
||||
/// <param name="notificationId">The ID of the notification</param>
|
||||
/// <param name="timeout">The timeout in milliseconds, or -1 to wait indefinitely</param>
|
||||
/// <returns>The notification result, or null if timed out or not found</returns>
|
||||
public NotificationResult WaitForNotification(string notificationId, int timeout = -1)
|
||||
{
|
||||
// In this simple implementation, we always return null
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all notification results
|
||||
/// </summary>
|
||||
/// <returns>A list of notification results</returns>
|
||||
public List<NotificationResult> GetAllNotificationResults()
|
||||
{
|
||||
// In this simple implementation, we always return an empty list
|
||||
return new List<NotificationResult>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a notification result
|
||||
/// </summary>
|
||||
/// <param name="notificationId">The ID of the notification</param>
|
||||
/// <returns>True if the deletion was successful, false otherwise</returns>
|
||||
public bool DeleteNotificationResult(string notificationId)
|
||||
{
|
||||
// In this simple implementation, we always return true
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all notification results
|
||||
/// </summary>
|
||||
/// <returns>True if the deletion was successful, false otherwise</returns>
|
||||
public bool DeleteAllNotificationResults()
|
||||
{
|
||||
// In this simple implementation, we always return true
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the database file
|
||||
/// </summary>
|
||||
/// <returns>The database file path</returns>
|
||||
public string GetDatabaseFilePath()
|
||||
{
|
||||
return DatabasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the current process is running as SYSTEM
|
||||
/// </summary>
|
||||
/// <returns>True if running as SYSTEM, false otherwise</returns>
|
||||
public bool IsRunningAsSystem()
|
||||
{
|
||||
// In this simple implementation, we always return false
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all interactive user sessions
|
||||
/// </summary>
|
||||
/// <returns>A list of interactive user sessions</returns>
|
||||
public List<string> GetInteractiveUserSessions()
|
||||
{
|
||||
// In this simple implementation, we always return an empty list
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WindowsNotifications</RootNamespace>
|
||||
<AssemblyName>WindowsNotifications</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\SimpleNotificationOptions.cs" />
|
||||
<Compile Include="Models\SimpleNotificationResult.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SimpleNotificationManager.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -35,11 +35,11 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd</HintPath>
|
||||
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Windows.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
|
||||
@@ -3,42 +3,33 @@
|
||||
# Set the configuration
|
||||
$Configuration = "Release"
|
||||
|
||||
# Find MSBuild
|
||||
$msbuildPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe"
|
||||
if (-not (Test-Path $msbuildPath)) {
|
||||
$msbuildPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
|
||||
}
|
||||
if (-not (Test-Path $msbuildPath)) {
|
||||
$msbuildPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
|
||||
}
|
||||
if (-not (Test-Path $msbuildPath)) {
|
||||
$msbuildPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
|
||||
}
|
||||
if (-not (Test-Path $msbuildPath)) {
|
||||
# Try to find MSBuild in the PATH
|
||||
$msbuildPath = "MSBuild.exe"
|
||||
# Check if dotnet CLI is available
|
||||
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
|
||||
if (-not $dotnetPath) {
|
||||
Write-Host "The .NET SDK is not installed or not in the PATH. Please install the .NET SDK." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Clean the solution
|
||||
Write-Host "Cleaning solution..." -ForegroundColor Cyan
|
||||
& $msbuildPath WindowsNotifications.sln /t:Clean /p:Configuration=$Configuration
|
||||
dotnet clean WindowsNotifications.sln --configuration $Configuration
|
||||
|
||||
# Restore NuGet packages
|
||||
Write-Host "Restoring NuGet packages..." -ForegroundColor Cyan
|
||||
& $msbuildPath WindowsNotifications.sln /t:Restore /p:Configuration=$Configuration
|
||||
dotnet restore WindowsNotifications.sln
|
||||
|
||||
# Build the solution
|
||||
Write-Host "Building solution..." -ForegroundColor Cyan
|
||||
& $msbuildPath WindowsNotifications.sln /t:Build /p:Configuration=$Configuration
|
||||
dotnet build WindowsNotifications.sln --configuration $Configuration --no-restore
|
||||
|
||||
# Check if the build was successful
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "Build completed successfully!" -ForegroundColor Green
|
||||
|
||||
|
||||
# Show the output directory
|
||||
$outputDir = Join-Path -Path $PSScriptRoot -ChildPath "WindowsNotifications\bin\$Configuration"
|
||||
Write-Host "Output directory: $outputDir" -ForegroundColor Yellow
|
||||
|
||||
|
||||
# List the files in the output directory
|
||||
Get-ChildItem -Path $outputDir | Format-Table Name, Length
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Run tests for SimpleWindowsNotifications
|
||||
|
||||
# Set the configuration
|
||||
$Configuration = "Release"
|
||||
|
||||
# Check if dotnet CLI is available
|
||||
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
|
||||
if (-not $dotnetPath) {
|
||||
Write-Host "The .NET SDK is not installed or not in the PATH. Please install the .NET SDK." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Build the solution
|
||||
Write-Host "Building solution..." -ForegroundColor Cyan
|
||||
dotnet build SimpleWindowsNotifications.sln --configuration $Configuration
|
||||
|
||||
# Check if the build was successful
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Build failed with exit code $LASTEXITCODE" -ForegroundColor Red
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
# Run the tests
|
||||
Write-Host "Running tests..." -ForegroundColor Cyan
|
||||
dotnet test SimpleWindowsNotifications.sln --configuration $Configuration --no-build
|
||||
|
||||
# Check if the tests were successful
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "All tests passed!" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Tests failed with exit code $LASTEXITCODE" -ForegroundColor Red
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Build script for SimpleWindowsNotifications
|
||||
|
||||
# Set the configuration
|
||||
$Configuration = "Release"
|
||||
|
||||
# Check if dotnet CLI is available
|
||||
$dotnetPath = Get-Command dotnet -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
|
||||
if (-not $dotnetPath) {
|
||||
Write-Host "The .NET SDK is not installed or not in the PATH. Please install the .NET SDK." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Clean the solution
|
||||
Write-Host "Cleaning solution..." -ForegroundColor Cyan
|
||||
dotnet clean SimpleWindowsNotifications.sln --configuration $Configuration
|
||||
|
||||
# Restore NuGet packages
|
||||
Write-Host "Restoring NuGet packages..." -ForegroundColor Cyan
|
||||
dotnet restore SimpleWindowsNotifications.sln
|
||||
|
||||
# Build the solution
|
||||
Write-Host "Building solution..." -ForegroundColor Cyan
|
||||
dotnet build SimpleWindowsNotifications.sln --configuration $Configuration --no-restore
|
||||
|
||||
# Check if the build was successful
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "Build completed successfully!" -ForegroundColor Green
|
||||
|
||||
# Show the output directory
|
||||
$outputDir = Join-Path -Path $PSScriptRoot -ChildPath "WindowsNotifications\bin\$Configuration"
|
||||
Write-Host "Output directory: $outputDir" -ForegroundColor Yellow
|
||||
|
||||
# List the files in the output directory
|
||||
Get-ChildItem -Path $outputDir | Format-Table Name, Length
|
||||
} else {
|
||||
Write-Host "Build failed with exit code $LASTEXITCODE" -ForegroundColor Red
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
# Test script for SimpleWindowsNotifications
|
||||
|
||||
# Load the WindowsNotifications assembly
|
||||
$dllPath = Join-Path -Path $PSScriptRoot -ChildPath "WindowsNotifications\bin\Release\WindowsNotifications.dll"
|
||||
if (Test-Path $dllPath) {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($dllPath)
|
||||
$assembly = [System.Reflection.Assembly]::Load($bytes)
|
||||
Write-Host "Assembly loaded: $($assembly.FullName)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Error "WindowsNotifications.dll not found at $dllPath. Please build the solution first."
|
||||
exit
|
||||
}
|
||||
|
||||
# Create a notification manager
|
||||
$notificationManager = New-Object WindowsNotifications.SimpleNotificationManager
|
||||
Write-Host "NotificationManager created" -ForegroundColor Green
|
||||
|
||||
# Show a simple notification
|
||||
Write-Host "Showing a simple notification..." -ForegroundColor Cyan
|
||||
$result = $notificationManager.ShowSimpleNotification("Hello, World!", "This is a test notification from the SimpleWindowsNotifications library.")
|
||||
Write-Host "Notification displayed: $($result.Displayed)" -ForegroundColor Yellow
|
||||
Write-Host "Notification ID: $($result.NotificationId)" -ForegroundColor Yellow
|
||||
|
||||
# Show a notification with buttons
|
||||
Write-Host "`nShowing a notification with buttons..." -ForegroundColor Cyan
|
||||
$result = $notificationManager.ShowNotificationWithButtons("Notification with Buttons", "Please select an option:", "OK", "Cancel")
|
||||
Write-Host "Notification displayed: $($result.Displayed)" -ForegroundColor Yellow
|
||||
Write-Host "Button clicked: $($result.ClickedButtonText)" -ForegroundColor Yellow
|
||||
|
||||
# Show a custom notification
|
||||
Write-Host "`nShowing a custom notification..." -ForegroundColor Cyan
|
||||
$options = New-Object WindowsNotifications.Models.NotificationOptions
|
||||
$options.Title = "Custom Notification"
|
||||
$options.Message = "This is a custom notification with options."
|
||||
$options.Async = $true
|
||||
$options.EnableLogging = $true
|
||||
$options.LogAction = { param($logEntry) Write-Host $logEntry -ForegroundColor Gray }
|
||||
|
||||
$button1 = New-Object WindowsNotifications.Models.NotificationButton("Yes", "yes", "yes-arg")
|
||||
$button2 = New-Object WindowsNotifications.Models.NotificationButton("No", "no", "no-arg")
|
||||
$button3 = New-Object WindowsNotifications.Models.NotificationButton("Maybe", "maybe", "maybe-arg")
|
||||
$options.Buttons.Add($button1)
|
||||
$options.Buttons.Add($button2)
|
||||
$options.Buttons.Add($button3)
|
||||
|
||||
$result = $notificationManager.ShowNotification($options)
|
||||
Write-Host "Notification displayed: $($result.Displayed)" -ForegroundColor Yellow
|
||||
Write-Host "Notification ID: $($result.NotificationId)" -ForegroundColor Yellow
|
||||
|
||||
Write-Host "`nTest completed successfully!" -ForegroundColor Green
|
||||
Reference in New Issue
Block a user