Exemplo n.º 1
0
        public void FindManyMultiKey()
        {
            var data   = CreateData();
            var memory = CreateMemory(data);

            var secondary = memory.SecondaryIndex("FirstName.Age", x => MemoryKey.Create(x.FirstName, x.Age));

            secondary.FindMany(MemoryKey.Create("aaa", 89)).Select(x => x.Id).OrderBy(x => x).IsCollection(2, 4);
            secondary.FindMany(MemoryKey.Create("aaa", 89), false).Select(x => x.Id).OrderByDescending(x => x).IsCollection(4, 2);
        }
Exemplo n.º 2
0
        public void MultiKeyFind()
        {
            var data      = CreateData();
            var memory    = CreateMemory(data);
            var secondary = memory.SecondaryIndex("FirstName.LastName", x => MemoryKey.Create(x.FirstName, x.LastName));

            foreach (var item in data)
            {
                var f = secondary.Find(MemoryKey.Create(item.FirstName, item.LastName));
                item.Id.Is(f.Id);
            }

            Assert.Throws <KeyNotFoundException>(() => secondary.Find(MemoryKey.Create("aaa", "___")));
            Assert.Throws <KeyNotFoundException>(() => secondary.Find(MemoryKey.Create("___", "foo")));

            secondary.FindOrDefault(MemoryKey.Create("aaa", "___")).IsNull();
            secondary.FindOrDefault(MemoryKey.Create("___", "foo")).IsNull();
        }
Exemplo n.º 3
0
        public void FindClosestMultiKey()
        {
            var data   = CreateData();
            var memory = CreateMemory(data);

            // Age of aaa
            //new Sample { Id = 5, Age = 19, FirstName = "aaa", LastName = "foo" },
            //new Sample { Id = 2, Age = 89, FirstName = "aaa", LastName = "bar" },
            //new Sample { Id = 4, Age = 89, FirstName = "aaa", LastName = "tako" },
            //new Sample { Id = 9, Age = 99, FirstName = "aaa", LastName = "ika" },

            var secondary = memory.SecondaryIndex("FirstName.Age", x => MemoryKey.Create(x.FirstName, x.Age));

            secondary.FindClosest(MemoryKey.Create("aaa", 10), true).Age.Is(19);
            secondary.FindClosest(MemoryKey.Create("aaa", 92), true).Age.Is(89);
            secondary.FindClosest(MemoryKey.Create("aaa", 120), true).Age.Is(99);
            secondary.FindClosest(MemoryKey.Create("aaa", 10), false).Age.Is(19);
            secondary.FindClosest(MemoryKey.Create("aaa", 73), false).Age.Is(89);
            secondary.FindClosest(MemoryKey.Create("aaa", 120), false).Age.Is(99);
        }
Exemplo n.º 4
0
        public void Range()
        {
            var memory = CreateMemory(CreateData());

            var byFirstNameAndLastNameAndAge = memory.SecondaryIndex("FirstName.LastName.Age", x => MemoryKey.Create(x.FirstName, x.LastName, x.Age));

            var byFirstName            = byFirstNameAndLastNameAndAge.UseIndex1();
            var byFirstNameAndLastName = byFirstNameAndLastNameAndAge.UseIndex12();

            byFirstName.FindMany("eee").Select(x => x.Id).OrderBy(x => x).Is(1, 10);
            byFirstName.FindMany("eeee").Count.Is(0);

            byFirstNameAndLastName.FindMany("aaa", "foo").Select(x => x.Id).OrderBy(x => x).Is(5);

            byFirstNameAndLastName.FindClosest("aaa", "takz").Id.Is(4);
        }
Exemplo n.º 5
0
        public void Unique()
        {
            var memory = CreateMemory(CreateData());

            var byIdAndAgeAndFirstNameAndLastName = memory.SecondaryIndex("AllIndex", x => MemoryKey.Create(x.Id, x.Age, x.FirstName, x.LastName));


            var byId                   = byIdAndAgeAndFirstNameAndLastName.UseIndex1();
            var byIdAndAge             = byIdAndAgeAndFirstNameAndLastName.UseIndex12();
            var byIdAndAgeAndFirstName = byIdAndAgeAndFirstNameAndLastName.UseIndex123();


            byId.Find(8).Id.Is(8);
            byId.FindOrDefault(100).IsNull();

            byIdAndAge.Find(4, 89).Id.Is(4);
            byIdAndAge.FindOrDefault(4, 899).IsNull();
            byIdAndAge.FindOrDefault(5, 89).IsNull();

            byIdAndAgeAndFirstName.Find(6, 29, "bbb").Id.Is(6);
            byIdAndAgeAndFirstName.FindOrDefault(6, 29, "bbbz").IsNull();
        }