public void Insert_ShouldAddARow_ToThe_Winner_Table_WithTheSuppliedValues() { using (new TransactionScope()) { //Arrange long attendeeID; long sponsorID; long swagID; string name = "Joe Smith"; using (var dc = new DayOfDotNetDataContext()) { attendeeID = (from x in dc.Attendees where x.IsEligible && !x.HasWon select x.AttendeeID).First(); sponsorID = (from x in dc.Sponsors where x.ProvidedSwag select x.SponsorID).First(); swagID = (from x in dc.Swags where x.SponsorID == sponsorID select x.SwagID).First(); } WinnerDTO winner = new WinnerDTO {AttendeeID = attendeeID, SponsorID = sponsorID, SwagID = swagID, Name = name}; //Act IWinnerRepository repo = new WinnerRepository(); bool success = repo.Insert(winner); //Assert success.ShouldBeTrue("Expected Success To Be True"); Winner retrievedWinner; using (var dc = new DayOfDotNetDataContext()) { retrievedWinner = (from x in dc.Winners where x.AttendeeID == attendeeID select x).First(); } retrievedWinner.AttendeeID.ShouldEqual(attendeeID, "Wrong AttendeeID"); retrievedWinner.SponsorID.ShouldEqual(sponsorID, "Wrong SponsorID"); retrievedWinner.SwagID.ShouldEqual(swagID, "Wrong SwagID"); retrievedWinner.Name.ShouldEqual(name, "Wrong Name"); } }
public bool DeleteAll() { using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) { dc.ExecuteCommand("Delete from Winner"); } return true; }
public void DeleteAll_ShouldRemoveAll_Winners_FromThe_Winner_Table() { //Arrange using (new TransactionScope()) { long attendeeID; long sponsorID; long swagID; string name = "Joe Smith"; using (var dc = new DayOfDotNetDataContext()) { attendeeID = (from x in dc.Attendees where x.IsEligible && !x.HasWon select x.AttendeeID).First(); sponsorID = (from x in dc.Sponsors where x.ProvidedSwag select x.SponsorID).First(); swagID = (from x in dc.Swags where x.SponsorID == sponsorID select x.SwagID).First(); dc.Winners.InsertOnSubmit(new Winner{AttendeeID = attendeeID, SponsorID = sponsorID, SwagID = swagID, Name = name}); dc.SubmitChanges(); } //Act IWinnerRepository rep = new WinnerRepository(); bool success = rep.DeleteAll(); //Assert success.ShouldBeTrue("Expected Success To Be True"); using (var dc = new DayOfDotNetDataContext()) { (from x in dc.Winners select x).Count().ShouldEqual(0, "Expected 0 rows in Winner table"); } } }
public bool ResetAllHasWon() { using (var dc = new DayOfDotNetDataContext()) { dc.ExecuteCommand("Update Attendee Set HasWon = 'false'"); } return true; }
public bool Insert(WinnerDTO winner) { Winner w = new Winner {AttendeeID = winner.AttendeeID, SponsorID = winner.SponsorID, SwagID = winner.SwagID, Name = winner.Name}; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) { dc.Winners.InsertOnSubmit(w); dc.SubmitChanges(); } return true; }
public void GetAll_ShouldReturn_All_Attendees_InThe_Database() { //Arrange int expectedCount; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) { expectedCount = (from x in dc.Attendees select x).Count(); } //Act IAttendeeRepository attendeeRepository = new AttendeeRepository(); IList<AttendeeDTO> attendees = attendeeRepository.GetAll(); //Assert attendees.Count.ShouldEqual(expectedCount); }
public void GetAll_Should_Return_All_Swags_From_The_Database() { //Arrange int expectedCount; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()){ expectedCount = (from x in dc.Swags select x).Count(); } //Act ISwagRepository repo = new SwagRepository(); IList<SwagDTO> swags = repo.GetAll(); //Assert swags.Count.ShouldEqual(expectedCount, "Wrong number of Swags"); }
public void GetAll_ShouldReturn_All_Sponsors_InThe_Database() { //Arrange int expectedCount; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) { expectedCount = (from x in dc.Sponsors select x).Count(); } //Act ISponsorRepository repo = new SponsorRepository(); IList<SponsorDTO> sponsors = repo.GetAll(); //Assert sponsors.Count.ShouldEqual(expectedCount, "Wrong number of sponsors"); }
public void DeleteAll_ShouldDelete_All_Attendees() { //Arrange using (new TransactionScope()) { //Act IAttendeeRepository repo = new AttendeeRepository(); bool successful = repo.DeleteAll(); //Assert successful.ShouldBeTrue("Expected True"); using (var dc = new DayOfDotNetDataContext()) { (from x in dc.Attendees select x).Count().ShouldEqual(0, "Expected 0 Attendees"); } } }
public void GetAllThatProvidedSwag_ShouldReturn_All_Sponsors_InThe_Database_Where_ProvidedSwag_Equals_True() { //Arrange int expectedCount; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()){ expectedCount = (from x in dc.Sponsors where x.ProvidedSwag select x).Count(); } //Act ISponsorRepository repo = new SponsorRepository(); IList<SponsorDTO> sponsors = repo.GetAllThatProvidedSwag(); //Assert sponsors.Count.ShouldEqual(expectedCount, "Wrong number of sponsors"); (from x in sponsors where !x.ProvidedSwag select x).Count().ShouldEqual(0, "Expected 0 Sponsors that did not provide swag!"); }
public void GetAllEligible_ShouldReturn_All_Attendess_InThe_Database_Where_IsEligible_Equals_True() { //Arrange int expectedCount; using (var dc = new DayOfDotNetDataContext()) { expectedCount = (from x in dc.Attendees where x.IsEligible select x).Count(); } //Act IAttendeeRepository attendeeRepository = new AttendeeRepository(); IList<AttendeeDTO> attendees = attendeeRepository.GetAllEligible(); //Assert attendees.Count.ShouldEqual(expectedCount, "Wrong number of attendess"); (from x in attendees where !x.IsEligible select x).Count().ShouldEqual(0, "Expected 0 Non-Eligible Attendees"); }
public bool InsertAll(IList<AttendeeDTO> attendeeDtos) { IList<Attendee> attendees = (from x in attendeeDtos select new Attendee { FirstName = x.FirstName, LastName = x.LastName, Company = x.Company, Email = x.Email, HasWon = x.HasWon, IsEligible = x.IsEligible }).ToList(); using (var dc = new DayOfDotNetDataContext()) { dc.Attendees.InsertAllOnSubmit(attendees); dc.SubmitChanges(); } return true; }
public void GetAllBySponsor_Should_Return_All_Swags_ForTheSpecified_Sponsor_From_The_Database() { //Arrange int expectedCount; long sponsorID; using (DayOfDotNetDataContext dc = new DayOfDotNetDataContext()) { sponsorID = (from x in dc.Sponsors where x.ProvidedSwag select x.SponsorID).FirstOrDefault(); expectedCount = (from x in dc.Swags where x.SponsorID == sponsorID select x).Count(); } //Act ISwagRepository repo = new SwagRepository(); IList<SwagDTO> swags = repo.GetAllBySponsor(sponsorID); //Assert swags.Count.ShouldEqual(expectedCount, "Wrong number of Swags"); (from x in swags select x.SponsorID).Distinct().Count().ShouldEqual(1, "Expected 1 Distinct SponsorId"); swags[0].SponsorID.ShouldEqual(sponsorID, "Wrong SponsorID"); }
public IList<AttendeeDTO> GetAll() { IList<AttendeeDTO> attendeeDTOList; using (var dc = new DayOfDotNetDataContext()) { attendeeDTOList = (from x in dc.Attendees select new AttendeeDTO { AttendeeID = x.AttendeeID, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, Company = x.Company, HasWon = x.HasWon, IsEligible = x.IsEligible }).ToList(); } return attendeeDTOList; }
public IList<SwagDTO> GetAll() { IList<SwagDTO> swags; using (var dc = new DayOfDotNetDataContext()) { swags = (from x in dc.Swags select new SwagDTO { SwagID = x.SwagID, SponsorID = x.SponsorID, Name = x.Name, ImageLocation = x.ImageLocation, Position = x.Position }).ToList(); } return swags; }
public IList<SponsorDTO> GetAll() { IList<SponsorDTO> sponsors; using (var dc = new DayOfDotNetDataContext()) { sponsors = (from x in dc.Sponsors select new SponsorDTO { SponsorID = x.SponsorID, Name = x.Name, ContactName = x.ContactName, ContactEmail = x.ContactEmail, SponsorshipLevel = x.SponsorshipLevel, ImageLocation = x.ImageLocation, Position = x.Position, ProvidedSwag = x.ProvidedSwag }).ToList(); } return sponsors; }
public void InsertAll_ShouldInsertAllTheSupplied_Attendees() { //Arrange AttendeeDTO attendee1 = new AttendeeDTO {FirstName = "FName1", LastName = "LName1", Company = "Company1", Email = "*****@*****.**", IsEligible = true, HasWon = true}; AttendeeDTO attendee2 = new AttendeeDTO {FirstName = "FName2", LastName = "LName2", Company = "Company2", Email = "*****@*****.**", IsEligible = false, HasWon = false}; IList<AttendeeDTO> attendees = new List<AttendeeDTO>{attendee1,attendee2}; using (new TransactionScope()) { using (var dc = new DayOfDotNetDataContext()) { dc.ExecuteCommand("Delete from Winner"); dc.ExecuteCommand("Delete from Attendee"); } //Act IAttendeeRepository repo = new AttendeeRepository(); bool successful = repo.InsertAll(attendees); //Assert successful.ShouldBeTrue("Expected True"); using (var dc = new DayOfDotNetDataContext()) { (from x in dc.Attendees select x).Count().ShouldEqual(2, "Expected 2 Attendees"); } } }
public void SetHasWon_ShouldSetThe_HasWon_Flag_To_True_OnThe_Attendee_WithTheSpecified_AttendeeID() { //Arrange long attendeeID; using (new TransactionScope()) { using (var dc = new DayOfDotNetDataContext()) { Attendee attendee = (from x in dc.Attendees where x.IsEligible && !x.HasWon select x).FirstOrDefault(); attendee.HasWon = true; attendeeID = attendee.AttendeeID; dc.SubmitChanges(); } //Act IAttendeeRepository repo = new AttendeeRepository(); bool successful = repo.SetHasWon(attendeeID); //Assert successful.ShouldBeTrue("Expected True"); using (var dc = new DayOfDotNetDataContext()) { (from x in dc.Attendees where x.AttendeeID == attendeeID select x.HasWon).FirstOrDefault().ShouldBeTrue("Expected True"); } } }
public bool SetHasWon(long attendeeID) { using (var dc = new DayOfDotNetDataContext()) { Attendee attendee = (from x in dc.Attendees where x.AttendeeID == attendeeID select x).FirstOrDefault(); if (attendee == null) return false; attendee.HasWon = true; dc.SubmitChanges(); } return true; }
public void ResetAllHasWon_ShouldSetThe_HasWon_Flag_To_False_OnAll_Attendees() { //Arrange using (new TransactionScope()) { using (var dc = new DayOfDotNetDataContext()) { Attendee attendee = (from x in dc.Attendees where x.IsEligible && !x.HasWon select x).FirstOrDefault(); attendee.HasWon = true; dc.SubmitChanges(); } //Act IAttendeeRepository repo = new AttendeeRepository(); bool successful = repo.ResetAllHasWon(); //Assert successful.ShouldBeTrue("Expected True"); using (var dc = new DayOfDotNetDataContext()) { (from x in dc.Attendees where x.HasWon select x).Count().ShouldEqual(0, "Expected 0 HasWon == True"); } } }