### C# Unit Test: Mocking Repository for Task Sorting Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Tests the CreatePlan method of SimpleTaskPlanner to verify that work items are correctly sorted by priority (High, Medium, Low) and then by due date. It uses Moq to provide a mock implementation of IWorkItemsRepository, avoiding actual database or file system interaction. ```csharp using Xunit; using Moq; using Ivanyshen.TaskPlanner.Domain.Logic; using Ivanyshen.TaskPlanner.Domain.Models; using Ivanyshen.TaskPlanner.Domain.Models.Enums; using Ivanyshen.TaskPlanner.DataAccess.Abstractions; // Test that CreatePlan sorts correctly [Fact] public void CreatePlan_SortsByPriorityAndDueDate() { // Arrange: Create mock repository var mockRepo = new Mock(); var tasks = new[] { new WorkItem { Title = "Low Priority Late", Priority = Priority.Low, DueDate = new DateTime(2025, 12, 1), IsCompleted = false }, new WorkItem { Title = "High Priority Early", Priority = Priority.High, DueDate = new DateTime(2025, 11, 1), IsCompleted = false }, new WorkItem { Title = "Medium Priority", Priority = Priority.Medium, DueDate = new DateTime(2025, 11, 15), IsCompleted = false } }; mockRepo.Setup(repo => repo.GetAll()).Returns(tasks); var planner = new SimpleTaskPlanner(mockRepo.Object); // Act WorkItem[] plan = planner.CreatePlan(); // Assert Assert.Equal(3, plan.Length); Assert.Equal(Priority.High, plan[0].Priority); Assert.Equal(Priority.Medium, plan[1].Priority); Assert.Equal(Priority.Low, plan[2].Priority); } ``` -------------------------------- ### C# Console Application for Task Management Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Demonstrates a full-featured interactive console application using repository and planner logic. It covers adding, displaying, completing, and removing tasks, with date parsing using a specific culture. Dependencies include Ivanyshen.TaskPlanner.DataAccess, Ivanyshen.TaskPlanner.Domain.Logic, and Ivanyshen.TaskPlanner.Domain.Models. ```csharp using Ivanyshen.TaskPlanner.DataAccess; using Ivanyshen.TaskPlanner.Domain.Logic; using Ivanyshen.TaskPlanner.Domain.Models; using Ivanyshen.TaskPlanner.Domain.Models.Enums; using System.Globalization; var repository = new FileWorkItemsRepository(); var planner = new SimpleTaskPlanner(repository); var uiCulture = new CultureInfo("uk-UA"); // Add a new task var newItem = new WorkItem(); newItem.Title = "Complete project report"; newItem.Description = "Write final report for Q4 project"; newItem.Priority = Priority.High; newItem.Complexity = Complexity.Days; // Parse date with specific culture if (DateTime.TryParseExact("31.12.2025", "dd.MM.yyyy", uiCulture, DateTimeStyles.None, out var dueDate)) { newItem.DueDate = dueDate; } Guid id = repository.Add(newItem); repository.SaveChanges(); Console.WriteLine($"Task added with ID: {id}"); // Build and display plan WorkItem[] plan = planner.CreatePlan(); if (plan.Length == 0) { Console.WriteLine("No tasks available."); } else { Console.WriteLine("=== Current Plan ==="); foreach (var task in plan) { Console.WriteLine(task); // Uses WorkItem.ToString() } } // Mark task as completed WorkItem taskToComplete = repository.Get(id); if (taskToComplete != null) { taskToComplete.IsCompleted = true; repository.Update(taskToComplete); repository.SaveChanges(); Console.WriteLine("Task marked as completed."); } // Remove a task bool removed = repository.Remove(id); if (removed) { repository.SaveChanges(); Console.WriteLine("Task removed from repository."); } ``` -------------------------------- ### Define and Use WorkItem Domain Model in C# Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Demonstrates how to create, populate, and interact with the WorkItem class, which represents a task with properties like title, description, due date, priority, and completion status. It supports cloning and formatted string output. This class is fundamental for task management within the application. ```csharp using Ivanyshen.TaskPlanner.Domain.Models; using Ivanyshen.TaskPlanner.Domain.Models.Enums; // Create a new work item with full details var task = new WorkItem( title: "Implement authentication feature", description: "Add JWT-based authentication to the API", dueDate: new DateTime(2025, 12, 31), priority: Priority.High, complexity: Complexity.Days ); // Access properties Console.WriteLine($"Task ID: {task.Id}"); Console.WriteLine($"Created: {task.CreationDate}"); Console.WriteLine($"Due: {task.DueDate:dd.MM.yyyy}"); Console.WriteLine($"Priority: {task.Priority}"); Console.WriteLine($"Completed: {task.IsCompleted}"); // Clone a work item (creates new GUID) var clonedTask = task.Clone(); // ToString() provides formatted output Console.WriteLine(task.ToString()); // Output: "Implement authentication feature: due 31.12.2025, high priority" ``` -------------------------------- ### Create Prioritized Task Plans with SimpleTaskPlanner in C# Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Illustrates the functionality of SimpleTaskPlanner, which generates a prioritized list of incomplete tasks. Tasks are sorted by priority (highest first), then by due date (earliest first), and finally alphabetically by title. This planner relies on an underlying repository for task data. ```csharp using Ivanyshen.TaskPlanner.Domain.Logic; using Ivanyshen.TaskPlanner.DataAccess; using Ivanyshen.TaskPlanner.Domain.Models; using Ivanyshen.TaskPlanner.Domain.Models.Enums; var repository = new FileWorkItemsRepository(); // Add multiple tasks with different priorities and due dates repository.Add(new WorkItem { Title = "Write documentation", DueDate = DateTime.Now.AddDays(10), Priority = Priority.Low, IsCompleted = false }); repository.Add(new WorkItem { Title = "Deploy to production", DueDate = DateTime.Now.AddDays(2), Priority = Priority.Urgent, IsCompleted = false }); repository.Add(new WorkItem { Title = "Code review", DueDate = DateTime.Now.AddDays(5), Priority = Priority.High, IsCompleted = false }); repository.Add(new WorkItem { Title = "Already done task", DueDate = DateTime.Now.AddDays(1), Priority = Priority.Urgent, IsCompleted = true // This will be excluded }); repository.SaveChanges(); // Create a plan var planner = new SimpleTaskPlanner(repository); WorkItem[] plan = planner.CreatePlan(); // Display the prioritized plan foreach (var task in plan) { Console.WriteLine(task.ToString()); } // Output (sorted by priority desc, then due date asc): // "Deploy to production: due 16.12.2025, urgent priority" // "Code review: due 19.12.2025, high priority" // "Write documentation: due 24.12.2025, low priority" ``` -------------------------------- ### C# Unit Test: Mocking Repository for Excluding Completed Tasks Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Tests the CreatePlan method to ensure that only incomplete work items are included in the generated plan. It mocks the repository to return a mix of completed and pending tasks and asserts that only the pending task is present in the output. ```csharp // Test that completed tasks are excluded [Fact] public void CreatePlan_ExcludesCompletedTasks() { var mockRepo = new Mock(); var tasks = new[] { new WorkItem { Title = "Done", IsCompleted = true }, new WorkItem { Title = "Pending", IsCompleted = false } }; mockRepo.Setup(repo => repo.GetAll()).Returns(tasks); var planner = new SimpleTaskPlanner(mockRepo.Object); WorkItem[] plan = planner.CreatePlan(); Assert.Single(plan); Assert.Equal("Pending", plan[0].Title); } ``` -------------------------------- ### JSON Format for Work Item Storage Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Illustrates the JSON structure used for persisting work items to 'work-items.json'. Properties are in camelCase, and the format is indented for readability. Includes fields like id, creationDate, title, description, dueDate, priority, complexity, and isCompleted. ```json [ { "id": "bc7d23e9-b361-4b0d-850b-dfbf538cb52f", "creationDate": "2025-10-25T13:18:19.0182375+03:00", "title": "Implement API endpoint", "description": "Create REST endpoint for user management", "dueDate": "2025-12-31T00:00:00Z", "priority": 3, "complexity": 2, "isCompleted": false }, { "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d", "creationDate": "2025-11-01T09:30:00.0000000+02:00", "title": "Write unit tests", "description": "Add test coverage for new features", "dueDate": "2025-12-15T00:00:00Z", "priority": 2, "complexity": 3, "isCompleted": false } ] ``` -------------------------------- ### Implement FileWorkItemsRepository for JSON Persistence in C# Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Shows how to use the FileWorkItemsRepository for CRUD operations on WorkItems, with automatic JSON serialization and in-memory caching. Modifications must be explicitly saved using SaveChanges() to persist to disk. It handles adding, retrieving, updating, and removing tasks. ```csharp using Ivanyshen.TaskPlanner.DataAccess; using Ivanyshen.TaskPlanner.Domain.Models; using Ivanyshen.TaskPlanner.Domain.Models.Enums; var repository = new FileWorkItemsRepository(); // Add a new work item var newTask = new WorkItem { Title = "Fix login bug", Description = "Users cannot login with special characters", DueDate = DateTime.Now.AddDays(3), Priority = Priority.Urgent, Complexity = Complexity.Hours, IsCompleted = false }; Guid taskId = repository.Add(newTask); repository.SaveChanges(); // Retrieve a specific work item WorkItem retrievedTask = repository.Get(taskId); if (retrievedTask != null) { Console.WriteLine($"Found: {retrievedTask.Title}"); } // Get all work items WorkItem[] allTasks = repository.GetAll(); Console.WriteLine($"Total tasks: {allTasks.Length}"); // Update an existing work item retrievedTask.IsCompleted = true; bool updateSuccess = repository.Update(retrievedTask); repository.SaveChanges(); // Remove a work item bool removeSuccess = repository.Remove(taskId); repository.SaveChanges(); ``` -------------------------------- ### C# Priority Enumeration Definition and Usage Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Defines the Priority enum for task urgency levels (None to Urgent) and shows how to parse from and convert to strings. It is used within the Ivanyshen.TaskPlanner.Domain.Models.Enums namespace. ```csharp using Ivanyshen.TaskPlanner.Domain.Models.Enums; // Available priority levels Priority none = Priority.None; // 0 Priority low = Priority.Low; // 1 Priority medium = Priority.Medium; // 2 Priority high = Priority.High; // 3 Priority urgent = Priority.Urgent; // 4 // Parse from string (case-insensitive) if (Enum.TryParse("High", true, out var priority)) { Console.WriteLine($"Parsed priority: {priority}"); } // Convert to string string priorityName = Priority.High.ToString().ToLower(); Console.WriteLine(priorityName); // "high" ``` -------------------------------- ### C# Complexity Enumeration Definition and Usage Source: https://context7.com/maxivanyshen/vntu-dotnet/llms.txt Defines the Complexity enum for task time estimation (None to Weeks) and demonstrates parsing from string input. It belongs to the Ivanyshen.TaskPlanner.Domain.Models.Enums namespace. ```csharp using Ivanyshen.TaskPlanner.Domain.Models.Enums; // Available complexity levels Complexity none = Complexity.None; // 0 Complexity minutes = Complexity.Minutes; // 1 Complexity hours = Complexity.Hours; // 2 Complexity days = Complexity.Days; // 3 Complexity weeks = Complexity.Weeks; // 4 // Parse from user input if (Enum.TryParse("Days", true, out var complexity)) { Console.WriteLine($"Task complexity: {complexity}"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.