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);
                }
            }
        }
Exemple #2
0
        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);
        }
 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]));
     }
 }
        public void TestTransferPaid()
        {
            var e = new StripeEvent
            {
                LiveMode = true,
                Type = "transfer.paid",
                Created = DateTime.Now.AddDays(-1),
                Data = new StripeEventData
                {
                    Object = JObject.FromObject(new StripeTransfer
                    {
                        Id = "tx9876",
                        Amount = 1443
                    })
                }
            };

            var charges = new List<StripeCharge>
            {
                new StripeCharge
                {
                    Id = "ch111",
                    Amount = 111,
                    Fee = 1,
                    Type = "charge"
                },
                new StripeCharge
                {
                    Id = "ch222",
                    Amount = 222,
                    Fee = 2,
                    Type = "charge"
                },
                new StripeCharge
                {
                    Id = "ch333",
                    Amount = 333,
                    Fee = 3,
                    Type = "charge"
                },
                new StripeCharge
                {
                    Id = "ch777",
                    Amount = 777, 
                    Fee = 7,
                    Type = "charge"
                },
                new StripeCharge
                {
                    Id = "ch444",
                    Amount = 444,
                    Fee = 4,
                    Type = "charge"
                },
                new StripeCharge
                {
                    Id = "ch555",
                    Amount = 555, 
                    Fee = 5,
                    Type = "refund"
                }
            };

           
            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch111")).Returns(new DonationDTO
            {
                Id = "1111",
                BatchId = null
            });

            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch222")).Returns(new DonationDTO
            {
                Id = "2222",
                BatchId = null
            });

            _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch333")).Returns(new DonationDTO
            {
                Id = "3333",
                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();
        }
Exemple #5
0
        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));
            }
        }
Exemple #6
0
        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);
            }
        }
        public void TestGetManyToManyGuidIdentifier()
        {
            // In this test we will create a N:M relationship between objects of ClassE and ClassF
            //      Class E     -       Class F
            // --------------------------------------
            //          1       -       1
            //          2       -       1, 2
            //          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));
                }
            }
        }
        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

            //      Class A     -       Class B
            // --------------------------------------
            //          1       -       <empty>
            //          2       -       <empty>
            //          3       -       3
            //          4       -       3, 4

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

                var storedChildKeyList = (from ClassAClassB ab in conn.Table<ClassAClassB>()
                                          where ab.ClassAId == objectA.Id
                                          select ab.ClassBId).ToList();


                var expectedChildIds = objectsB.GetRange(0, i + 1).Where(b => !objectsBToRemove.Contains(b)).Select(objectB => objectB.Id).ToList();
                Assert.AreEqual(expectedChildIds.Count, storedChildKeyList.Count, string.Format("Relationship count is not correct for Object with Id {0}", objectA.Id));
                foreach (var objectBKey in storedChildKeyList)
                {
                    Assert.IsTrue(expectedChildIds.Contains(objectBKey), "Relationship ID is not correct");
                }
            }
        }
        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");
                }
            }
        }
        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));
                }
            }
        }
        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));
                }
            }
        }
Exemple #12
0
        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]);
        }