public void InMemRepository_Delete() { byte[] data = new byte[0]; var repository = new InMemRepository <IrepoModel>(ref data); repository.Add(new repoTestModel() { Campo1 = 10006, Campo2 = 10009 }); repository.Add(new repoTestModel() { Campo1 = 10004, Campo2 = 10002 }); var enumerator = repository.AsEnumerable().GetEnumerator(); enumerator.MoveNext(); IrepoModel model = (IrepoModel)enumerator.Current; repository.Remove(model); enumerator.Reset(); enumerator.MoveNext(); //comprobamos que se haya saltado el primer registro en esta iteración. Assert.AreEqual(10004, (enumerator.Current as IrepoModel).Campo1); }
public void ExecuteGetAll_With_Paging_Should_Save_TotalItems_In_Cache() { var repos = new InMemRepository <Contact>( new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider)); repos.Add(new Contact { ContactId = 1, Name = "Test1" }); repos.Add(new Contact { ContactId = 2, Name = "Test2" }); repos.Add(new Contact { ContactId = 3, Name = "Test3" }); repos.Add(new Contact { ContactId = 4, Name = "Test4" }); var pagingOptions = new PagingOptions <Contact>(1, 1, "Name"); var items = repos.GetAll(x => x.Name, pagingOptions); repos.CacheUsed.Should().BeFalse(); items.Count().Should().Be(1); pagingOptions.TotalItems.Should().Be(4); // reset paging options so the TotalItems is default pagingOptions = new PagingOptions <Contact>(1, 1, "Name"); items = repos.GetAll(x => x.Name, pagingOptions); repos.CacheUsed.Should().BeTrue(); items.Count().Should().Be(1); pagingOptions.TotalItems.Should().Be(4); }
public void InMemRepository_StringsSerialization() { byte[] data = new byte[0]; var repository = new InMemRepository <imodel2>(ref data); repository.Add(new model2() { field1 = 1, text1 = "texto 1-1", text2 = "texto 1-2" }); repository.Add(new model2() { field1 = 2, text1 = "texto 2-1", text2 = "texto 2-2" }); repository.SaveToFile("diario_str.iaj"); var repository2 = InMemRepository <imodel2> .FromFile("diario_str.iaj"); int n = 1; foreach (imodel2 record in repository2.AsEnumerable()) { Assert.AreEqual(record.field1, n); Assert.AreEqual(record.text1, string.Format("texto {0}-1", n)); Assert.AreEqual(record.text2, string.Format("texto {0}-2", n)); n++; } }
public void Second_Get_Call_Should_Get_New_Item_From_Cache() { var repository = new InMemRepository <Contact, int>( new ConcurrentDictionary <int, Contact>(), new TimeoutCachingStrategy <Contact, int>(10, cacheProvider) { CachePrefix = "#RepoTimeoutCache" }); repository.Add(new Contact() { Name = "Test User" }); var item = repository.Get(1); // after this call it's in cache item.Name.Should().Be("Test User"); repository.Update(new Contact() { ContactId = 1, Name = "Test User EDITED" }); // does update cache var item2 = repository.Get(1); // should get from cache since the timeout hasn't happened item2.Name.Should().Be("Test User EDITED"); }
public void ExecuteGet_Should_Use_Cache_After_First_Call() { var repos = new InMemRepository <Contact>( new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider)); repos.Add(new Contact { Name = "Test1" }); repos.Add(new Contact { Name = "Test2" }); var item = repos.Get(1); repos.CacheUsed.Should().BeTrue(); item.Should().NotBeNull(); }
public void ExecuteFindAll_With_Selector_Should_Use_Cache_After_First_Call() { var repos = new InMemRepository <Contact>( new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider)); repos.Add(new Contact { Name = "Test1" }); repos.Add(new Contact { Name = "Test2" }); var items = repos.FindAll(x => x.ContactId < 3, x => x.Name); repos.CacheUsed.Should().BeFalse(); items.Count().Should().Be(2); items = repos.FindAll(x => x.ContactId < 3, x => x.Name); repos.CacheUsed.Should().BeTrue(); items.Count().Should().Be(2); }
public void InMemRepository_Add() { byte[] data = new byte[0]; var repository = new InMemRepository <IrepoModel>(ref data); repository.Add(new repoTestModel() { Campo1 = 10006, Campo2 = 10009 }); repository.Add(new repoTestModel() { Campo1 = 10004, Campo2 = 10002 }); var enumerator = repository.AsEnumerable().GetEnumerator(); enumerator.MoveNext(); IrepoModel model = (IrepoModel)enumerator.Current; enumerator.MoveNext(); model = (IrepoModel)enumerator.Current; repository.SaveToFile(".\\diario.iaj"); }
public void Cache_Should_Timeout() { var repository = new InMemRepository <Contact, int>( new ConcurrentDictionary <int, Contact>(), new TimeoutCachingStrategy <Contact, int>(2, cacheProvider) { CachePrefix = "#RepoTimeoutCache" }); repository.Add(new Contact() { Name = "Test User" }); repository.Get(1); repository.CacheUsed.Should().BeTrue(); Thread.Sleep(5000); repository.Get(1); repository.CacheUsed.Should().BeFalse(); }