public void HasNoDataAtAll() { using (var wrapper = new RegistersWrapper()) { IRegister register = wrapper.New.Register(); var rdbc = wrapper.DB.Tables.DbContextForReader; Assert.True(rdbc.People.Count() == 0); Assert.True(rdbc.DebtDeals.Count() == 0); Assert.True(rdbc.DebtDealsAnalysis.Count() == 0); Assert.True(rdbc.CurrentDebts.Count() == 0); Assert.True(rdbc.CurrentTotalsPerPerson.Count() == 0); Assert.True(rdbc.CurrentStatisticsPerPerson.Count() == 0); Assert.True(rdbc.CurrentPeopleStatisticsDocuments.Count() == 0); Assert.True(register.HasNoData); Assert.True(((IRegisterReader)register).HasNoData); // achievers register IAchieversRegisterReader achieversReader = ((IRegisterReader)register).Debts.Achievers; Assert.Empty(achieversReader.ByID.WithMaxDueDebtsTotal); Assert.Empty(achieversReader.ByID.WhoHistoricallyCreditedMaxTotal); Assert.Empty(achieversReader.ByID.BestDebtorByRepaidFractionThenTotal); } }
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); } } } }
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); } } }
public void HasNoDataWhenEmpty() { using (var w = new RegistersWrapper()) { IPeopleRegister register = w.New.PeopleRegister(); Assert.True(register.HasNoData); Assert.True(((IPeopleRegisterReader)register).HasNoData); } }
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 }); } }
public void CanTryToLookupPeopleWhenEmpty() { using (var w = new RegistersWrapper()) { IPeopleRegister rwRegister = w.New.PeopleRegister(); var roRegister = (IPeopleRegisterReader)rwRegister; Assert.True(roRegister.GetById("123") == null); Assert.True(roRegister.All .Count(p => p.Id == "123") == 0); Assert.True(rwRegister.GetById("123") == null); Assert.True(rwRegister.All .Count(p => p.Id == "123") == 0); } }
public void HasPeopleButHasNoDeals() { using (var wrapper = new RegistersWrapper()) { IRegister register = wrapper.New.Register(); var rdbc = wrapper.DB.Tables.DbContextForReader; var populator = new TablesDbPopulator(wrapper.DB.Tables.DbContext); long count = new Random().Next(5, 20); populator.AddPeople(count); Assert.True(rdbc.People.Count() == count); Assert.False(register.HasNoData); Assert.False(((IRegisterReader)register).HasNoData); } }
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)); } } }
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(""); }