Пример #1
0
        public void Save(User user)
        {
            var current = users.FirstOrDefault(i => i.Id == user.Id);
            if (current != null)
                users.Remove(current);

            users.Add(user);
        }
Пример #2
0
        public void ShouldCacheItem()
        {
            AOP.RegisterTypeMap<ICacheStore>(new CacheStore());

            var repo = new UserRepository();


            Stopwatch sw = Stopwatch.StartNew();
            var repository = AOP.Create<IUserRepository>(repo);
            System.Diagnostics.Debug.WriteLine(sw.ElapsedMilliseconds);


            var user = new User { Id = Guid.NewGuid(), Name = "User 1" };

            repository.Save(user);

            var u1 = repository.GetById(user.Id);
            var u2 = repository.GetById(user.Id);
            var u3 = repository.GetById(user.Id);

            Assert.AreEqual(1, repo.GetByIdCount);
        }
Пример #3
0
        public void ShouldImplementCacheAspect()
        {
            var realRepository = new UserRepository();
            var repository = AspectFactory.Create<IUserRepository>(realRepository);

            var user = new User { Id = Guid.NewGuid(), Name = "User 1" };
            repository.Save(user);

            var u1 = repository.GetById(user.Id);
            var u2 = repository.GetById(user.Id);
            var u3 = repository.GetById(user.Id);

            Assert.AreEqual(1, realRepository.GetByIdCount);
        }