public void CanGetPersonById()
        {
            using (var dbsProvider = new TestDBsProvider()) {
                this.AddThreePersons(dbsProvider);

                using (var w = new RegistersWrapper(dbsProvider)) {
                    var rdbc = w.DB.Tables.DbContextForReader;

                    Assert.True(rdbc.People.Where(
                                    p => p.Id == Id2 &&
                                    p.Name == Name2 && p.Surname == Surname2
                                    ).Count() == 1
                                );

                    IPeopleRegister register  = w.New.PeopleRegister();
                    var             regReader = (IPeopleRegisterReader)register;

                    foreach (PersonRow person in new[] {
                        register.GetById(Id2),
                        regReader.GetById(Id2)
                    }
                             )
                    {
                        Assert.True(person.Id == Id2 &&
                                    person.Name == Name2 &&
                                    person.Surname == Surname2);
                    }
                }
            }
        }
Exemple #2
0
        public void FinalStateMatches()
        {
            const int peopleCount    = 10,
                      firstIdNumber  = 0,
                      secondIdNumber = 3,
                      thirdIdNumber  = 7;
            decimal amount           = 20.123m;

            string giverId, takerId, thirdId;
            long   debtDealId;

            using (var dbsProvider = new TestDBsProvider()) {
                using (var w = new RegistersWrapper(dbsProvider)) {
                    var dbc = w.DB.Tables.DbContext;

                    new TablesDbPopulator(dbc).AddPeople(peopleCount);

                    IRegister rwRoot = w.New.Register();
                    var       roRoot = (IRegisterReader)rwRoot;

                    IPeopleRegisterReader roPeople = roRoot.People;
                    giverId = roPeople.All.OrderBy(p => p.Id)
                              .Skip(firstIdNumber).First().Id;
                    takerId = roPeople.All.OrderBy(p => p.Id)
                              .Skip(secondIdNumber).First().Id;
                    thirdId = roPeople.All.OrderBy(p => p.Id)
                              .Skip(thirdIdNumber).First().Id;

                    debtDealId = rwRoot.Debts.Deals.Add(new DebtDealRow {
                        Time    = DateTime.Now,
                        GiverId = giverId, TakerId = takerId,
                        Amount  = amount
                    });
                }

                using (var w = new RegistersWrapper(dbsProvider)) {
                    var rdbc   = w.DB.Tables.DbContextForReader;
                    var roRoot = (IRegisterReader)w.New.Register();

                    this.CheckPairDebtsRegister(
                        roRoot.Debts.Pairs, rdbc,
                        giverId, takerId, thirdId, amount);

                    this.CheckPersonDebtsRegister(
                        roRoot.Debts.Person, rdbc,
                        giverId, takerId, thirdId, amount);

                    this.CheckDebtDealsRegister(
                        roRoot.Debts.Deals, rdbc,
                        debtDealId,
                        giverId, takerId, thirdId, amount);

                    this.CheckAchieversRegister(
                        roRoot.Debts.Achievers, w.DB.Documents.AchieversCollection,
                        giverId, takerId, amount);
                }
            }
        }
        private void AddThreePersons(TestDBsProvider dbsProvider)
        {
            this.AddTwoPersons(dbsProvider);

            using (var w = new RegistersWrapper(dbsProvider)) {
                IPeopleRegister peopleRegister = w.New.PeopleRegister();
                peopleRegister.Add(new PersonRow {
                    Id = Id3, Name = Name3, Surname = Surname3
                });
            }
        }
        private void AddTwoPersons(TestDBsProvider dbsProvider)
        {
            using (var w = new RegistersWrapper(dbsProvider)) {
                IPeopleRegister register = w.New.PeopleRegister();

                register.Add(new PersonRow {
                    Id = Id1, Name = Name1, Surname = Surname1
                });
                register.Add(new PersonRow {
                    Id = Id2, Name = Name2, Surname = Surname2
                });
            }
        }
