Moonglade

Modern Markdown blogging with AI-powered localization and search.

All Posts


5-Minute Introduction to .NET Unit Testing ★

This article is an introductory tutorial on C# unit testing. Using BookService as an example, it provides a detailed demonstration of the complete process of writing tests with xUnit, NSubstitute, and FluentAssertions. The article first introduces the basic construction of test classes, including creating mock objects with NSubstitute, initializing the system under test, and preparing test data. It then focuses on writing test methods, distinguishing between the [Fact] and [Theory] attributes: [Fact] is used for testing a single scenario and follows the standard Arrange (setup), Act (execution), and Assert (verification) structure; [Theory] combined with [InlineData] supports multiple sets of input parameters, making it particularly suitable for verifying exception throwing or boundary conditions. The tutorial also demonstrates how to use Arg.Any<T> to handle arbitrary parameters, and introduces methods for running tests and viewing results via the dotnet test command or an IDE. The article emphasizes improving code readability through normalized test method naming conventions (such as Method_Scenario_ExpectedResult), and points out that unit testing can effectively prevent missed parameter validation, making it an important practice for ensuring code quality.

Views 278
.NET Test nsubstitute tdd unit testing xunit

Struggling to debug production microservices? Get to know OpenTelemetry. ★

Struggling to debug production microservices? Get to know OpenTelemetry.

This article provides an in-depth introduction to the concept of observability and the application of OpenTelemetry in .NET microservice systems. It begins with a practical case study running on K8s, demonstrating how to leverage OpenTelemetry and Jaeger to implement distributed tracing. This allows for visual analysis of request latency and paths across various services, enabling precise identification of performance bottlenecks. Subsequently, the article elaborates on the three pillars of OpenTelemetry: Traces, Metrics, and Logs. Traces associate dispersed request contexts through Spans, providing a full-chain view. Metrics serve as aggregated numerical data for monitoring infrastructure status, service performance, and business metrics, supporting various instrument types and aggregation methods. Logs address the pain points of traditional logging in distributed systems, such as lack of context correlation, inconsistent data models, and integration difficulties, thereby achieving seamless association between logs, traces, and metrics. Through a unified data model and standardized protocols, OpenTelemetry helps developers collect telemetry data cross-platform and cross-language, quickly diagnose production issues, optimize system performance, and enhance overall system observability and stability, providing robust support for fault troubleshooting and business analysis in microservice architectures.

Views 136
.NET Distributed Tracing Jaeger Microservices Observability OpenTelemetry

Why Is My API Slow as a Snail? Series Table of Contents and Guide ★

This series of articles aims to address the challenges of slow API response times and difficult fault debugging in production environments, systematically introducing methods for analyzing and handling online issues. The first part focuses on how to use Serilog to configure comprehensive structured logging, capturing critical timing and diagnostic information, and leveraging Seq for centralized log management, thereby helping developers easily analyze logs and quickly pinpoint performance bottlenecks. The second part delves into the application of OpenTelemetry, demonstrating how to achieve correlated analysis of distributed tracing, metrics, and logs through a unified framework, thereby enhancing the reliability and operational efficiency of software systems. This series is suitable for developers and operations personnel who wish to optimize system performance, monitor runtime status, and rapidly identify root causes. All articles are simultaneously published on WeChat Official Accounts and both domestic and international blog platforms, facilitating multi-platform reading and learning for readers.

Views 173
.NET OpenTelemetry Performance Serilog performance analysis structured logging


Quick Start: VS Code Python Development Environment Setup Guide (2025 Edition)

This article provides a detailed demonstration of the complete process for building an efficient Python development environment using `uv`, `Ruff`, and `Ty`. First, it covers managing virtual environments and dependencies with `uv`, leveraging its high-performance characteristics to quickly install libraries such as `numpy`, `pandas`, and `Streamlit`. It also demonstrates how to configure domestic mirror sources to accelerate the download of large packages. Next, it delves into configuring VS Code with the `Ruff` plugin to automatically format code, clean up unused imports, and auto-fix syntax issues upon saving, significantly enhancing code cleanliness and development efficiency. Following this, the `Ty` tool is introduced for static type checking, complementing `Ruff`'s limitations in type safety by detecting potential type errors before code execution, with real-time diagnostics enabled via a VS Code plugin. Finally, the article compares the applicable scenarios of `Anaconda` and `uv`, recommending that beginners or research collaboration environments continue using `Anaconda`, while enterprise-level developers or advanced users pursuing ultimate efficiency and code quality should prioritize the combination of `uv`, `Ruff`, and `Ty` to achieve a more concise, fast, and standardized Python development experience.

Views 523
Python VS Code VSCode ruff ty uv

Linux Docker root and rootless modes

