public void EntityType_Returns_Proper_Type()
        {
            var repo = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>());

            repo.EntityType.Should().Be(typeof(Contact));
        }
        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 Default_CachePrefix()
        {
            var repos = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact, int>(cacheProvider));

            repos.CachingStrategy.FullCachePrefix.Should().StartWith(DefaultRepositoryConventions.CachePrefix);
        }
        public void KeyType_Implied_Returns_Proper_Type()
        {
            var repo = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>());

            repo.KeyType.Should().Be(typeof(int));
        }
示例#5
0
        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++;
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
 public UserContainerTests()
 {
     repo      = new InMemRepository();
     container = new UserContainer(repo.CreateUserContainerDAL(), repo.CreateUserDAL(), repo.CreateBetDAL());
     user      = new User("Test", repo.CreateUserDAL(), repo.CreateBetDAL())
     {
         Id = 15
     };
 }
示例#9
0
        public AdminTests()
        {
            repo      = new InMemRepository();
            admin     = new Admin(repo.CreateAdminDAL());
            user      = new User("Test", repo.CreateUserDAL(), repo.CreateBetDAL());
            container = new UserContainer(repo.CreateUserContainerDAL(), repo.CreateUserDAL(), repo.CreateBetDAL());

            admin.NewUserAdded     += container.ReceiveNewUserNotification;
            admin.UserModification += container.ReceiveUserModificationNotification;
        }
        public void Change_CachePrefix()
        {
            const string newPrefix = "TestPrefix123";

            DefaultRepositoryConventions.CachePrefix = newPrefix;

            var repos = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact, int>(cacheProvider));

            repos.CachingStrategy.FullCachePrefix.Should().StartWith(newPrefix);
        }
        public void SetUp()
        {
            _db = new InMemUnitOfWork();
            _repo = new InMemRepository<DataModel, int>(_db);

            var newThing = new DataModel { Id = 47, Name = "Thing 1" };
            _repo.Create(newThing);

            newThing = new DataModel { Id = 84, Name = "Thing 2" };
            _repo.Create(newThing);

            _db.Commit();
        }
示例#12
0
        public RoomTests()
        {
            repo      = new InMemRepository();
            generator = new NumberGenerator();
            wheel     = new Wheel(generator);
            room      = new Room(1, repo.CreateRoomDAL(), repo.CreateRoundDAL(), repo.CreateUserDAL(), repo.CreateBetDAL(), wheel);


            player = new User("test", repo.CreateUserDAL(), repo.CreateBetDAL())
            {
                Id = 1
            };
            round = new Round(8, repo.CreateRoundDAL(), wheel);
        }
        public void Using_DisableCaching_Should_Disable_Cache_Inside_Using_Block()
        {
            var cacheProvider = new InMemoryCachingProvider(new MemoryCache(new MemoryCacheOptions()));
            var repos         = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider));

            repos.CachingEnabled.Should().BeTrue();

            using (repos.DisableCaching())
            {
                repos.CachingEnabled.Should().BeFalse();
            }

            repos.CachingEnabled.Should().BeTrue();
        }
        public void ClearCache_Changes_FullCachePrefix()
        {
            var repos = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider));

            var fullCachePrefix = repos.CachingStrategy.FullCachePrefix;

            // shouldn't change if we call it again
            repos.CachingStrategy.FullCachePrefix.Should().Be(fullCachePrefix);

            // clear out only the cache for this specific repository
            repos.ClearCache();

            // this should have changed this time
            repos.CachingStrategy.FullCachePrefix.Should().NotBe(fullCachePrefix);
        }
示例#15
0
        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 ClearAllCache_Changes_FullCachePrefix_When_Configured()
        {
            Cache.CachePrefixManager = new SingleServerCachePrefixManager();

            var repos = new InMemRepository <Contact>(
                new ConcurrentDictionary <int, Contact>(), new StandardCachingStrategy <Contact>(cacheProvider));

            var fullCachePrefix = repos.CachingStrategy.FullCachePrefix;

            // shouldn't change if we call it again
            repos.CachingStrategy.FullCachePrefix.Should().Be(fullCachePrefix);

            // clear out all cached items across all repositories
            Cache.ClearAll();

            // this should have changed this time
            repos.CachingStrategy.FullCachePrefix.Should().NotBe(fullCachePrefix);
        }
示例#17
0
        public RoomContainerTests()
        {
            repo      = new InMemRepository();
            container = new RoomContainer(
                repo.CreateRoomContainerDAL(),
                repo.CreateRoomDAL(),
                repo.CreateRoundDAL(),
                repo.CreateUserDAL(),
                repo.CreateBetDAL(),
                new Wheel(new NumberGenerator()));

            room = new Room(1,
                            repo.CreateRoomDAL(),
                            repo.CreateRoundDAL(),
                            repo.CreateUserDAL(),
                            repo.CreateBetDAL(),
                            new Wheel(new NumberGenerator()));
        }
示例#18
0
        public void SetUp()
        {
            _db   = new InMemUnitOfWork();
            _repo = new InMemRepository <DataModel, int>(_db);

            var newThing = new DataModel {
                Id = 47, Name = "Thing 1"
            };

            _repo.Create(newThing);

            newThing = new DataModel {
                Id = 84, Name = "Thing 2"
            };
            _repo.Create(newThing);

            _db.Commit();
        }
示例#19
0
        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 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();
        }
示例#21
0
        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 AdminContainerTests()
 {
     repo      = new InMemRepository();
     container = new AdminContainer(repo.CreateAdminContainerDAL(), repo.CreateAdminDAL());
 }
示例#23
0
 public NewsItemContainerTests()
 {
     repo      = new InMemRepository();
     container = new NewsItemContainer(repo.CreateNewsItemContainerDAL(), repo.CreateNewsItemDAL());
     newsItem  = new NewsItem("Special deal", repo.CreateNewsItemDAL());
 }
示例#24
0
 public UserTests()
 {
     repo = new InMemRepository();
     user = new User("test", repo.CreateUserDAL(), repo.CreateBetDAL());
     bet  = new ColorBet(IPocketColor.Black);
 }