Exemple #5
0
        public void FinalStateMatches()
        {
            using (var dbsProvider = new TestDBsProvider()) {
                for (byte c = 0; c < 30; c++)
                {
                    TakeCreditAndPayBack(dbsProvider, countOfPaybacks: 1);
                    dbsProvider.DeleteAllContent();

                    TakeCreditAndPayBack(dbsProvider, countOfPaybacks: 2);
                    dbsProvider.DeleteAllContent();

                    TakeCreditAndPayBack(dbsProvider,
                                         countOfPaybacks: (uint)new Random().Next(3, 70));
                    dbsProvider.DeleteAllContent();
                }
            }
        }
        public void CanQueryPeople()
        {
            using (var dbsProvider = new TestDBsProvider()) {
                this.AddThreePersons(dbsProvider);

                using (var w = new RegistersWrapper(dbsProvider)) {
                    var dbc = w.DB.Tables.DbContext;
                    Assert.True(dbc.People.Where(
                                    p => p.Id == Id2 &&
                                    p.Name == Name2 && p.Surname == Surname2
                                    ).Count() == 1
                                );

                    var rdbc = w.DB.Tables.DbContextForReader;
                    Assert.True(rdbc.People.Where(
                                    p => p.Id == Id2 &&
                                    p.Name == Name2 && p.Surname == Surname2
                                    ).Count() == 1
                                );
                }
            }
        }
        public void CanSaveAndRetrieveDocument()
        {
            string testCollectionName = "TestDocs_hs523";
            var    originalDoc        = new TestDoc()
            {
                Id  = new ObjectId(),
                B   = 12,
                S   = "stri",
                HSS = new HashSet <string>()
                {
                    "aVal", "bVal"
                }
            };

            using (var dbsProvider = new TestDBsProvider()) {
                using (var w = new RegistersWrapper(dbsProvider)) {
                    IMongoCollection <TestDoc> collection = w.DB.Documents.MongoDB
                                                            .GetCollection <TestDoc>(testCollectionName);

                    collection.InsertOne(originalDoc);
                }

                using (var w = new RegistersWrapper(dbsProvider)) {
                    IMongoCollection <TestDoc> collection = w.DB.Documents.MongoDB
                                                            .GetCollection <TestDoc>(testCollectionName);

                    TestDoc retrievedDoc = collection.AsQueryable()
                                           .Where(td => td.Id == originalDoc.Id)
                                           .First();

                    Assert.True(retrievedDoc.B == originalDoc.B);
                    Assert.True(retrievedDoc.S == originalDoc.S);
                    Assert.True(retrievedDoc.HSS.SetEquals(originalDoc.HSS));
                }
            }
        }
Exemple #8
0
        private void TakeCreditAndPayBack(
            TestDBsProvider dbsProvider, uint countOfPaybacks
            )
        {
            const int peopleCount    = 10,
                      firstIdNumber  = 0,
                      secondIdNumber = 3,
                      thirdIdNumber  = 7;
            const decimal maxAmout   = 1e6m,
                          minAmount  = 1;
            decimal totalAmount
                = (decimal)(new Random().NextDouble())
                  * (maxAmout - minAmount)
                  + minAmount;

            string logIndent = "   ";

            this.output.WriteLine(
                $"TakeCreditAndPayBack: totalAmount = {totalAmount}, "
                + $"countOfPaybacks = {countOfPaybacks}:");

            using (var w = new RegistersWrapper(dbsProvider)) {
                var dbc = w.DB.Tables.DbContext;

                new TablesDbPopulator(dbc).AddPeople(peopleCount);

                var       rdbc   = w.DB.Tables.DbContextForReader;
                IRegister rwRoot = w.New.Register();
                var       roRoot = (IRegisterReader)rwRoot;

                IPeopleRegisterReader roPeople = roRoot.People;
                string giverId = roPeople.All.OrderBy(p => p.Id)
                                 .Skip(firstIdNumber).First().Id;
                string takerId = roPeople.All.OrderBy(p => p.Id)
                                 .Skip(secondIdNumber).First().Id;
                string thirdId = roPeople.All.OrderBy(p => p.Id)
                                 .Skip(thirdIdNumber).First().Id;

                (long creditDebtDealId, long[] paybackDebtDealIds)
                    = this.MakeDeals(
                          rwRoot, rdbc,
                          giverId, takerId, thirdId,
                          totalAmount, countOfPaybacks, logIndent);

                this.CheckPairDebtsRegister(
                    roRoot.Debts.Pairs, rdbc, giverId, takerId, thirdId);

                this.CheckPersonDebtsRegister(
                    roRoot.Debts.Person, rdbc,
                    giverId, takerId, thirdId, totalAmount);

                this.CheckDebtDealsRegister(
                    roRoot.Debts.Deals, rdbc,
                    creditDebtDealId, paybackDebtDealIds,
                    giverId, takerId, thirdId,
                    totalAmount, countOfPaybacks);

                this.CheckAchieversRegister(
                    roRoot.Debts.Achievers,
                    rdbc, w.DB.Documents.AchieversCollection,
                    giverId, takerId, totalAmount);
            }

            this.output.WriteLine("");
        }