public void GetUserByEmail_ReturnsNullForNullEmail() { using var context = DBContextHelpers.PrepareContext(); var currentUser = context.GetUserByEmail(null); currentUser.Should().BeNull(); }
public void GetUserByEmail_ReturnsNullForNotFound() { using var context = DBContextHelpers.PrepareContext(); var currentUser = context.GetUserByEmail("*****@*****.**"); currentUser.Should().BeNull(); }
public void GetUserByEmail_ReturnsUserByEmail() { using var context = DBContextHelpers.PrepareContext(); var currentUser = context.GetUserByEmail("*****@*****.**"); currentUser.Id.Should().Be(1); currentUser.Families.Count.Should().Be(2); }
public void GetInvitationsForUser_ReturnsEmptyList_WhenNullUser() { using var context = DBContextHelpers.PrepareContext(); var invitations = context.GetInvitationsForUser(null); invitations.Should().HaveCount(0); }
public void InviteNewMember_InvalidEmail_ThrowsException() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); Action act = () => { controller.InviteNewMember(1, "not an email address"); }; act.Should().Throw <ForagerApiException>().Which.Code.Should().Be(ForagerApiExceptionCode.InvalidEmailProvided); }
public void InviteNewMember_FamilyNotFound_ThrowsException() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); Action act = () => { controller.InviteNewMember(5, "*****@*****.**"); }; act.Should().Throw <ForagerApiException>().Which.Code.Should().Be(ForagerApiExceptionCode.FamilyNotFound); }
public void Post_InvalidName_ThrowsException() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); Action act = () => { controller.Post(1, " "); }; act.Should().Throw <ForagerApiException>().Which.Code.Should().Be(ForagerApiExceptionCode.InvalidNameProvided); }
public void Get_FamilyNotFound_ThrowsException() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); Action act = () => { controller.Get(5); }; act.Should().Throw <ForagerApiException>().Which.Code.Should().Be(ForagerApiExceptionCode.FamilyNotFound); }
public void Get_ReturnsFamily() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); var response = controller.Get(1); response.Id.Should().Be(1); response.Members.Should().HaveCount(3); }
public void Reject_UpdatesInvitation() { using var context = DBContextHelpers.PrepareContext(); var controller = new InvitationController(context); var response = controller.Reject(2); context.Families.Single(f => f.Id == 2).Members.Should().NotContain(u => u.Id == 2); context.Invitations.Single(i => i.Id == 2).Status.Should().Be(InvitationStatus.Rejected); }
public void GetInvitationsForUser_ReturnsEmptyList_WhenNoInvitationsAreFound() { using var context = DBContextHelpers.PrepareContext(); var currentUser = new User { Email = "*****@*****.**" }; var invitations = context.GetInvitationsForUser(currentUser); invitations.Should().HaveCount(0); }
public void Put_InvalidName_ThrowsException() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); context.Families.Should().NotContain(f => f.Name == "new family"); Action act = () => { controller.Put(" "); }; act.Should().Throw <ForagerApiException>().Which.Code.Should().Be(ForagerApiExceptionCode.InvalidNameProvided); }
public void LinkUserToFamily_WithInvalidUser_ShouldThrowError() { using var context = DBContextHelpers.PrepareContext(); Action act = () => { context.LinkUserToFamily(null, default); context.SaveChanges(); }; act.Should().Throw <ForagerApiException>().Where(e => e.Code == ForagerApiExceptionCode.UserNotFound); }
public void RejectInvitation_WithAcceptedId_ShouldThrowError() { using var context = DBContextHelpers.PrepareContext(); Action act = () => { context.RejectInvitation(3); context.SaveChanges(); }; act.Should().Throw <ForagerApiException>().Where(e => e.Code == ForagerApiExceptionCode.InvitationNotFound); }
public void RejectInvitation_SetsStatusToRejected() { using var context = DBContextHelpers.PrepareContext(); context.RejectInvitation(2); context.SaveChanges(); var invitation = context.Invitations.Single(i => i.Id == 2); invitation.Status.Should().Be(InvitationStatus.Rejected); invitation.ResolvedOn.Should().NotBeNull(); }
public void AcceptInvitation_WithInvalidUser_ShouldThrowError() { using var context = DBContextHelpers.PrepareContext(); Action act = () => { var family = context.AcceptInvitation(4); context.SaveChanges(); }; act.Should().Throw <ForagerApiException>().Where(e => e.Code == ForagerApiExceptionCode.UserNotFound); }
public void LinkUserToFamily_WithInvalidFamily_ShouldThrowError() { using var context = DBContextHelpers.PrepareContext(); var user = context.Users.Single(u => u.Id == 2); Action act = () => { context.LinkUserToFamily(user, null); context.SaveChanges(); }; act.Should().Throw <ForagerApiException>().Where(e => e.Code == ForagerApiExceptionCode.FamilyNotFound); }
public void Post_TrimsName() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); context.Families.Single(f => f.Id == 1).Name.Should().BeNull(); var response = controller.Post(1, " my family "); context.Families.Single(f => f.Id == 1).Name.Should().Be("my family"); response.Name.Should().Be("my family"); response.Id.Should().Be(1); }
public void Accept_AddsUserToFamily() { using var context = DBContextHelpers.PrepareContext(); var controller = new InvitationController(context); context.Families.Single(f => f.Id == 2).Members.Should().NotContain(u => u.Id == 2); var response = controller.Accept(2); context.Families.Single(f => f.Id == 2).Members.Should().ContainSingle(u => u.Id == 2); context.Invitations.Single(i => i.Id == 2).Status.Should().Be(InvitationStatus.Accepted); response.Id.Should().Be(2); response.Members.Should().Contain(2); }
public void Put_TrimsNamey() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); context.Families.Should().NotContain(f => f.Name == "new family"); var response = controller.Put(" new family "); context.Families.Should().ContainSingle(f => f.Name == "new family"); response.Name.Should().Be("new family"); response.Members.Should().HaveCount(1); response.Creator.Should().Be(1); }
public void GetInvitationsForUser_ReturnsCorrectList() { using var context = DBContextHelpers.PrepareContext(); var currentUser = context.GetUserByEmail("*****@*****.**"); var invitations = context.GetInvitationsForUser(currentUser); invitations.Should().HaveCount(1); var invitation = invitations.First(i => true); invitation.Id.Should().Be(1); invitation.Source.Id.Should().Be(2); invitation.Family.Id.Should().Be(1); }
public void InviteNewMember_StoresTrimmedEmail() { using var context = DBContextHelpers.PrepareContext(); var controller = CreateController(context); context.Invitations.Should().NotContain(i => i.Email == "*****@*****.**"); var response = controller.InviteNewMember(1, " [email protected] "); var invitation = context.Invitations.Single(i => i.Email == "*****@*****.**" && i.Family.Id == 1); invitation.Should().NotBeNull(); invitation.Source.Id.Should().Be(1); }
public void Get_CreatesNewUser() { var userInfo = Substitute.For <IUserInformationService>(); userInfo.GetUserEmail().Returns("*****@*****.**"); using var context = DBContextHelpers.PrepareContext(); var controller = new UserController(userInfo, context); context.Users.Should().HaveCount(3); var response = controller.Get(); context.Users.Should().HaveCount(4); }
public void Get_ReturnsUserInformation() { var userInfo = Substitute.For <IUserInformationService>(); userInfo.GetUserEmail().Returns("*****@*****.**"); using var context = DBContextHelpers.PrepareContext(); var controller = new UserController(userInfo, context); var response = controller.Get(); response.CurrentUser.Should().Be(1); response.Families.Should().HaveCount(2); response.Users.Should().HaveCount(3); response.Invitations.Should().HaveCount(1).And.ContainSingle(i => i.Id == 1); }
public void LinkUserToFamily_LinksUserToFamily() { using var context = DBContextHelpers.PrepareContext(); var user = context.Users.Single(u => u.Id == 2); var family = context.Families.Single(f => f.Id == 2); family.Members.Should().NotContain(m => m.Id == 2); user.Families.Should().NotContain(f => f.Id == 2); context.LinkUserToFamily(user, family); context.SaveChanges(); family.Members.Should().ContainSingle(m => m.Id == 2); user.Families.Should().ContainSingle(f => f.Id == 2); }
public void AcceptInvitation_AddsUserToFamily() { using var context = DBContextHelpers.PrepareContext(); var family = context.AcceptInvitation(2); context.SaveChanges(); var invitation = context.Invitations.Single(i => i.Id == 2); invitation.Status.Should().Be(InvitationStatus.Accepted); invitation.ResolvedOn.Should().NotBeNull(); family.Id.Should().Be(2); family.Members.Should().ContainSingle(m => m.Id == 2); }