public void Two_Part_Predicate_Constant_On_Left_Should_Match()
        {
            var spec            = new Specification <Contact>(contact => (contact.Name == "test" && 1 == contact.ContactTypeId));
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.ShouldBe(true);
            value.ShouldBe(1);
        }
        public void Single_Part_Predicate_NotEqual_Should_Not_Match()
        {
            var spec            = new Specification <Contact>(contact => contact.ContactTypeId != 1);
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.ShouldBe(false);
            value.ShouldBe(0);
        }
Пример #3
0
        public void Single_Part_Predicate_Constant_On_Right_Should_Not_Match()
        {
            var spec            = new Specification <Contact>(contact => contact.Name == "test");
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.Should().Be(false);
            value.Should().Be(0);
        }
        public void Single_Part_Predicate_Constant_On_Left_Should_Match()
        {
            var spec            = new Specification <Contact>(contact => 1 == contact.ContactTypeId);
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Single_Part_Predicate_Constant_On_Right_Should_Not_Match()
        {
            var spec = new Specification<Contact>(contact => contact.Name == "test");
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(false);
            value.ShouldEqual(0);
        }
        public void Single_Part_Predicate_Constant_On_Left_Should_Match()
        {
            var spec = new Specification<Contact>(contact => 1 == contact.ContactTypeId);
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Single_Part_Predicate_GreaterThan_Should_Not_Match()
        {
            var spec            = new Specification <Contact>(contact => contact.ContactTypeId > 1);
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(false);
            value.ShouldEqual(0);
        }
        public void Two_Part_Predicate_Constant_On_Right_Should_Match()
        {
            var spec            = new Specification <Contact>(contact => (contact.Name == "test" && contact.ContactTypeId == 1));
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Partition_Column_Used_More_Than_Once_Should_Not_Match()
        {
            var contactId = 1;

            var spec            = new Specification <Contact>(contact => (contact.ContactTypeId == 1 || contactId == 2));
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.ShouldBe(true);
            value.ShouldBe(1);
        }
        public void Single_Part_Predicate_Variable_On_Left_Should_Match()
        {
            var contactId = 1;

            var spec            = new Specification <Contact>(contact => contactId == contact.ContactTypeId);
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.ShouldBe(true);
            value.ShouldBe(1);
        }
        public void Single_Part_Predicate_Using_Equals_Method_On_Right_Should_Match()
        {
            var spec            = new Specification <Contact>(contact => contact.ContactTypeId.Equals(1));
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId);

            var isMatch = cachingStrategy.TryPartitionValue(spec, out int value);

            isMatch.ShouldBe(true);
            value.ShouldBe(1);

            isMatch.ShouldBe(true);
            value.ShouldBe(1);
        }
        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 Partition_Column_Used_More_Than_Once_Should_Not_Match()
        {
            var contactId = 1;

            var spec = new Specification<Contact>(contact => (contact.ContactTypeId == 1 || contactId == 2));
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Single_Part_Predicate_Using_Equals_Method_On_Left_With_Variable_Should_Match()
        {
            var contactTypeId   = 1;
            var spec            = new Specification <Contact>(contact => contactTypeId.Equals(contact.ContactTypeId));
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Get_Entity_Partition_Value()
        {
            var contact1 = new Contact {
                ContactId = 1, ContactTypeId = 1
            };
            var contact2 = new Contact {
                ContactId = 1, ContactTypeId = 2
            };
            var cachingStrategy = new StandardCachingStrategyWithPartition <Contact>(cacheProvider, c => c.ContactTypeId);

            cachingStrategy.TryPartitionValue(contact1, out int contactId);
            contactId.ShouldBe(1);

            cachingStrategy.TryPartitionValue(contact2, out contactId);
            contactId.ShouldBe(2);
        }
        public void Deleted_Entity_With_Nullable_PartitionKey_Should_Not_Be_Returned_From_Cache()
        {
            var dbPath = EfDataDirectoryFactory.Build();

            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

            // Standard partition cache and expression.
            var strategy = new StandardCachingStrategyWithPartition <Node, int, int?>(new InMemoryCachingProvider(),
                                                                                      n => n.ParentId);

            // Standard EF repo.
            IRepository <Node, int> repository =
                new EfRepository <Node, int>(new TestObjectEntities("Data Source=" + dbPath), strategy);

            // Create a root node (ParentId = null).
            var rootNode = new Node()
            {
                ParentId = null, Name = "Root"
            };

            repository.Add(rootNode);

            // Note: If we dont assign an int? here then TryPartitionValue in StandardCachingStrategyBase cannot find the partition key in the expression
            // because there would be a cast made in the expression which breaks partition key discovery.
            int?rootNodeId = rootNode.Id;

            // Create a child node referencing the root node as it's parent.
            var childNode = new Node()
            {
                ParentId = rootNodeId, Name = "Child"
            };

            repository.Add(childNode);

            // Find the child nodes via the parentId, this will cause the cache to store the child node.
            repository.FindAll(n => n.ParentId == rootNodeId).Count().ShouldEqual(1);

            // Deleting the child node should also increment the partition generation.
            repository.Delete(childNode);

            // Subsequent query should not return the child node.
            repository.FindAll(n => n.ParentId == rootNodeId).Count().ShouldEqual(0, "Deleted entity returned from cache.");
        }
        public void TryGetResult_Should_Get_Value_If_Reinstantiated()
        {
            var contact = new Contact()
            {
                ContactId = 1, Name = "Test User"
            };

            CachingStrategy.SaveGetResult(1, contact);

            var cacheProvider = new InMemoryCachingProvider(Cache);

            var localCachingStrategy = new StandardCachingStrategyWithPartition <Contact, int, int>(cacheProvider, c => c.ContactTypeId)
            {
                CachePrefix = "#RepoStandardCacheWithPartition"
            };

            localCachingStrategy.TryGetResult(1, out Contact result).ShouldBe(true);
            result.ContactId.ShouldBe(contact.ContactId);
            result.Name.ShouldBe(contact.Name);
        }
        public void Single_Part_Predicate_Using_Equals_Method_On_Right_With_Variable_Should_Match()
        {
            var contactTypeId = 1;
            var spec = new Specification<Contact>(contact => contact.ContactTypeId.Equals(contactTypeId));
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }
        public void Two_Part_Predicate_Variable_On_Right_Should_Match()
        {
            var contactId = 1;

            var spec = new Specification<Contact>(contact => (contact.Name == "test" && contact.ContactTypeId == contactId));
            var cachingStrategy = new StandardCachingStrategyWithPartition<Contact, int, int>(c => c.ContactTypeId);

            int value;
            var isMatch = cachingStrategy.TryPartitionValue(spec, out value);

            isMatch.ShouldEqual(true);
            value.ShouldEqual(1);
        }