当前位置: 首页>>代码示例>>C#>>正文


C# InMemoryRepository.Find方法代码示例

本文整理汇总了C#中InMemoryRepository.Find方法的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRepository.Find方法的具体用法?C# InMemoryRepository.Find怎么用?C# InMemoryRepository.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InMemoryRepository的用法示例。


在下文中一共展示了InMemoryRepository.Find方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_return_matches_from_a_repository

        public void Should_return_matches_from_a_repository()
        {
            var users = new List<UserGroup>
                               {
                                    new UserGroup {Id = Guid.NewGuid(), Name = "First Group"},
                                    new UserGroup {Id = Guid.NewGuid(), Name = "Second Group"},
                                    new UserGroup {Id = Guid.NewGuid(), Name = "Third Group"},
                             		new UserGroup {Id = Guid.NewGuid(), Name = "News Editor Group"},
                             		new UserGroup {Id = Guid.NewGuid(), Name = "Publishing Group"},
                             		new UserGroup {Id = Guid.NewGuid(), Name = "Blogging Group"},
                             		new UserGroup {Id = Guid.NewGuid(), Name = "Product Editing Group"}
                               };

            IRepository<UserGroup> repository = new InMemoryRepository<UserGroup>(users);
            var matches = repository.Find(new PagedUserGroups(3, 3));

            Assert.AreEqual(3, matches.Count);

            var count = 0;
            foreach (var item in matches)
            {
                if (count == 0)
                    Assert.AreEqual("News Editor Group", item.Name);
                if (count == 1)
                    Assert.AreEqual("Publishing Group", item.Name);
                if (count == 2)
                    Assert.AreEqual("Blogging Group", item.Name);

                count++;
            }
        }
开发者ID:pollingj,项目名称:Membrane-CMS,代码行数:31,代码来源:PagedUserGroupsFixture.cs

示例2: ChangeTrackingTest

        public void ChangeTrackingTest()
        {
            var repo = new InMemoryRepository<TestClass>(x => x.ID);
                var initialValue = "myValue";
                var obj = new TestClass { StringValue = initialValue };

                repo.Insert(obj);
                repo.SaveChanges();

                var storedObj = repo.Find(obj.ID);
                storedObj.Object.StringValue = initialValue + 1;
                repo.SaveChanges();

                storedObj = repo.Find(obj.ID);
                Assert.AreEqual(initialValue + 1, storedObj.Object.StringValue);
        }
开发者ID:simran2jain,项目名称:Repository,代码行数:16,代码来源:Tests.cs

示例3: Should_return_matches_from_a_repository

        public void Should_return_matches_from_a_repository()
        {
            var users = new List<InstalledPlugin>
                               {
                                    new InstalledPlugin { Id = Guid.NewGuid(), Name = "Blog", Version = "1.0.0"},
                                    new InstalledPlugin { Id = Guid.NewGuid(), Name = "News", Version = "1.0.0"},
                                    new InstalledPlugin { Id = Guid.NewGuid(), Name = "Events", Version = "1.0.0"}
                               };

            IRepository<InstalledPlugin> repository = new InMemoryRepository<InstalledPlugin>(users);
            var matches = repository.Find(new OrderedPlugins());

            Assert.AreEqual(3, matches.Count);

            var count = 0;
            foreach (var item in matches)
            {
                if (count == 0)
                    Assert.AreEqual("Blog", item.Name);
                if (count == 1)
                    Assert.AreEqual("Events", item.Name);
                if (count == 2)
                    Assert.AreEqual("News", item.Name);

                count++;
            }
        }
开发者ID:pollingj,项目名称:Membrane-CMS,代码行数:27,代码来源:OrderedPluginFixture.cs

示例4: FindShouldBeCachedWithMultiplePredicateValueHash

        public void FindShouldBeCachedWithMultiplePredicateValueHash()
        {
            var repository = new InMemoryRepository<Contact, string>(new StandardCachingStrategy<Contact, string>()); // by default uses InMemoryCache

            for (var i = 1; i < 5; i++)
            {
                repository.Add(new Contact { ContactId = i.ToString(), Name = "Contact " + i, ContactTypeId = 1});
            }

            var contactId = "1";
            repository.Find(x => x.ContactTypeId == 1 && x.ContactId == contactId)
                .ContactId.ShouldEqual(contactId);

            contactId = "2";
            repository.Find(x => x.ContactTypeId == 1 && x.ContactId == contactId)
                .ContactId.ShouldEqual(contactId);
        }
开发者ID:nubizsoft,项目名称:SharpRepository,代码行数:17,代码来源:StandardCachingSpikes.cs

