question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CreateJsonResultAndETag( ) should return a consistent result.

See original GitHub issue

What is wrong?

When an entity does not implement IEtag, given 2 different calls that produce the same collection, CreateJsonResultAndETag( ) function from Beef.AspNetCore.WebApi.WebApiActionBase class returns different ETag values when API is called with ExcludeFields and returns the same ETag when API is called without ExcludeFields.

What is expected?

EDIT:
Expected to return the same ETag for the collection when entity does not implement IETag and returns a calculated ETag when entity implements IETag.

or

WebApiGet<TResult, TColl, TEntity> should not call CreateJsonResultAndETag( ) and should not set ETag header when items from a Collection do not implement IETag.

How to reproduce:

codegen xml:

<Entity Name="Contact" Collection="true" CollectionResult="true" WebApiRoutePrefix="api/v1/contacts" 
          AutoImplement="Database" Implements="Changelog">
    <Property Name="Id" Type="Guid" UniqueKey="true"/>
    <Property Name="Name" Type="string" DataName="ContactTypeCode" />
 <Operation Name="GetByArgs" OperationType="GetColl" PagingArgs="true">
      <Parameter Name="search" Type="string"/>
    </Operation>
</Entity>

unit test:

Assume the database has 2 contacts: “Mary Flower” and “Mary Smith”.

[Test]
        public void A152_GetByArgs_CheckETagWithoutAddingPatient_WithExcludeFields()  
        {

            var contactArgs = "Mary" ;
            var pagingArgs = new Beef.Entities.PagingArgs { IsGetCount = true };
            var webReqOptions = new Beef.WebApi.WebApiRequestOptions().Exclude("changeLog");

            var originalEtag = AgentTester.Create<ContactAgent, ContactCollectionResult>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run((a) => a.Agent.GetByArgsAsync(contactArgs, pagingArgs, webReqOptions)).Response.Headers.ETag;

 /****

Update contact name to "Mary Anne"

(details hidden for brevity)
******/


            var newEtag = AgentTester.Create<ContactAgent, ContactCollectionResult>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run((a) => a.Agent.GetByArgsAsync(contactArgs, pagingArgs, webReqOptions)).Response.Headers.ETag;

//This test passes
            Assert.AreNotEqual(originalEtag, newEtag, "ETag should not be the same after an update.");
        }

        [Test]
        public void A153_GetByArgs_CheckETagWithoutAddingPatient_WithAllFields()
        {
            var contactArgs = "Mary" ;
            var pagingArgs = new Beef.Entities.PagingArgs { IsGetCount = true };
 
            var originalEtag = AgentTester.Create<ContactAgent, ContactCollectionResult>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run((a) => a.Agent.GetByArgsAsync(contactArgs, pagingArgs)).Response.Headers.ETag;
 /****

Update contact name to "Mary Anne"

(details hidden for brevity)
******/
            var newEtag = AgentTester.Create<ContactAgent, ContactCollectionResult>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run((a) => a.Agent.GetByArgsAsync(contactArgs, pagingArgs)).Response.Headers.ETag;

//This test fails
            Assert.AreNotEqual(originalEtag, newEtag, "ETag should not be the same after an update.");
        }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chullybuncommented, Jul 2, 2020

@leandrodotec and @edjo23, thanks. I have fixed the issue, and have gone down the GetHashCode route. A new version of the Beef.AspNetCore.WebApi nuget package has been published. As an FYI, I am wanting to avoid doing any JSON serialization unless absolutely necessary and let ASP.NET Core framework handle. Eventually, I will make using the native or Newtonsoft serializer configurable, versus just Newtonsoft as it is now and this helps enable.

0reactions
leandrodoteccommented, Jul 12, 2020

Hi @chullybun, using GetHashCode makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found