public async Task CreateFriendShip_InDatabase_Success() { User kyle = SampleData.UserKyle(); User caleb = SampleData.UserCaleb(); Friendship friendship = new Friendship { User = kyle, Friend = caleb }; using var appDbContext = new AppDbContext(Options, null); appDbContext.Users.Add(kyle); appDbContext.Users.Add(caleb); await appDbContext.SaveChangesAsync(); friendship.FriendId = caleb.Id; friendship.UserId = kyle.Id; appDbContext.Friends.Add(friendship); await appDbContext.SaveChangesAsync(); using var appDbAssert = new AppDbContext(Options, null); var friendshipDB = await appDbAssert.Friends.SingleOrDefaultAsync(f => f.Id == friendship.Id); Assert.Equal(friendship.Id, friendshipDB.Id); Assert.Equal(friendship.UserId, friendshipDB.UserId); Assert.Equal(friendship.FriendId, friendshipDB.FriendId); }
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 void User_AddFriends_Success() { User kyle = SampleData.UserKyle(); User caleb = SampleData.UserCaleb(); bool added = kyle.AddFriend(caleb); Assert.True(added); Assert.Collection(kyle.Friends, friend => Assert.Equal(caleb.FirstName, friend.FirstName)); Assert.Collection(caleb.Friends, friend => Assert.Equal(kyle.FirstName, friend.FirstName)); }
public void Create_Friendship_UserIDEmptyFails() { Action act = () => new Friendship { User = SampleData.UserKyle(), Friend = SampleData.UserCaleb(), FriendId = new Guid().ToString(), UserId = "" }; Assert.Throws <ArgumentException>(act); }
public void Create_Friendship_Success() { var userId = new Guid().ToString(); var friendId = new Guid().ToString(); var friendship = new Friendship { User = SampleData.UserKyle(), Friend = SampleData.UserCaleb(), FriendId = friendId, UserId = userId }; Assert.Equal((userId, friendId, SampleData.Kyle, SampleData.Caleb), (friendship.UserId, friendship.FriendId, friendship.User.FirstName, friendship.Friend.FirstName)); }
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)); }