Giter VIP home page Giter VIP logo

cleanmoq's Introduction

CleanMoq

CleanMoq

Nuget Nuget The Standard Community

Introduction

This is CleanMoq a branch of the popular Moq library.

All copyrights of use can be found in the license text here

CleanMoq is a mocking library for .NET developers to take full advantage of .NET Linq expression trees and lambda expressions, which makes it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn't require any prior knowledge or experience with mocking concepts.

Purpose

For use in engineering standard compliant systems. We take the utmost opinion that no bots or obtrusive hidden features without consent are intruduced into the background of any of our dependent libraries with the highest regard.
This forked branch of the original Moq library was born to do just that, to protect all our systems from future potential unwarranted harms. Please use with confidence in building your Standard Compliant systems.

Roadmap

On August 4, 2023 SponserLink was introduced in the 4.20.0 version of the Moq library by its creators, and on August 9, 2023 it was removed via the proj file only after the Apple systems failed to build.

Moq Version 4.20.69 released on August 11, 2023 states SponsorLink removal via pull request #1375. Again only with the removal of the project reference. SponsorLink is still a viable potential threat of being reimplemented at any givin point in time as the coding for it still resides within this current version v4.20.69.

CleanMoq was forked from Moq version 4.20.0 where all reference coding to SponsorLink has been removed not just the project reference within the Moq.CodeAnalysis project file.

It has been completely removed in CleanMoq.

Version 1.0.0 is the beginning of CleanMoq, it is the version 4.20.0 without the spyware.

CleanMoq will be enhanced to standard principles as required and versioning forward will commence from version 1.0.0.

CleanMoq may or may not be updated with future enhancements of the original Moq library as it progresses towards the future.

CleanMoq will stand as its own library into the future, we hope we can build everyones confidence in using it without worry or concerns.

The motto remains the same in The Standard Community (A Coalition of Good-Hearted Engineers)

Standard-Promise

The most important fulfillment aspect in a Standard complaint system is aimed towards contributing to people, its evolution, and principles. An organization that systematically honors an environment of learning, training, and sharing knowledge is an organization that learns from the past, makes calculated risks for the future, and brings everyone within it up to speed on the current state of things as honestly, rapidly, and efficiently as possible.

We believe that everyone has the right to privacy, and will never do anything that could violate that right. We are committed to writing ethical and responsible software, and will always strive to use our skills, coding, and systems for the good. We believe that these beliefs will help to ensure that our software(s) are safe and secure and that it will never be used to harm or collect personal data for malicious purposes.

The Standard Community as a promise to you is in upholding these values.

How to install

Install from NuGet.

How to use

Standard compliant sample setup for service dependencies

   public partial class AIFileServiceTests
    {
        private readonly Mock<IOpenAIBroker> openAIBrokerMock;
        private readonly Mock<IDateTimeBroker> dateTimeBrokerMock;
        private readonly ICompareLogic compareLogic;
        private readonly IAIFileService aiFileService;

        public AIFileServiceTests()
        {
            this.openAIBrokerMock = new Mock<IOpenAIBroker>();
            this.dateTimeBrokerMock = new Mock<IDateTimeBroker>();
            this.compareLogic = new CompareLogic();

            this.aiFileService = new AIFileService(
                openAIBroker: this.openAIBrokerMock.Object,
                dateTimeBroker: this.dateTimeBrokerMock.Object);
        }

Sample test employing verify functions

    [Fact]
        private async Task ShouldThrowDependencyExceptionOnUploadIfUrlNotFoundAsync()
        {
            // given
            AIFile someAIFile = CreateRandomAIFile();

            var httpResponseUrlNotFoundException =
                new HttpResponseUrlNotFoundException();

            var invalidConfigurationFileException =
                new InvalidConfigurationAIFileException(
                    message: "Invalid AI file configuration error occurred, contact support.",
                        httpResponseUrlNotFoundException);

            var expectedFileDependencyException =
                new AIFileDependencyException(
                    message: "AI file dependency error occurred, contact support.",
                        invalidConfigurationFileException);

            this.openAIBrokerMock.Setup(broker =>
                broker.PostFileFormAsync(It.IsAny<ExternalAIFileRequest>()))
                    .ThrowsAsync(httpResponseUrlNotFoundException);

            // when
            ValueTask<AIFile> uploadFileTask =
                this.aiFileService.UploadFileAsync(someAIFile);

            AIFileDependencyException actualFileDependencyException =
                await Assert.ThrowsAsync<AIFileDependencyException>(
                    uploadFileTask.AsTask);

            // then
            actualFileDependencyException.Should().BeEquivalentTo(
                expectedFileDependencyException);

            this.openAIBrokerMock.Verify(broker =>
               broker.PostFileFormAsync(It.IsAny<ExternalAIFileRequest>()),
                   Times.Once);

            this.openAIBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }

Why?

The library was created mainly for developers who aren't currently using any mocking library or are displeased with the complexities of some other implementation.

CleanMoq is designed to be a very practical, unobtrusive and straight-forward way to quickly setup dependencies for your tests. Its API design helps even novice users to fall in the "pit of success" and avoid most common misuses/abuses of mocking.

Who?

Moq was originally developed by Clarius, Manas and InSTEDD.

Moq uses Castle DynamicProxy internally as the interception mechanism to enable mocking.

Features at a glance

CleanMoq offers all the same original features as the Moq library, features like below:

  • Strong-typed: no strings for expectations, no object-typed return values or constraints
  • Unsurpassed VS IntelliSense integration: everything supports full VS IntelliSense, from setting expectations, to specifying method call arguments, return values, etc.
  • No Record/Replay idioms to learn. Just construct your mock, set it up, use it and optionally verify calls to it (you may not verify mocks when they act as stubs only, or when you are doing more classic state-based testing by checking returned values from the object under test)
  • VERY low learning curve as a consequence of the previous three points. For the most part, you don't even need to ever read the documentation.
  • Granular control over mock behavior with a simple MockBehavior.
  • Mock both interfaces and classes
  • Override expectations: can set default expectations in a fixture setup, and override as needed on tests
  • Pass constructor arguments for mocked classes
  • Intercept and raise events on mocks
  • Intuitive support for out/ref arguments

Thank You

Special thanks to the original maintainers and supporters of Moq - find the list on the front-page for Moq here

cleanmoq's People

Contributors

stakx avatar kzu avatar jeremymeng avatar ishimko avatar salfab avatar tonyhallett avatar scott-xu avatar felicepollano avatar ocoanet avatar theoy avatar hassanhabib avatar snrnats avatar glhays avatar pimterry avatar bfriesen avatar stoo101 avatar matkubicki avatar quetzalcoatl avatar lepijohnny avatar yorah avatar iskiselev avatar devlooped-bot avatar dependabot[bot] avatar shereef avatar code-grump avatar caraul avatar adam-knights avatar joeenzminger avatar robsiklos avatar yonahw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.