LucidCode library

LucidCode library


Some time ago I’ve created a library with a few simple but useful extensions.

Note: LucidCode is an opinionated library, that helps me in my daily developer work. It doesn’t mean it will be perfect for everyone :)

LucidCode contains a few useful methods, like In, NotIn, ToNullIfEmpty, etc. Here are some examples:

bool IsMyFavouriteColor => ColorInput.ToLower().In("green", "blue");

string Address => EmployeeAdressInput.ToNullIfWhiteSpace() ?? DefaultCompanyAddress;

The full list of methods can be found on the LucidCode source page.

Support for Arrange Act Assert pattern – LucidTest

Arrange Act Assert pattern (AAA) is a very powerful pattern for writing tests. The problem for me is that usually the AAA implementation is done by adding comments in the test code. I don’t like this approach. I believe the code should be self-explanatory as much as possible. Meaning the comments should be reserved only for very complicated cases, but not as a pattern for every test.

Therefore I’ve added LucidTest to LucidCode. It contains a set of extension methods and classes to support the AAA pattern.

Here is an AAA example with comments:

        public void Test_NameProvider()
            // Arrange
            var nameProvider = new NameProvider();

            // Act
            var userName = nameProvider.GetUserName(0);

            // Assert

And the same test using LucidTest:

        public void Test_NameProvider() => LucidTest
            .Arrange(() => new NameProvider())
            .Act(provider => provider.GetUserName(0))
            .Assert(result => result.ShouldBe("Admin"));

LucidTest async support

I also extended the library for async/await support. One can start with normal code (not async) to do Arrange action and then do async operations – example:

        public Task Test_NameProvider() => LucidTest
            .Arrange(() => new NameProvider())
            .ActAsync(provider => provider.GetUserNameAsync(0))
            .AssertAsync(result => result.ShouldBe("Admin"));

Or go with full async since the beginning – example:

        public Task Test_NameProvider2() => LucidTest
            .ArrangeAsync(() => GetProviderAsync())
            .ActAsync(provider => provider.GetUserNameAsync(0))
            .AssertAsync(result => result.ShouldBe("Admin"));


That’s all! Let me know if you find it useful.



Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.