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


C# List.GetRange方法代码示例

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


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

示例1: ShouldCancelTasksOnShutdown

        public void ShouldCancelTasksOnShutdown()
        {
            var executor = CreateDefaultExecutor(ShutdownMode.CancelQueuedTasks);
            var tasks = new List<WaitingTask>();
            var futures = new List<Future<int>>();
            for(int i=0; i<10; i++) {
                WaitingTask task = new WaitingTask();
                tasks.Add(task);
                if(i == 0) {
                    Monitor.Enter(task);
                }
                futures.Add(executor.Submit(task));
            }
            executor.Shutdown();
            Monitor.Exit(tasks[0]);

            while(!executor.IsShutdown()) { }
            Assert.AreEqual(0, futures[0].GetResult());
            foreach(Future<int> future in futures.GetRange(1, 9)) {
                Assert.IsTrue(future.IsDone);
                try {
                    Assert.AreEqual(0, future.GetResult());
                    Assert.Fail(); // Should not reach this
                } catch(ExecutionException e) {
                    Assert.IsInstanceOfType(typeof(TaskCancelledException), e.delayedException);
                }
            }
        }
开发者ID:magwo,项目名称:ExecutorsDotNet,代码行数:28,代码来源:SingleThreadTester.cs

示例2: Simple2

        public void Simple2()
        {
            var list = new List<int> { 1, 2, 3, 4, 7, 8 }; ;
            IList<int> iList = list;

            var listRange = list.GetRange(2, 3);
            var iListRange = iList.GetRange(2, 3);
            AssertListsAreTheSame(listRange, iListRange);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:9,代码来源:GetRange.cs

示例3: MoveTest

 public void MoveTest()
 {
     int len = 2;
     int step = 1;
     int from = 1, to = 3;
     var list1 = new List<string>
         {
             "ABABAB",
             "ABATAT",
             "TABABAB",
             "ABTABAB",
             "ABABAB",
             "ABABAB",
             "ABABAB"
         };
     List<string> list = list1.GetRange(@from, to - @from);
     var chain = new ComplexChain(list1);
     var iterator = new EndIterator(chain, len, step);
     iterator.Move(2);
     List<string> result = iterator.Next();
     for (int i = 0; i < list.Count; i++)
     {
         Assert.True(list[i].Equals(result[i]));
     }
 }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:25,代码来源:EndIteratorTests.cs

示例4: TestTransferPaid


//.........这里部分代码省略.........
                BatchId = null
            });

            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch444")).Throws(new Exception("Not gonna do it, wouldn't be prudent."));

            _paymentService.Setup(mocked => mocked.GetChargeRefund("ch555")).Returns(new StripeRefund
            {
                Data = new List<StripeRefundData>
                { new StripeRefundData()
                    {
                        Id = "ch555",
                        Amount = "987",
                        Charge = new StripeCharge {
                            Id = "re_123456"
                        }
                    }
                }
            });

            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch555")).Returns(new DonationDTO
            {
                Id = "5555",
                BatchId = 1984
            });
            _donationService.Setup(mocked => mocked.GetDonationBatch(1984)).Returns(new DonationBatchDTO
            {
                Id = 5150,
                ProcessorTransferId = "OU812"
            });

            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch777")).Returns(new DonationDTO
            {
                Id = "7777",
                BatchId = 2112
            });
            _donationService.Setup(mocked => mocked.GetDonationBatch(2112)).Returns(new DonationBatchDTO
            {
                Id = 2112,
                ProcessorTransferId = null
            });

            _donationService.Setup(mocked => mocked.GetDonationBatchByProcessorTransferId("tx9876")).Returns((DonationBatchDTO)null);
            _paymentService.Setup(mocked => mocked.GetChargesForTransfer("tx9876")).Returns(charges);
            _donationService.Setup(
                mocked => mocked.CreatePaymentProcessorEventError(e, It.IsAny<StripeEventResponseDTO>()));
            _donationService.Setup(mocked => mocked.UpdateDonationStatus(1111, 999, e.Created, null)).Returns(1111);
            _donationService.Setup(mocked => mocked.UpdateDonationStatus(2222, 999, e.Created, null)).Returns(2222);
            _donationService.Setup(mocked => mocked.UpdateDonationStatus(3333, 999, e.Created, null)).Returns(3333);
            _donationService.Setup(mocked => mocked.UpdateDonationStatus(7777, 999, e.Created, null)).Returns(7777);
            _donationService.Setup(mocked => mocked.CreateDeposit(It.IsAny<DepositDTO>())).Returns(
                (DepositDTO o) =>
                {
                    o.Id = 98765;
                    return (o);
                });
            _donationService.Setup(mocked => mocked.CreateDonationBatch(It.IsAny<DonationBatchDTO>())).Returns((DonationBatchDTO o) => o);

            var result = _fixture.ProcessStripeEvent(e);
            Assert.IsNotNull(result);
            Assert.IsInstanceOf<TransferPaidResponseDTO>(result);
            var tp = (TransferPaidResponseDTO)result;
            Assert.AreEqual(6, tp.TotalTransactionCount);
            Assert.AreEqual(4, tp.SuccessfulUpdates.Count);
            Assert.AreEqual(charges.GetRange(0, 4).Select(charge => charge.Id), tp.SuccessfulUpdates);
            Assert.AreEqual(2, tp.FailedUpdates.Count);
            Assert.AreEqual("ch444", tp.FailedUpdates[0].Key);
            Assert.AreEqual("Not gonna do it, wouldn't be prudent.", tp.FailedUpdates[0].Value);
            Assert.AreEqual("ch555", tp.FailedUpdates[1].Key);
            Assert.IsNotNull(tp.Batch);
            Assert.IsNotNull(tp.Deposit);
            Assert.IsNotNull(tp.Exception);

            _donationService.Verify(mocked => mocked.CreateDonationBatch(It.Is<DonationBatchDTO>(o =>
                o.BatchName.Matches(@"MP\d{12}")
                && o.SetupDateTime == o.FinalizedDateTime
                && o.BatchEntryType == 555
                && o.ItemCount == 4
                && o.BatchTotalAmount == ((111 + 222 + 333 + 777) / Constants.StripeDecimalConversionValue)
                && o.Donations != null
                && o.Donations.Count == 4
                && o.DepositId == 98765
                && o.ProcessorTransferId.Equals("tx9876")
            )));

            _donationService.Verify(mocked => mocked.CreateDeposit(It.Is<DepositDTO>(o =>
                o.DepositName.Matches(@"MP\d{12}")
                && !o.Exported
                && o.AccountNumber.Equals(" ")
                && o.BatchCount == 1
                && o.DepositDateTime != null
                && o.DepositTotalAmount == (1456 / Constants.StripeDecimalConversionValue)
                && o.ProcessorFeeTotal == (13 / Constants.StripeDecimalConversionValue)
                && o.DepositAmount == (1443 / Constants.StripeDecimalConversionValue)
                && o.Notes == null
                && o.ProcessorTransferId.Equals("tx9876")
            )));

            _paymentService.VerifyAll();
            _donationService.VerifyAll();
        }
