public void SaveGetAllResult_Should_Set_Cache()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };

            CachingStrategy.SaveGetAllResult(null, null, new[] { contact });
            CachingStrategy.TryGetAllResult(null, null, out result).ShouldEqual(true);

            result.Count().ShouldEqual(1);
        }
        public void SaveGetAllResult_With_Generational_Disabled_Should_Not_Set_Cache()
        {
            ((StandardCachingStrategyWithPartition<Contact, int, int>)CachingStrategy).GenerationalCachingEnabled = false;

            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };

            CachingStrategy.SaveGetAllResult(null, null, new[] { contact });
            CachingStrategy.TryGetAllResult(null, null, out result).ShouldEqual(false);
        }
示例#3
0
        public void Batch_Update_Should_Queue_Delete_Action()
        {
            var repository = new InMemoryRepository<Contact, Int32>();

            using (var batch = repository.BeginBatch())
            {
                var contact = new Contact();
                batch.Delete(contact);
                batch.BatchActions.FirstOrDefault().Item.ShouldEqual(contact);
                batch.BatchActions.FirstOrDefault().Action.ShouldEqual(BatchAction.Delete);
            }
        }
        public void Get_Entity_Partition_Value()
        {
            var contactId = 0;
            var contact1 = new Contact { ContactId = 1, ContactTypeId = 1 };
            var contact2 = new Contact { ContactId = 1, ContactTypeId = 2 };
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact>(c => c.ContactTypeId);

            cachingStrategy.TryPartitionValue(contact1, out contactId);
            contactId.ShouldEqual(1);

            cachingStrategy.TryPartitionValue(contact2, out contactId);
            contactId.ShouldEqual(2);
        }
        public void SaveFindResult_Should_Set_Cache()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = null;

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            queryOptions = new SortingOptions<Contact>("Name");
            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
        public void Logging_Via_Aspects()
        {
            var repository = new InMemoryRepository<Contact, int>();

            var contact1 = new Contact() {Name = "Contact 1"};
            repository.Add(contact1);
            repository.Add(new Contact() { Name = "Contact 2"});
            repository.Add(new Contact() { Name = "Contact 3"});

            contact1.Name += " EDITED";
            repository.Update(contact1);

            repository.Delete(2);

            repository.FindAll(x => x.ContactId < 50);
        }
        public void SaveGetResult_With_WriteThrough_Disabled_Should_Not_Set_Cache()
        {
            ((StandardCachingStrategyWithPartition<Contact, int, int>)CachingStrategy).WriteThroughCachingEnabled = false;

            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };

            CachingStrategy.SaveGetResult(1, null, contact);
            CachingStrategy.TryGetResult(1, null, out result).ShouldEqual(false);
        }
        public void SaveGetResult_Should_Set_Cache()
        {
            Contact result;
            var contact = new Contact() {ContactId = 1, Name = "Test User"};

            CachingStrategy.SaveGetResult(1, null, contact);
            CachingStrategy.TryGetResult(1, null, out result).ShouldEqual(true);

            result.ContactId.ShouldEqual(contact.ContactId);
            result.Name.ShouldEqual(contact.Name);
        }
        public void TryGetAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var sorting = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveGetAllResult(sorting, null, new[] { contact });
            CachingStrategy.TryGetAllResult(sorting, null, out result).ShouldEqual(true);

            result.Count().ShouldEqual(1);
        }
        public void TryGetAllResult_With_Different_QueryOptions_Should_Return_False()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };

            CachingStrategy.SaveGetAllResult(new SortingOptions<Contact>("Name"), null, new[] { contact });
            CachingStrategy.TryGetAllResult(null, null, out result).ShouldEqual(false);
        }
        public void TryFindResult_With_Different_QueryOptions_Should_Return_False()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, null, null, out result).ShouldEqual(false);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, new SortingOptions<Contact>("Name", true), null, out result).ShouldEqual(false);
        }
        public void TryFindResult_After_Update_To_Partition_Should_Return_False()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            contact.Name = "Test User - EDITED";
            CachingStrategy.Update(1, contact);

            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(false);
            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);

            // after saving the new results in the next generation then it should find it
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
        public void TryFindResult_After_Update_To_Different_Partition_Should_Return_True()
        {
            Contact result;
            var contact = new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindResult(specification, queryOptions, null, contact);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);

            var contact2 = new Contact() { ContactId = 2, Name = "Test User 2", ContactTypeId = 2 };
            CachingStrategy.Update(2, contact2);
            CachingStrategy.TryFindResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }
        public void TryFindAllResult_With_Same_QueryOptions_Should_Return_True()
        {
            IEnumerable<Contact> result;
            var contact = new Contact() { ContactId = 1, Name = "Test User" };
            var specification = new Specification<Contact>(x => x.ContactId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name");

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, new[] { contact });
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);

            result.Count().ShouldEqual(1);
        }
        public void TryFindAllResult_After_Add_To_Partition_Should_Return_False()
        {
            IEnumerable<Contact> result;
            var contacts = new[] { new Contact() { ContactId = 1, Name = "Test User", ContactTypeId = 1 } };
            var specification = new Specification<Contact>(x => x.ContactTypeId == 1);
            IQueryOptions<Contact> queryOptions = new SortingOptions<Contact>("Name", true);

            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);

            var contact2 = new Contact() { ContactId = 2, Name = "Test User 2", ContactTypeId = 1 };
            CachingStrategy.Add(2, contact2);
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(false);
            CachingStrategy.SaveFindAllResult(specification, queryOptions, null, contacts);

            // after saving the new results in the next generation then it should find it
            CachingStrategy.TryFindAllResult(specification, queryOptions, null, out result).ShouldEqual(true);
        }