Testing and Debugging

The StringlyTyped project implements value objects. The following outline describes the testing strategies and debugging techniques used to ensure correctness and reliability of the implementation.

Testing

The project employs unit testing to validate the behavior of the Value Object implementation. These tests cover aspects like:

  • Equality: Verifies that two Value Objects are considered equal if they have the same underlying values. This includes comparing Value Objects with each other, with primitives, and with objects. This is achieved using Fact attributes in ValueObjectTests.cs.
    • Example:
      [Fact]
                public void equality_between_same_value_objects()
                {
                    Age.From(18).Equals(Age.From(18)).Should().BeTrue();
                    (Age.From(18) == Age.From(18)).Should().BeTrue();
                    
                    (Age.From(18) != Age.From(19)).Should().BeTrue();
                    (Age.From(18) == Age.From(19)).Should().BeFalse();
                }
                
  • Validation: Ensures that the constructor of a Value Object enforces the expected constraints on the input values. This is validated using the Should().ThrowExactly() method within the ValueObjectTests.cs file.
  • Example:
    [Fact]
              public void validation()
              {
                  Func act = () => Age.From(12);
                  act.Should().ThrowExactly();
              
                  Func act2 = () => EightiesDate.From(new DateTime(1990, 1,1));
                  act2.Should().ThrowExactly();
              
                  Func act3 = () => EightiesDate.From(new DateTime(1985, 6,10));
                  act3.Should().NotThrow();
              }
              
  • Nullness: Verifies that the constructor correctly handles null input values when applicable. The Should().ThrowExactly() method is used for this.
  • Example:
    [Fact]
              public void nullness()
              {
                  (Age.From(50) == null).Should().BeFalse();
                  Age.From(50).Equals(null).Should().BeFalse();
                  
                  (Age.From(50) != null).Should().BeTrue();
                  
                  Func act = () => Daves.From(null);
                  act.Should().ThrowExactly();
              }
              
  • Hashing: Checks that the GetHashCode() method returns consistent and correct hash values for Value Objects.
    • Example:
      [Fact]
                public void hashing()
                {
                    (Age.From(18).GetHashCode() == Age.From(18).GetHashCode()).Should().BeTrue();
                    (Age.From(18).GetHashCode() == Age.From(19).GetHashCode()).Should().BeFalse();
                    (Age.From(18).GetHashCode() == Score.From(1).GetHashCode()).Should().BeFalse();
                    (Age.From(18).GetHashCode() == Score.From(18).GetHashCode()).Should().BeFalse();
                }
                
  • To String: Tests the behavior of the ToString() method to ensure it provides a meaningful string representation.
    • Example:
      [Fact]
                public void to_string()
                {
                    Age.From(18).ToString().Should().Be("18");
                    Age.From(100).ToString().Should().Be("100");
                    Age.From(1_000).ToString().Should().Be("1000");
                }
                

Debugging

The project leverages the Visual Studio debugger for stepping through code, inspecting variables, and understanding program execution flow. The following tools are used for debugging:

  • Breakpoints: Used to pause execution at specific locations in the code.
  • Watch Window: Allows monitoring the values of variables during execution.
  • Call Stack: Provides insight into the function call sequence that led to the current execution point.

Additional Information

The project utilizes the following tools for testing and debugging:

  • xUnit: Used for unit testing.
  • FluentAssertions: Provides a more readable syntax for asserting expectations in tests.
  • Visual Studio Debugger: The primary tool for debugging.

Code Files

The following code files are relevant to testing and debugging:

  • tests/StringlyTyped.SmallTests/ValueObjectTests.cs: Contains the unit tests for value object functionality.
  • src/StringlyTyped/ValueObject.cs: Implements the base class for Value Objects.
  • src/StringlyTyped/obj/Debug/net461/StringlyTyped.AssemblyInfo.cs: Contains assembly information, including debugging symbols.

This outline provides a basic understanding of the testing and debugging practices used in the StringlyTyped project. It is important to note that these practices may evolve as the project grows and requirements change.

Top-Level Directory Explanations

samples/ - This directory contains example projects demonstrating the usage of StringlyTyped library.

src/ - This directory contains the source code of the StringlyTyped library.

tests/ - This directory contains unit tests for the StringlyTyped library. It includes benchmark tests and small tests.