Git Product home page Git Product logo

Comments (7)

jordimontana82 avatar jordimontana82 commented on May 25, 2024

Could you post a unit test of what you are trying to do please?

from fake-xrm-easy.

hsouth95 avatar hsouth95 commented on May 25, 2024

Is this enough or would like the setup of the FakedContext too?

[TestMethod]
        public void UpdateCurrentParentAccountChangesNothing()
        {
            // Arrange
            this.parentAccount["statuscode"] = new OptionSetValue((int)StatusCode.Current);

            // Act
            this.context.ExecutePluginWith<UpdateAccount>(this.pluginContext);

            // Assert
            var account = (from a in this.context.CreateQuery("account")
                           where a.Id == this.parentAccount.Id
                           select a).FirstOrDefault();

            A.CallTo(() => this.service.Update(A<Entity>.Ignored)).MustNotHaveHappened();
            Assert.IsNotNull(account);
            Assert.IsTrue(account.GetAttributeValue<OptionSetValue>("statuscode").Value == (int)StatusCode.Current);
        }

from fake-xrm-easy.

jordimontana82 avatar jordimontana82 commented on May 25, 2024

Ok, I know what you mean know :)

At the minute those extensions are managed internally by the framework. They are not exposed, cause the intent of framework is to have these mocks already done and to write unit tests pretty much like if you were writing CRM customizations.

For example, there is a mock already for the Update message.

So, I suppose in that example, if what you need is to make sure the account attribute wasn't updated, it would be enough with these 2 asserts you had:

    Assert.IsNotNull(account);
    Assert.IsTrue(account.GetAttributeValue<OptionSetValue>("statuscode").Value == (int)StatusCode.Current);

from fake-xrm-easy.

jordimontana82 avatar jordimontana82 commented on May 25, 2024

Another thing, I saw you are keeping an instance of the context outside your unit test? This is not ideal, because the context keeps you entities in memory, a unit test execution could affect other tests if you share the same instance. Better to instantiate a context per test, so that the tests will be repeatable.

from fake-xrm-easy.

hsouth95 avatar hsouth95 commented on May 25, 2024

Thank you for your response! That makes sense however it does prevent us from achieving the code coverage that we want. I will keep that in mind. I'm not used to unit testing, so thank you for the advice.

from fake-xrm-easy.

jordimontana82 avatar jordimontana82 commented on May 25, 2024

You're very welcome 👍

from fake-xrm-easy.

jordimontana82 avatar jordimontana82 commented on May 25, 2024

@hsouth95 maybe is a bit too late for this... but never say never!

As other users requested this, now the service is a singleton instance so, you could things like this from now on:

A.CallTo(() => this.service.Create(A.Ignored)).MustNotHaveHappened();

from fake-xrm-easy.

Related Issues (20)

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.