Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Uhhhhhhhhhhh...................</p> <p>Q1: Don't make changes to code then write a test. Write a test first for the expected behavior. Then you can do whatever you want to the SUT.</p> <p>Q2: You don't make the changes in your <code>Product</code> Gateway to change the owner of the product. You make the change in your model.</p> <p>But if you insist, then listen to your tests. They are telling you that you have the possibility for products to be pulled from the gateway that have the incorrect owners. Oops, Looks like a business rule. Should be tested for in the model.</p> <p>Also your using a mock. Why are you testing an implementation detail? The gateway only cares that the <code>_productRepository.GetProduct(id)</code> returns a product. Not what the product is.</p> <p>If you test in this manner you will be creating fragile tests. What if product changes further. Now you have failing tests all over the place.</p> <p>Your consumers of product (MODEL) are the only ones that care about the implementation of <code>Product</code>.</p> <p>So your gateway test should look like this:</p> <pre><code>[Test] public void GetProduct_return_the_same_product_as_getProduct_on_productRepository() { var product = EntityGenerator.Product(); _productRepositoryMock.Setup(pr =&gt; pr.GetProduct(product.Id)).Returns(product); _productService.GetProduct(product.Id); _productRepositoryMock.VerifyAll(); } </code></pre> <p>Don't put business logic where it doesn't belong! And it's corollary is don't test for business logic where there should be none.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload