c# - SharpRepository Unit Testing CacheRepository Unable to Add Multiple Items -


we using sharprepository on top of entityframework 6, that's working great far. implementing full unit testing, in researching approved method unit test sharprepository cacherepository, lets populate repo consistent test data , tests services , models against test repositories. working part.

the issue

have populated these repos successfully, single object, can pull object out , test against it. new test use case, required test against multiple entries, when add them, last entry available in repo. see both unit test output, , inspecting repo in watch window while debugging, ever has one.

i have setup standard cache strategy , inmemory provider, have tried adding each object individually , list, add function.

the code

the setup

    [testinitialize]     public void initialize()     {         var sharprepositoryconfiguration = new sharprepositoryconfiguration();         sharprepositoryconfiguration.addcachingstrategy(new standardcachingstrategyconfiguration("standard"));         sharprepositoryconfiguration.addcachingprovider(new inmemorycachingproviderconfiguration("inmemory"));         sharprepositoryconfiguration.addrepository(new cacherepositoryconfiguration("textfilter", "textfilter", "standard", "inmemory"));          textfilterrepo = sharprepositoryconfiguration.getinstance<textfilter, int>("textfilter");     }      [testcleanup]     public void cleanup()     {         textfilterrepo.delete(c => true);     } 

these methods should called before , after each test method respectively, should not cause issue inside method itself.

the add

        list<textfilter> badwords;         var badword1= new textfilter         {             id = 0,             filtertype = 1,             filtertext = "badword1",             datetimecreated = datetime.now         };         var badword2 = new textfilter         {             id = 1,             filtertype = 1,             filtertext = "badword2",             datetimecreated = datetime.now         };         var badword3 = new textfilter         {             id = 2,             filtertype = 1,             filtertext = "badword3",             datetimecreated = datetime.now         };          badwords = new list<textfilter>         {             badword1,             badword2,             badword3         };          textfilterrepo.add(badwords); 

as said before i've tried both individual add calls , list, same results.

edit: sharprepositorysettings i'm not sure why cacheused set false, not have additional settings these, i'm wondering if part of problem , if need call explicitly work.

research

i've researched extensively, both sharp repository in general , unit testing specifically.

i've seen so, led me use cacherepository, how can seed sharprepository's inmemoryrepository? . have not been able find info on information. have setup caching repository incorrectly, typically looks in examples i've seen. have used in many unit tests, have not had populate multiple values before.

request

i'm looking both in identifying why setup cannot add multiple objects it's cache, , how can change code, or unit test setup in general able accommodate multiple objects in cacherepository.

so hopped sharp repo source code, , found issues. first apologize, of have been avoided, sanitized code example , naming conventions make easier read, covered key value had naming convention mismatch sharp repo. issue sharp uses convention based mapping id (which huge convenience).

enter image description here enter image description here

for interested found tracing through additem method in cacherepositorybase.cs. convention specific code in defaultrepositoryconventions.cs you'd need pull source see future knowledge seekers, if you're having issues might worth check.

it's worth mentioning got [repositoryprimarykey] attribute work, renaming property match convention, both worked equally well. annotation particularly helpful auto-generated ef entities using metadata partial class.

many @jefftreuting, help.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -