public void CanReturnTopN() { // save a few items var ciRep = new CharityInfoRepository(); var ci1 = new CharityInfo(); ci1.CharityName = "test1"; ci1.GameScore = 1400; ciRep.SaveOrUpdate(ci1); int saved1Id = ci1.Id; this.FlushSessionAndEvict(ci1); var ci2 = new CharityInfo(); ci2.CharityName = "test2"; ci2.GameScore = 1500; ciRep.SaveOrUpdate(ci2); int saved2Id = ci2.Id; this.FlushSessionAndEvict(ci2); var ci3 = new CharityInfo(); ci3.CharityName = "test3"; ci3.GameScore = 1100; ciRep.SaveOrUpdate(ci3); int saved3Id = ci3.Id; this.FlushSessionAndEvict(ci3); var ciRep2 = new CharityInfoRepository(); var topList = ciRep2.GetTop(2); Assert.AreEqual(2, topList.Count()); Assert.AreEqual("test2", topList[0].CharityName); Assert.AreEqual("test1", topList[1].CharityName); }
public void FetchUntilNot_FailsAfter10() { // save a ci var ciRep = new CharityInfoRepository(); var ci = new CharityInfo(); ci.CharityName = "testprod"; ciRep.SaveOrUpdate(ci); int savedId = ci.Id; this.FlushSessionAndEvict(ci); var ciRep2 = new CharityInfoRepository(); var tasks = new MatchTasks(ciRep2); bool expectedErrorFound = false; try { var randomCi = tasks.FetchUntilNot(0, savedId + 1, savedId + 11); } catch (ApplicationException appex) { if (appex.Message.StartsWith("FetchUntilNot failed to find a random entity after")) expectedErrorFound = true; } Assert.IsTrue(expectedErrorFound); }
public ActionResult CreateOrUpdate(CharityInfo ci) { if (ModelState.IsValid && ci.IsValid()) { this.charityInfoRepository.SaveOrUpdate(ci); return this.RedirectToAction("Index"); } return View(ci); }
public void CanCompareCharityInfos() { CharityInfo instance = new CharityInfo(); instance.CharityNumber = 35325; ; CharityInfo instanceToCompareTo = new CharityInfo(); instanceToCompareTo.CharityNumber = 35325; instance.ShouldEqual(instanceToCompareTo); }
public void CanReturnSingleRecentItem() { // save a prod var ciRep = new NHibernateRepository<CharityInfo>(); var ci = new CharityInfo(); ci.CharityName = "testprod"; ciRep.SaveOrUpdate(ci); int savedId = ci.Id; this.FlushSessionAndEvict(ci); var ciRep2 = new NHibernateRepository<CharityInfo>(); var foundProd = ciRep2.Get(savedId); Assert.AreEqual("testprod", foundProd.CharityName); }
private Tuple<int, int> MakeSomeData(int howMany) { int firstId = -1; int lastId = -1; var ciRep = new NHibernateRepository<CharityInfo>(); for (int i = 0; i <= howMany; i++) { var ci = new CharityInfo(); ci.CharityName = "testprod"+ i.ToString(); ciRep.SaveOrUpdate(ci); if (firstId == -1) firstId = ci.Id; if (i == howMany) lastId = ci.Id; this.FlushSessionAndEvict(ci); } return new Tuple<int, int>(firstId, lastId); }