public async Task Update_EventUpdated_SavedToDatabase() { var eventId = -1; Event eventHappenin = SampleData.EventParty(); using var appDbContext = new AppDbContext(Options, null); appDbContext.Events.Add(eventHappenin); await appDbContext.SaveChangesAsync(); eventId = eventHappenin.Id; using var appDbContextFetch = new AppDbContext(Options, null); Event eventFromDb = await appDbContextFetch.Events.Include(e => e.Host) .Include(e => e.Location).Where(e => e.Id == eventId).SingleOrDefaultAsync(); eventFromDb.Cost = 12.00; eventFromDb.Host = SampleData.UserCaleb(); await appDbContextFetch.SaveChangesAsync(); using var appDbContextAssert = new AppDbContext(Options, null); eventFromDb = await appDbContextAssert.Events.Include(e => e.Host) .Include(e => e.Location).Where(e => e.Id == eventId).SingleOrDefaultAsync(); Assert.Equal(12.00, eventFromDb.Cost); Assert.Equal(SampleData.Caleb, eventFromDb.Host.FirstName); Assert.Equal(eventId, eventFromDb.Id); }
public async Task Fetch_Event_DatabaseShouldReturnItWithUserAndLocation() { var eventId = -1; Event eventHappenin = SampleData.EventParty(); using var appDbContext = new AppDbContext(Options, null); appDbContext.Events.Add(eventHappenin); await appDbContext.SaveChangesAsync(); eventId = eventHappenin.Id; using var appDbContextAssert = new AppDbContext(Options, null); Event eventFromDb = await appDbContextAssert.Events.Include(e => e.Host) .Include(e => e.Location).Where(e => e.Id == eventId).SingleOrDefaultAsync(); Assert.Equal(eventHappenin.Name, eventFromDb.Name); Assert.Equal(eventHappenin.Description, eventFromDb.Description); Assert.Equal(eventHappenin.AgeRestriction, eventFromDb.AgeRestriction); Assert.Equal(eventHappenin.Cost, eventFromDb.Cost); Assert.NotNull(eventFromDb.Host); Assert.Equal(eventHappenin.Host.FirstName, eventFromDb.Host.FirstName); Assert.Equal(eventHappenin.Host.LastName, eventFromDb.Host.LastName); Assert.NotNull(eventFromDb.Location); Assert.Equal(eventHappenin.Location.Id, eventFromDb.Location.Id); Assert.Equal(eventHappenin.Location.Address, eventFromDb.Location.Address); Assert.Equal(eventHappenin.Location.City, eventHappenin.Location.City); }
public void Event_AddNullAttendee_ShouldReturnFalse() { Event eventHappenin = SampleData.EventParty(); bool added = eventHappenin.AddAttendee(null); Assert.False(added); Assert.Empty(eventHappenin.Attendees); }
public void Event_AddAttendees_Success() { Event eventHappenin = SampleData.EventParty(); User kyle = SampleData.UserKyle(); User caleb = SampleData.UserCaleb(); bool addedKyle = eventHappenin.AddAttendee(kyle); bool addedCaleb = eventHappenin.AddAttendee(caleb); Assert.True(addedKyle); Assert.True(addedCaleb); Assert.Collection(eventHappenin.Attendees, attendee => Assert.Equal(SampleData.Kyle, attendee.FirstName), attendee => Assert.Equal(SampleData.Caleb, attendee.FirstName)); }
public async Task Create_Event_DatabaseShouldSaveIt() { var eventId = -1; Event eventHappenin = SampleData.EventParty(); using var appDbContext = new AppDbContext(Options, null); appDbContext.Events.Add(eventHappenin); await appDbContext.SaveChangesAsync(); eventId = eventHappenin.Id; using var appDbContextAssert = new AppDbContext(Options, null); Event eventFromDb = await appDbContextAssert.Events.Where(e => e.Id == eventId).SingleOrDefaultAsync(); Assert.Equal(eventHappenin.Name, eventFromDb.Name); Assert.Equal(eventHappenin.Description, eventFromDb.Description); Assert.Equal(eventHappenin.AgeRestriction, eventFromDb.AgeRestriction); Assert.Equal(eventHappenin.Cost, eventFromDb.Cost); }