Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Simplify.System

i4004 edited this page Oct 1, 2014 · 5 revisions

Provides classes to get assembly information and ambient context for wrapping DateTime.Now, DateTime.UtcNow, DateTime.Today properties.

Available at NuGet as binary package and source package

Getting assembly information

Provides IAssemblyInfo interface and AssemblyInfo class to get assembly information.

With AssemblyInfo you can get assembly version, product name, description, copyright, company name information.

General usage

AssemblyInfo.Entry static ambient context provides information about Entry assembly.

Custom usage

AssemblyInfo can be instantiated to get specified assembly information:

 var assemblyInfo = new AssemblyInfo(Assembly.GetAssembly(typeof(SomeClass)));

Mocking DateTime.Now, DateTime.UtcNow, DateTime.Today

Provides ITimeProvider interface and TimeProvider class for mocking and using DateTime.Now, DateTime.UtcNow, DateTime.Today properties.

With TimeProvider.Current ambient context you can easily get actual DateTime.Now, DateTime.UtcNow, DateTime.Today properties or mock them when you want.

By default TimeProvider.Current initialized with SystemTimeProvider class which wraps system DateTime.Now, DateTime.UtcNow, DateTime.Today properties.

Usage example

// Will return actual DateTime.Now
 var currentTime = TimeProvider.Current.Now;

Mocking example with Moq

var fakeTimeProvider = new Mock<ITimeProvider>();
fakeTimeProvider.SetupGet(x => x.Now).Returns(new DateTime(2014, 10, 10));
TimeProvider.Current = fakeTimeProvider.Object;

// Will return fake value
var time = TimeProvider.Current.Now;