Skip to content

About

Simple solution for mocking date properties with private setters in C#.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

126 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DateOverride

Azure DevOps builds Azure DevOps builds Sonar Coverage Nuget Nuget

DateOverride is a simple solution for mocking date properties with private setters in C#.

Dependencies

Install

  • Package Manager Console

Install-Package DateOverride
  • .Net CLI

dotnet add package DateOverride

How to use

DateOverride can set any DateTime or DateTimeOffset property, with the SetDate() extension method, trough the following syntax:

object.SetDate(property, date);

Where:

  • obejct : the object containing the property to be set
  • property : the property name as a string
  • date : the date which to set the property

Sample

public class Item
{
    public DateTime CreatedAt { get; private set; }
}

[Fact]
public void Should_set_DateTime()
{
    //Arrange
    var item = new Item();   
    
    var today = DateTime.Now;
    var tomorrow = DateTime.Now.AddDays(1);
    
    //Act
    item.SetDate(nameof(item.CreatedAt), tomorrow);
    
    //Assert
    item.Date.Should().BeAfter(today);
}

Contributions

Contributions and feature requests are always welcome.

About

Simple solution for mocking date properties with private setters in C#.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages