public void InvitationManager_SaveAInvitationWithUsed_ThrowsValidationError() { // Arrange var sessionMock = new Mock <ISession>(); var mapperMock = new Mock <IMapper>(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var invitationManager = new InvitationManager(sessionMock.Object, mapperMock.Object, unitOfWorkMock.Object); unitOfWorkMock .SetupGet(x => x.IsManagedTransaction) .Returns(true); var invitationDTO = new InvitationDTO { Used = true, UserId = 1, invitationKey = "fsdfsdfdsfdsfdfs" }; var invitationEntity = new InvitationEntity { Used = true, invitationKey = "fsdfsdfdsfdsfdfs" }; mapperMock .Setup(x => x.Map(It.IsAny <InvitationDTO>(), It.IsAny <InvitationEntity>())) .Returns(invitationEntity); // Act var saveResult = invitationManager.Save(invitationDTO); // Assert Assert.False(saveResult.Succeeded); Assert.True(saveResult.ErrorMessages.Count > 0); }
internal static void CreateInvitation() { var user1 = session.Load <UserEntity>(1); var Invitation = new InvitationEntity { invitationKey = "Key", User = user1, Used = false }; InsertEntity(Invitation); }
public async Task <ActionResult <MessageAndStatus> > InviteUserPermission(int listAggregationId, [FromBody] UserPermissionToListAggregation item) { var user = await _context.Users.Where(a => a.EmailAddress == item.User.EmailAddress).FirstOrDefaultAsync(); if (user == null) { return(await Task.FromResult(new MessageAndStatus { Status = "ERROR", Message = "User not exist." })); } var bbbb = _context.Invitations.Where(a => a.EmailAddress == item.User.EmailAddress && a.ListAggregatorId == listAggregationId).Any(); if (bbbb) { return(await Task.FromResult(new MessageAndStatus { Status = "ERROR", Message = "Ivitation is on list" })); } bbbb = _context.UserListAggregators.Where(a => a.UserId == user.UserId && a.ListAggregatorId == listAggregationId).Any(); if (bbbb) { return(await Task.FromResult(new MessageAndStatus { Status = "ERROR", Message = "User already has permission." })); } var senderName = HttpContext.User.Identity.Name; var invitationEntity = new InvitationEntity { EmailAddress = item.User.EmailAddress, ListAggregatorId = listAggregationId, PermissionLevel = item.Permission, SenderName = senderName }; _context.Add(invitationEntity); await _context.SaveChangesAsync(); return(await Task.FromResult(new MessageAndStatus { Status = "OK", Message = "Ivitation was added." })); }