开发者ID:plachmann,项目名称:crds-angular,代码行数:101,代码来源:StripeEventServiceTest.cs

示例5: AssertList

        private void AssertList(LispObject list, List<Token> tokens)
        {
            if (list.IsNil)
            {
                Assert.IsEmpty(tokens);
            }
            else
            {
                var cons = (Cons)list;
                var symbol = (Symbol)cons.Car;

                Assert.That(symbol.SameName(tokens[0].Name));

                AssertList(cons.Cdr, tokens.GetRange(1, tokens.Count - 1));
            }
        }
开发者ID:nja,项目名称:keel,代码行数:16,代码来源:ReaderTest.cs

示例6: GetChecklistsShouldReturnNumberOfElementsEqualToSpecifiedPageSize

        public void GetChecklistsShouldReturnNumberOfElementsEqualToSpecifiedPageSize()
        {
            // Arrange
            var repositoryChecklists = new List<ChecklistDto>
            {
                new ChecklistDto { Title = "A" },
                new ChecklistDto { Title = "B" },
                new ChecklistDto { Title = "C" },
                new ChecklistDto { Title = "D" },
                new ChecklistDto { Title = "E" }
            };

            var fakeRepository = A.Fake<IChecklistRepository>();
            A.CallTo(() => fakeRepository.GetChecklists()).Returns(repositoryChecklists.AsQueryable());

            var startup = new Startup
            {
                ControllerConfiguration = new ControllerConfiguration { PageSizeLimit = 100 },
                ChecklistRepository = fakeRepository
            };
            using (WebApp.Start(BaseApiUriString, startup.Configuration))
            {
                var client = new HttpClient();

                // Act
                var responseOne = client.GetAsync(new Uri(BaseApiUriString + "/api/checklists?pageNumber=1&pageSize=2")).Result;
                var returnedChecklistsOne = JsonConvert.DeserializeObject<List<ChecklistDto>>(responseOne.Content.ReadAsStringAsync().Result);

                var responseTwo = client.GetAsync(new Uri(BaseApiUriString + "/api/checklists?pageNumber=2&pageSize=2")).Result;
                var returnedChecklistsTwo = JsonConvert.DeserializeObject<List<ChecklistDto>>(responseTwo.Content.ReadAsStringAsync().Result);

                var responseThree = client.GetAsync(new Uri(BaseApiUriString + "/api/checklists?pageNumber=3&pageSize=2")).Result;
                var returnedChecklistsThree = JsonConvert.DeserializeObject<List<ChecklistDto>>(responseThree.Content.ReadAsStringAsync().Result);

                var responseFour = client.GetAsync(new Uri(BaseApiUriString + "/api/checklists?pageNumber=4&pageSize=2")).Result;
                var returnedChecklistsFour = JsonConvert.DeserializeObject<List<ChecklistDto>>(responseFour.Content.ReadAsStringAsync().Result);

                // Assert
                Assert.That(responseOne.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.True(returnedChecklistsOne.SequenceEqual(repositoryChecklists.GetRange(0, 2)));

                Assert.That(responseTwo.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.True(returnedChecklistsTwo.SequenceEqual(repositoryChecklists.GetRange(2,2)));

                Assert.That(responseThree.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.True(returnedChecklistsThree.SequenceEqual(repositoryChecklists.GetRange(4, 1)));

                Assert.That(responseFour.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.IsEmpty(returnedChecklistsFour);
            }
        }
开发者ID:denholms,项目名称:LSCS,代码行数:51,代码来源:GetChecklistTests.cs

示例7: TestGetManyToManyGuidIdentifier


//.........这里部分代码省略.........
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            var conn = Utils.CreateConnection();
            conn.DropTable<M2MClassE>();
            conn.DropTable<M2MClassF>();
            conn.DropTable<ClassEClassF>();
            conn.CreateTable<M2MClassE>();
            conn.CreateTable<M2MClassF>();
            conn.CreateTable<ClassEClassF>();

            // Use standard SQLite-Net API to create the objects
            var objectsF = new List<M2MClassF>
            {
                new M2MClassF {
                    Foo = string.Format("1- Foo String {0}", new Random().Next(100))
                },
                new M2MClassF {
                    Foo = string.Format("2- Foo String {0}", new Random().Next(100))
                },
                new M2MClassF {
                    Foo = string.Format("3- Foo String {0}", new Random().Next(100))
                },
                new M2MClassF {
                    Foo = string.Format("4- Foo String {0}", new Random().Next(100))
                }
            };
            conn.InsertAll(objectsF);

            var objectsE = new List<M2MClassE>
            {
                new M2MClassE {
                    Id = Guid.NewGuid(),
                    Bar = string.Format("1- Bar String {0}", new Random().Next(100))
                },
                new M2MClassE {
                    Id = Guid.NewGuid(),
                    Bar = string.Format("2- Bar String {0}", new Random().Next(100))
                },
                new M2MClassE {
                    Id = Guid.NewGuid(),
                    Bar = string.Format("3- Bar String {0}", new Random().Next(100))
                },
                new M2MClassE {
                    Id = Guid.NewGuid(),
                    Bar = string.Format("4- Bar String {0}", new Random().Next(100))
                }
            };

            conn.InsertAll(objectsE);

            foreach (var objectE in objectsE)
            {
                var copyE = objectE;
                Assert.Null(objectE.FObjects);

                // Fetch (yet empty) the relationship
                conn.GetChildren(copyE);

                Assert.NotNull(copyE.FObjects);
                Assert.AreEqual(0, copyE.FObjects.Length);
            }


            // Create the relationships in the intermediate table
            for (var eIndex = 0; eIndex < objectsE.Count; eIndex++)
            {
                for (var fIndex = 0; fIndex <= eIndex; fIndex++)
                {
                    conn.Insert(new ClassEClassF
                        {
                            ClassEId = objectsE[eIndex].Id,
                            ClassFId = objectsF[fIndex].Id
                        });
                }
            }


            for (var i = 0; i < objectsE.Count; i++)
            {
                var objectE = objectsE[i];

                // Relationship still empty because hasn't been refreshed
                Assert.NotNull(objectE.FObjects);
                Assert.AreEqual(0, objectE.FObjects.Length);

                // Fetch the relationship
                conn.GetChildren(objectE);

                var childrenCount = i + 1;

                Assert.NotNull(objectE.FObjects);
                Assert.AreEqual(childrenCount, objectE.FObjects.Length);
                var foos = objectsF.GetRange(0, childrenCount).Select(objectB => objectB.Foo).ToList();
                foreach (var objectD in objectE.FObjects)
                {
                    Assert.IsTrue(foos.Contains(objectD.Foo));
                }
            }
        }
开发者ID:xamarin-libraries,项目名称:sqlite.net-pcl-extensions,代码行数:101,代码来源:ManyToManyTests.cs

示例8: TestUpdateUnsetManyToManyList

        public void TestUpdateUnsetManyToManyList()
        {
            // In this test we will create a N:M relationship between objects of ClassA and ClassB
            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            // After that, we will remove objects 1 and 2 from relationships
            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       <empty>
            //          2       -       <empty>
            //          3       -       3
            //          4       -       3, 4


            var conn = Utils.CreateConnection();
            conn.DropTable<M2MClassA>();
            conn.DropTable<M2MClassB>();
            conn.DropTable<ClassAClassB>();
            conn.CreateTable<M2MClassA>();
            conn.CreateTable<M2MClassB>();
            conn.CreateTable<ClassAClassB>();

            // Use standard SQLite-Net API to create the objects
            var objectsB = new List<M2MClassB>
            {
                new M2MClassB {
                    Foo = string.Format("1- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("2- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("3- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("4- Foo String {0}", new Random().Next(100))
                }
            };
            conn.InsertAll(objectsB);

            var objectsA = new List<M2MClassA>
            {
                new M2MClassA {
                    Bar = string.Format("1- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("2- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("3- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("4- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                }
            };

            conn.InsertAll(objectsA);

            // Create the relationships
            for (var aIndex = 0; aIndex < objectsA.Count; aIndex++)
            {
                var objectA = objectsA[aIndex];

                for (var bIndex = 0; bIndex <= aIndex; bIndex++)
                {
                    var objectB = objectsB[bIndex];
                    objectA.BObjects.Add(objectB);
                }

                conn.UpdateWithChildren(objectA);
            }

            // At these points all the relationships are set
            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            // Now we will remove ClassB objects 1 and 2 from the relationships
            var objectsBToRemove = objectsB.GetRange(0, 2);

            foreach (var objectA in objectsA)
            {
                objectA.BObjects.RemoveAll(objectsBToRemove.Contains);
                conn.UpdateWithChildren(objectA);
            }

            // This should now be the current status of all relationships

//.........这里部分代码省略.........
开发者ID:xamarin-libraries,项目名称:sqlite.net-pcl-extensions,代码行数:101,代码来源:ManyToManyTests.cs

示例9: TestUpdateSetManyToManyList

        public void TestUpdateSetManyToManyList()
        {
            // In this test we will create a N:M relationship between objects of ClassA and ClassB
            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            var conn = Utils.CreateConnection();
            conn.DropTable<M2MClassA>();
            conn.DropTable<M2MClassB>();
            conn.DropTable<ClassAClassB>();
            conn.CreateTable<M2MClassA>();
            conn.CreateTable<M2MClassB>();
            conn.CreateTable<ClassAClassB>();

            // Use standard SQLite-Net API to create the objects
            var objectsB = new List<M2MClassB>
            {
                new M2MClassB {
                    Foo = string.Format("1- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("2- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("3- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("4- Foo String {0}", new Random().Next(100))
                }
            };
            conn.InsertAll(objectsB);

            var objectsA = new List<M2MClassA>
            {
                new M2MClassA {
                    Bar = string.Format("1- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("2- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("3- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                },
                new M2MClassA {
                    Bar = string.Format("4- Bar String {0}", new Random().Next(100)),
                    BObjects = new List<M2MClassB>()
                }
            };

            conn.InsertAll(objectsA);

            // Create the relationships
            for (var aIndex = 0; aIndex < objectsA.Count; aIndex++)
            {
                var objectA = objectsA[aIndex];

                for (var bIndex = 0; bIndex <= aIndex; bIndex++)
                {
                    var objectB = objectsB[bIndex];
                    objectA.BObjects.Add(objectB);
                }
            
                conn.UpdateWithChildren(objectA);
            }


            for (var i = 0; i < objectsA.Count; i++)
            {
                var objectA = objectsA[i];
                var childrenCount = i + 1;
                var storedChildKeyList = (from ClassAClassB ab in conn.Table<ClassAClassB>()
                                          where ab.ClassAId == objectA.Id
                                          select ab.ClassBId).ToList();
                                         

                Assert.AreEqual(childrenCount, storedChildKeyList.Count, "Relationship count is not correct");
                var expectedChildIds = objectsB.GetRange(0, childrenCount).Select(objectB => objectB.Id).ToList();
                foreach (var objectBKey in storedChildKeyList)
                {
                    Assert.IsTrue(expectedChildIds.Contains(objectBKey), "Relationship ID is not correct");
                }
            }
        }
开发者ID:xamarin-libraries,项目名称:sqlite.net-pcl-extensions,代码行数:90,代码来源:ManyToManyTests.cs

示例10: TestGetManyToManyArray

        public void TestGetManyToManyArray()
        {
            // In this test we will create a N:M relationship between objects of ClassC and ClassD
            //      Class C     -       Class D
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            var conn = Utils.CreateConnection();
            conn.DropTable<M2MClassC>();
            conn.DropTable<M2MClassD>();
            conn.DropTable<ClassCClassD>();
            conn.CreateTable<M2MClassC>();
            conn.CreateTable<M2MClassD>();
            conn.CreateTable<ClassCClassD>();

            // Use standard SQLite-Net API to create the objects
            var objectsD = new List<M2MClassD>
            {
                new M2MClassD {
                    Foo = string.Format("1- Foo String {0}", new Random().Next(100))
                },
                new M2MClassD {
                    Foo = string.Format("2- Foo String {0}", new Random().Next(100))
                },
                new M2MClassD {
                    Foo = string.Format("3- Foo String {0}", new Random().Next(100))
                },
                new M2MClassD {
                    Foo = string.Format("4- Foo String {0}", new Random().Next(100))
                }
            };
            conn.InsertAll(objectsD);

            var objectsC = new List<M2MClassC>
            {
                new M2MClassC {
                    Bar = string.Format("1- Bar String {0}", new Random().Next(100))
                },
                new M2MClassC {
                    Bar = string.Format("2- Bar String {0}", new Random().Next(100))
                },
                new M2MClassC {
                    Bar = string.Format("3- Bar String {0}", new Random().Next(100))
                },
                new M2MClassC {
                    Bar = string.Format("4- Bar String {0}", new Random().Next(100))
                }
            };

            conn.InsertAll(objectsC);

            foreach (var objectC in objectsC)
            {
                var copyC = objectC;
                Assert.Null(objectC.DObjects);

                // Fetch (yet empty) the relationship
                conn.GetChildren(copyC);

                Assert.NotNull(copyC.DObjects);
                Assert.AreEqual(0, copyC.DObjects.Length);
            }


            // Create the relationships in the intermediate table
            for (var cIndex = 0; cIndex < objectsC.Count; cIndex++)
            {
                for (var dIndex = 0; dIndex <= cIndex; dIndex++)
                {
                    conn.Insert(new ClassCClassD
                    {
                        ClassCId = objectsC[cIndex].Id,
                        ClassDId = objectsD[dIndex].Id
                    });
                }
            }


            for (var i = 0; i < objectsC.Count; i++)
            {
                var objectC = objectsC[i];

                // Relationship still empty because hasn't been refreshed
                Assert.NotNull(objectC.DObjects);
                Assert.AreEqual(0, objectC.DObjects.Length);

                // Fetch the relationship
                conn.GetChildren(objectC);

                var childrenCount = i + 1;

                Assert.NotNull(objectC.DObjects);
                Assert.AreEqual(childrenCount, objectC.DObjects.Length);
                var foos = objectsD.GetRange(0, childrenCount).Select(objectB => objectB.Foo).ToList();
                foreach (var objectD in objectC.DObjects)
                {
                    Assert.IsTrue(foos.Contains(objectD.Foo));
//.........这里部分代码省略.........
开发者ID:xamarin-libraries,项目名称:sqlite.net-pcl-extensions,代码行数:101,代码来源:ManyToManyTests.cs

示例11: TestGetManyToManyList

        public void TestGetManyToManyList()
        {
            // In this test we will create a N:M relationship between objects of ClassA and ClassB
            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          3       -       1, 2, 3
            //          4       -       1, 2, 3, 4

            var conn = Utils.CreateConnection();
            conn.DropTable<M2MClassA>();
            conn.DropTable<M2MClassB>();
            conn.DropTable<ClassAClassB>();
            conn.CreateTable<M2MClassA>();
            conn.CreateTable<M2MClassB>();
            conn.CreateTable<ClassAClassB>();

            // Use standard SQLite-Net API to create the objects
            var objectsB = new List<M2MClassB>
            {
                new M2MClassB {
                    Foo = string.Format("1- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("2- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("3- Foo String {0}", new Random().Next(100))
                },
                new M2MClassB {
                    Foo = string.Format("4- Foo String {0}", new Random().Next(100))
                }
            };
            conn.InsertAll(objectsB);

            var objectsA = new List<M2MClassA>
            {
                new M2MClassA {
                    Bar = string.Format("1- Bar String {0}", new Random().Next(100))
                },
                new M2MClassA {
                    Bar = string.Format("2- Bar String {0}", new Random().Next(100))
                },
                new M2MClassA {
                    Bar = string.Format("3- Bar String {0}", new Random().Next(100))
                },
                new M2MClassA {
                    Bar = string.Format("4- Bar String {0}", new Random().Next(100))
                }
            };

            conn.InsertAll(objectsA);

            foreach (var objectA in objectsA)
            {
                var copyA = objectA;
                Assert.Null(objectA.BObjects);

                // Fetch (yet empty) the relationship
                conn.GetChildren(copyA);

                Assert.NotNull(copyA.BObjects);
                Assert.AreEqual(0, copyA.BObjects.Count);
            }


            // Create the relationships in the intermediate table
            for (var aIndex = 0; aIndex < objectsA.Count; aIndex++)
            {
                for (var bIndex = 0; bIndex <= aIndex; bIndex++)
                {
                    conn.Insert(new ClassAClassB
                        {
                            ClassAId = objectsA[aIndex].Id,
                            ClassBId = objectsB[bIndex].Id
                        });
                }
            }


            for (var i = 0; i < objectsA.Count; i++)
            {
                var objectA = objectsA[i];

                // Relationship still empty because hasn't been refreshed
                Assert.NotNull(objectA.BObjects);
                Assert.AreEqual(0, objectA.BObjects.Count);

                // Fetch the relationship
                conn.GetChildren(objectA);

                var childrenCount = i + 1;

                Assert.NotNull(objectA.BObjects);
                Assert.AreEqual(childrenCount, objectA.BObjects.Count);
                var foos = objectsB.GetRange(0, childrenCount).Select(objectB => objectB.Foo).ToList();
                foreach (var objectB in objectA.BObjects)
                {
                    Assert.IsTrue(foos.Contains(objectB.Foo));
//.........这里部分代码省略.........
开发者ID:xamarin-libraries,项目名称:sqlite.net-pcl-extensions,代码行数:101,代码来源:ManyToManyTests.cs

示例12: RemoveRedundant2

        public void RemoveRedundant2()
        {
            const string file = "THE_FILE";
            const int line = 666;
            const int col = 555;
            //test case from MissingMapped
            var subject = new AstNull(file, line, col);
            var argv = new List<AstExpr>
                {
                    subject,
                    _createPlaceholder(2),
                    _createPlaceholder(),
                    _createPlaceholder(1)
                };
            var originalArgv = argv.GetRange(0, 2);

            _placeholderArgvProcessing(argv);

            Assert.AreEqual(originalArgv.Count, argv.Count, "argc not correct");
            for (var i = 0; i < originalArgv.Count; i++)
                Assert.AreSame(originalArgv[i], argv[i]);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:22,代码来源:AstTests.cs


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