示例5: Repository_Supports_Selectors

        public void Repository_Supports_Selectors()
        {
            var repo = new InMemoryRepository<Order>();

            // let's add a couple of orders to work with
            repo.Add(new Order()
                         {
                             Name = "Order 1",
                             Total = 120.00,
                             OrderDate = new DateTime(2013, 4, 26)
                         });

            repo.Add(new Order()
                         {
                             Name = "Order 2",
                             Total = 80.00,
                             OrderDate = new DateTime(2013, 4, 24)
                         });

            // normal Get method
            var order = repo.Get(1);
            order.OrderId.ShouldEqual(1);

            // in this case we only need the order name
            var orderName = repo.Get(1, x => x.Name);
            orderName.ShouldEqual("Order 1");

            // we can also bring back an anonymous type if needed
            var anonymousType = repo.Get(1, x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 });
            anonymousType.IsExpensiveOrder.ShouldBeTrue();

            // or we can map it to a specific type we have defined like a ViewModel
            var viewModel = repo.Get(1, x => new OrderViewModel() {Name = x.Name, IsExpensiveOrder = x.Total > 100.0});
            viewModel.IsExpensiveOrder.ShouldBeTrue();

            // We have the same options with the GetAll, Find and FindAll as well
            orderName = repo.Find(x => x.OrderId == 2, x => x.Name);
            orderName.ShouldEqual("Order 2");

            // we can also bring back an anonymous type if needed
            var anonymousTypes = repo.GetAll(x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
            anonymousTypes.Count.ShouldEqual(2);
            anonymousTypes.First().Name.ShouldEqual("Order 1");
            anonymousTypes.First().IsExpensiveOrder.ShouldBeTrue();

            anonymousTypes.Last().Name.ShouldEqual("Order 2");
            anonymousTypes.Last().IsExpensiveOrder.ShouldBeFalse();

            // or we can map it to a specific type we have defined like a ViewModel
            var viewModels = repo.FindAll(x => x.OrderId < 5, x => new OrderViewModel() { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
            viewModels.Count.ShouldEqual(2);
            viewModels.First().Name.ShouldEqual("Order 1");
            viewModels.First().IsExpensiveOrder.ShouldBeTrue();

            viewModels.Last().Name.ShouldEqual("Order 2");
            viewModels.Last().IsExpensiveOrder.ShouldBeFalse();
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:57,代码来源:HowToUseGetSelectors.cs

示例6: DetectsChangedKeys

        public void DetectsChangedKeys()
        {
            var repo = new InMemoryRepository<TestClass>(x => x.ID);
                var initialValue = "myValue";
                var obj = new TestClass { ID = "myKey", StringValue = initialValue };

                repo.Insert(obj);
                repo.SaveChanges();

                var storedObj = repo.Find(obj.ID);
                storedObj.Object.ID = "newKey";

                Assert.Throws<RepositoryException>(repo.SaveChanges);
        }
开发者ID:simran2jain,项目名称:Repository,代码行数:14,代码来源:Tests.cs

示例7: Should_return_matches_from_a_repository

        public void Should_return_matches_from_a_repository()
        {
            var users = new List<MembraneUser>
                               {
                                   new MembraneUser {Username = "andypike", Password = "apass"},
                                   new MembraneUser {Username = "johnpolling", Password = "jpass"},
                                   new MembraneUser {Username = "someone", Password = "pass"},
                                   new MembraneUser {Username = "another", Password = "pass"},
                                   new MembraneUser {Username = "onemore", Password = "pass"}
                               };

            IRepository<MembraneUser> repository = new InMemoryRepository<MembraneUser>(users);
            var matches = repository.Find(new UserByUsernameAndPassword("johnpolling", "jpass"));

            Assert.AreEqual(1, matches.Count);
        }
开发者ID:pollingj,项目名称:Membrane-CMS,代码行数:16,代码来源:UserByUsernameAndPasswordFixture.cs

示例8: UpdateTest

        public void UpdateTest()
        {
            var repository = new InMemoryRepository<ComplexTestClass>(x => x.ID);
                var obj = new ComplexTestClass() { IntValue = 1 };
                repository.Insert(obj);
                repository.SaveChanges();

                repository.Update(new { IntValue = 2 }, obj.ID);
                repository.SaveChanges();

                var val = repository.Find(obj.ID).Object;
                Assert.AreEqual(2, val.IntValue);

                var updateObj = new { DateTimeValue = DateTime.MaxValue };
                repository.Update(updateObj, x => x.ComplexProperty, obj.ID);
                repository.SaveChanges();

                Assert.AreEqual(val.ComplexProperty.DateTimeValue, DateTime.MaxValue);
        }
开发者ID:simran2jain,项目名称:Repository,代码行数:19,代码来源:Tests.cs

示例9: ExecuteFind_With_Selector_Should_Use_Cache_After_First_Call

        public void ExecuteFind_With_Selector_Should_Use_Cache_After_First_Call()
        {
            var repos = new InMemoryRepository<Contact>(new StandardCachingStrategy<Contact>());

            repos.Add(new Contact { Name = "Test1" });
            repos.Add(new Contact { Name = "Test2" });

            var item = repos.Find(x => x.ContactId == 1, x => x.Name);
            repos.CacheUsed.ShouldBeFalse();
            item.ShouldNotBeNull();

            item = repos.Find(x => x.ContactId ==1, x => x.Name);
            repos.CacheUsed.ShouldBeTrue();
            item.ShouldNotBeNull();
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:15,代码来源:InMemoryCachingTests.cs


注:本文中的InMemoryRepository.Find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。