This article provides an in-depth analysis of the core differences between Docker in Root mode and Rootless mode. Root mode operates at the system-wide level, storing data in `/var/lib/docker`. It offers full privileges but has lower security. Rootless mode runs with regular user permissions, isolates data within the user directory, and leverages user namespace technology to enhance security and enable independent instances for multiple users. However, it is limited by CPU and I/O constraints and certain network functionalities. The article points out that because the data storage and service configurations of the two modes are completely independent, they cannot share images and containers. Based on the current actual needs, which do not require advanced features, the author decided to disable Root mode and fully adopt Rootless mode. The text details how to manage user-level services using `systemctl --user`, corrects the misconception that `systemctl` is limited to system-level usage, and compares the configuration file paths, socket locations, and storage directories in both modes. Additionally, it discusses the Rootless capabilities of applications such as Podman and Caddy, summarizes the advantages and limitations of Rootless mode in development, testing, and shared hosting scenarios, and provides a practical guide for managing containers more securely and flexibly in a Linux environment.

Views 551
AnduinOS Docker comparison-analysis configuration-management docker-containerization linux-containers rootless-docker security-best-practices

Find Your Clipboard Assistant for AnduinOS

This article documents the author's process of migrating tools after switching from Windows to AnduinOS, a GNOME-based distribution, in order to address the lack of a multi-entry clipboard history feature. The article first explains the importance of the built-in clipboard tool in Windows 11 for development scenarios. It then describes how to install and configure the GNOME extension `clipboard-indicator` on AnduinOS as an alternative. The core steps include: first, verifying the GNOME Shell version via the command line and selecting the matching extension version based on the official support list (e.g., GNOME 42 corresponds to `v47`); second, downloading the specified version's archive from the GNOME Extensions website and extracting it into the specific folder under the `/usr/share/gnome-shell/extensions` directory; finally, enabling the extension using the `gnome-extensions enable` command. After installation, users can find the clipboard icon in the status bar and customize settings and shortcuts. It is recommended to set the shortcut to `win+v` to replicate the Windows experience. The article specifically notes that in terminal environments, copy and paste must be performed using `ctrl+shift+c` and `ctrl+shift+v` to avoid conflicts with default terminal control commands. This extension effectively resolves efficiency pain points in the new system, providing developers with smooth, rapid multi-text transfer capabilities, significantly improving...

Views 195
AnduinOS GNOME extensions Windows alternative clipboard productivity tool terminal

How to Enjoyably Develop .NET with AnduinOS

This article aims to provide .NET developers with a guide for setting up a development environment in VSCode on AnduinOS or any Linux system that closely mimics the Visual Studio experience. It begins by noting that, due to the lack of a free Visual Studio and the absence of a Rider Community Edition, VSCode emerges as an ideal alternative. The core content recommends the C# extension and its key settings, such as enabling OmniSharp decompilation support, EditorConfig, and the Roslyn analyzer, to enhance basic functionality. For advanced needs, it introduces the C# Dev Kit and its intelligent completion components, while cautioning about its commercial licensing restrictions and account login requirements. Additionally, it recommends Roslynator as a lightweight alternative for code analysis and refactoring, along with practical plugins for automatically generating XML documentation comments and completing namespaces. The article also briefly discusses the pros and cons of GitHub Copilot. The author emphasizes that these configurations can significantly improve development efficiency and invites readers to share further optimization suggestions, aiming to help developers achieve a smoother C# development experience on Linux platforms.

Views 312
.NET AnduinOS C# VSCode development-environment dotnet github-copilot vscode-plugins

Reflections on Design Patterns in Software Development

As a senior .NET developer, the author reflects on the dangers of blindly advocating design patterns and rigid thinking in software development, advocating for critical thinking and flexible application. The author argues that tools should serve actual needs rather than dogma, pointing out that JavaScript, with its full-stack capabilities and rich ecosystem, holds immense value in both front-end and back-end development. To this end, the author used GPT-4 to convert video tutorials into text and wrote the concise tutorial "JavaScript: From Beginner to Off the Rails." This book is designed specifically for experienced engineers, covering core concepts such as variables and asynchronous programming. It aims to help readers quickly master JS skills, break free from dependence on a single tech stack, adapt to a rapidly changing technological environment, and achieve the transition from novice to proficient developer.

Views 169
JavaScript beginner-tutorial high-concurrency programming rapid-development web-development

How to Develop a Large Language Model Chatbot in 5 Minutes

This article aims to guide readers in quickly developing a chatbot based on a large language model within 5 minutes, serving as an introductory practice for exploring LLM application development. The tutorial uses Python combined with the LlamaIndex and Gradio libraries, leveraging the free API provided by the Groq platform to host the Llama3-70b model, achieving a low-cost solution that runs smoothly without requiring a high-performance GPU. The development workflow covers managing dependencies with Poetry, creating the project structure, configuring API keys to ensure security, and writing the core code logic. The core section uses LlamaIndex to construct a message list containing the system prompt, conversation history, and current input, and calls the stream_chat method to implement streaming responses, simulating a natural typing effect; simultaneously, it utilizes Gradio to quickly build a web interactive interface, supporting context memory functionality. The article also demonstrates how to generate a shared link for others to access via the share parameter, and tests the model's capabilities through a series of fun and challenging questions, verifying its performance in logical reasoning and context retention. Although there are minor flaws such as occasionally ignoring translation instructions, this solution demonstrates the powerful performance of Llama3-70b among open-source models, providing developers with an effective path to advance from basic chatbots to more complex LLM applications.

Views 534
AI chatbot gradio llama3 70b poetry stream chat