-
C#樹林
[C#]Fixing Return Values and Tracking Property Changes with Moq
Overview This article explains how to define the behavior of interface properties using the Moq library for .NET unit testing. We will cover two patterns: "read-only" behavior that returns a fixed value, and "auto-implemented" behavior t... -
C#樹林
【C#】Moqでプロパティの戻り値固定と値の保持(追跡)を実装する方法
概要 .NETの単体テストにおけるモックライブラリ「Moq」を使用して、インターフェースのプロパティの振る舞いを定義する方法です。 単に値を返すだけの「読み取り専用」のような振る舞いと、値の代入を記憶して保持する「自動実装プロパティ」のような振る... -
C#樹林
Getting Started with Moq in C# (Generating Mock Objects)
Overview "Moq" is a library used in unit testing to separate "external dependencies" such as databases or external APIs. This allows you to verify only the logic of the object you are testing. With Moq, you can easily create "fake object... -
C#樹林
【C#】Moqの利用を開始したい(Mockオブジェクトの生成)
概要 単体テストにおいて、データベースや外部APIなどの「外部依存」を切り離し、テスト対象のロジックだけを検証するために使われるライブラリが「Moq(モック)」です。 Moqを使用すると、インターフェースを実装した「偽物のオブジェクト(Mock)」を簡... -
C#樹林
[C#]Outputting Debug Messages in xUnit.net Unit Tests
Overview When executing tests in xUnit.net, standard Console.WriteLine statements do not display output. Instead, you must receive the ITestOutputHelper interface via the constructor (Dependency Injection) and use its WriteLine method. T... -
C#樹林
【C#】xUnit.netの単体テストでデバッグメッセージを出力する
概要 xUnit.netのテスト実行時には、通常の Console.WriteLine を使用しても出力が表示されません。 代わりに ITestOutputHelper インターフェースをコンストラクタ経由で受け取り(依存性注入)、その WriteLine メソッドを使用することで、テストエクス... -
C#樹林
[C#]Supplying Test Data from External Methods with MemberData in xUnit.net
Overview This implementation uses the [MemberData] attribute in xUnit.net to dynamically supply parameters to test methods from static methods or properties. It is suitable for managing "arrays," "objects," "dynamically generated data," ... -
C#樹林
【C#】MemberData属性でテストデータを外部メソッドから供給する
概要 xUnit.netの [MemberData] 属性を使用し、テストメソッドに渡すパラメータを静的メソッド(またはプロパティ)から動的に供給する実装です。 [InlineData] では扱いにくい「配列」「オブジェクト」「動的に生成されるデータ」や「多数のテストケース... -
C#樹林
[C#]Parameterized Tests Using InlineData in xUnit.net (Data-Driven Testing)
Overview By combining the [Theory] and [InlineData] attributes in xUnit.net, you can execute a single test method multiple times with different input patterns. This is called "Parameterized Testing" or "Data-Driven Testing." It is an eff... -
C#樹林
【C#】InlineData属性を使用したパラメータ化テスト(データ駆動テスト)
概要 xUnit.netの [Theory] 属性と [InlineData] 属性を組み合わせることで、1つのテストメソッドに対して複数の異なる入力パターンを連続して実行できます。 これを「パラメータ化テスト(Parameterized Tests)」または「データ駆動テスト」と呼び、境界... -
C#樹林
[C#]Setup and Teardown in xUnit.net (Constructor and Dispose)
Overview In xUnit.net, a new instance of the test class is created for every test method and destroyed once the test is complete. By utilizing this lifecycle, it is standard practice to write "Setup" in the constructor and "Teardown" in ... -
C#樹林
【C#】xUnit.netでのテスト前処理・後処理(コンストラクタとDispose)
概要 xUnit.netでは、テストメソッドを実行するたびにテストクラスのインスタンスが新しく生成され、終了時に破棄されます。 このライフサイクルを利用して、コンストラクタに「前処理(Setup)」を、IDisposable インターフェースの Dispose メソッドに「... -
C#樹林
[C#]Testing if a Specific Exception Occurs with xUnit.net
Overview This implementation verifies whether a specific exception occurs as expected when a method is executed. Using the Assert.Throws<T> method in xUnit.net, a test succeeds if the specified exception is thrown within the proces... -
C#樹林
【C#】xUnit.netで特定の例外が発生するか検証する
概要 メソッド実行時に期待した通りの例外(エラー)が発生するかをテストする実装です。 xUnit.netの Assert.Throws<T> メソッドを使用すると、内部の処理で指定した例外がスローされればテスト成功、スローされなければ(または違う例外が出れば)... -
C#樹林
Testing if a Value is Within a Specific Range with xUnit.net in C#
Overview This implementation uses the Assert.InRange method in xUnit.net to verify if a test result is between a specific minimum and maximum value (inclusive). It works for integers, dates (DateTime), floating-point numbers, and any typ... -
C#樹林
【C#】xUnit.netで値が指定範囲内に収まっているか検証する
概要 xUnit.netの Assert.InRange メソッドを使用して、テスト結果の値が特定の最小値と最大値の範囲内(境界値を含む)にあるかを検証する実装です。 整数だけでなく、日付(DateTime)や浮動小数点数など、IComparable を実装しているすべての型に対して... -
未分類
[C#] Verifying Return Values and State with xUnit.net Assert Methods
Overview This implementation covers basic assertions in xUnit.net to determine if the execution result of a target method matches expectations. It encompasses techniques for verifying value equality (Equal), boolean values (True/False), ... -
C#樹林
【C#】xUnit.netのAssertメソッドによる戻り値と状態の検証
概要 xUnit.netにおいて、テスト対象メソッドの実行結果が期待通りであるかを判定するための基本的な検証(アサーション)実装です。 値の等価性(Equal)、真偽値(True/False)、nullチェック、およびオブジェクトの参照同一性(Same)を確認する手法を... -
C#樹林
[C#] Introduction to xUnit.net and Writing Basic Unit Tests
Overview This implementation introduces "xUnit.net," a widely used testing framework in .NET development, and demonstrates the minimal test code required to verify method behavior. It covers the steps to build an automated testing enviro... -
C#樹林
【C#】xUnit.netの導入と基本的な単体テストの記述
概要 .NET開発で広く利用されているテストフレームワーク「xUnit.net」をプロジェクトに導入し、メソッドの動作を検証する最小限のテストコードを実装します。 Visual StudioやCI/CD環境で自動実行可能なテスト環境を構築するための手順と、基本的なアサー... -
C#樹林
[C#] How to Define and Apply Paragraph Styles in Word Documents using OpenXML
Overview This implementation demonstrates how to programmatically apply "styles," such as headings or emphasis, to a Word document. When handling styles in OpenXML, simply specifying a Style ID is insufficient; the style definition itsel... -
C#樹林
【C#】OpenXMLで段落にスタイルを定義して適用する
概要 Word文書において、見出しや強調表示などの「スタイル」をプログラムから適用する実装です。 OpenXMLでスタイルを扱う場合、単にスタイルIDを指定するだけでは不十分で、そのスタイル定義自体が文書内(styles.xml)に存在する必要があります。ここで... -
C#樹林
[C#] How to Insert Paragraphs at Specific Positions in Existing Word Documents Using OpenXML
Overview This implementation demonstrates how to open an existing Word file (.docx) and insert a new paragraph "before" a specified reference paragraph. In the OpenXML SDK, you can interject new elements at any position within the docume... -
C#樹林
【C#】OpenXMLで既存のWord文書の特定位置に段落を挿入する
概要 作成済みのWordファイル(.docx)を開き、指定した段落の「前」に新しい段落を挿入する実装です。 OpenXML SDKでは Body 要素が持つ InsertBefore メソッドを使用することで、文書構造の任意の位置に新しい要素を割り込ませることができます。 仕様(... -
C#樹林
[C#] How to Set Paragraph Alignment (Left, Center, Right) in Word Documents with OpenXML SDK
Overview When creating Word documents using the OpenXML SDK, you can programmatically control the alignment of each paragraph (Left, Center, Right, Justified/Both). This is achieved by adding the Justification information inside the Para... -
C#樹林
【C#】OpenXML SDKでWord文書の段落配置(左・中央・右揃え)を設定する
概要 OpenXML SDKを使用してWord文書を作成する際、段落ごとの配置(左揃え、中央揃え、右揃え、両端揃えなど)をプログラムから制御する実装です。 段落のプロパティ(ParagraphProperties)内に配置情報(Justification)を追加することで、テキストの位... -
C#樹林
[C#] How to Create New Word Documents and Write Text Using OpenXML SDK
Overview This implementation creates .docx Word files in environments where Microsoft Word is not installed (such as servers or Linux). Using the "OpenXML SDK" provided by Microsoft, we programmatically construct the Word document struct... -
C#樹林
【C#】OpenXML SDKでWord文書を新規作成してテキストを書き込む
概要 Microsoft Wordがインストールされていない環境(サーバーやLinuxなど)で、.docx 形式のWordファイルを新規作成する実装です。 Microsoftが提供する「OpenXML SDK」を使用し、Word文書の構造(Document, Body, Paragraph, Run, Text)をプログラムか... -
C#樹林
[C#] How to Set Background Colors and Borders in Excel Using NPOI
Overview This implementation uses the NPOI library to apply formatting (styles) such as cell background colors, borders, and font colors to an Excel sheet. Styling in NPOI follows a specific procedure: first, you "create a style object,"... -
C#樹林
【C#】NPOIを使ってExcelのセルに背景色や罫線を設定する
概要 NPOIを使用して、セルの背景色、罫線、フォントカラーなどの書式設定(スタイル)を適用する実装です。 Excelのスタイル設定は「スタイルオブジェクトを作成」し、それを「セルに割り当てる」という手順で行います。 仕様(入出力) 入力: 保存先パス...