public static async Task <Guid> CreateAsync(DbContextOptions <MemCheckDbContext> testDB, Guid creatorId, string?name = null, string?versionDescription = null, DateTime?lastChangeUtcDate = null, string?source = null, string?description = null) { using var dbContext = new MemCheckDbContext(testDB); var creator = await dbContext.Users.SingleAsync(u => u.Id == creatorId); var originalBlob = new[] { (byte)0, (byte)0, (byte)0, (byte)0 }; var smallBlob = new[] { (byte)0 }; var mediumBlob = new[] { (byte)0, (byte)0 }; var bigBlob = new[] { (byte)0, (byte)0, (byte)0 }; var result = new Image { Owner = creator, Name = name ?? RandomHelper.String(), Description = description ?? RandomHelper.String(), Source = source ?? RandomHelper.String(), InitialUploadUtcDate = lastChangeUtcDate ?? DateTime.UtcNow, LastChangeUtcDate = lastChangeUtcDate ?? DateTime.UtcNow, VersionDescription = versionDescription ?? RandomHelper.String(), VersionType = ImageVersionType.Creation, OriginalContentType = "InvalidForUnitTests", OriginalSize = originalBlob.Length, OriginalBlob = originalBlob, SmallBlobSize = smallBlob.Length, SmallBlob = smallBlob, MediumBlobSize = mediumBlob.Length, MediumBlob = mediumBlob, BigBlobSize = bigBlob.Length, BigBlob = bigBlob }; dbContext.Images.Add(result); await dbContext.SaveChangesAsync(); return(result.Id); }
public static async Task SetRandomPasswordAsync(DbContextOptions <MemCheckDbContext> db, Guid userId) { using var dbContext = new MemCheckDbContext(db); var userToDelete = dbContext.Users.Single(u => u.Id == userId); using var userManager = GetUserManager(dbContext); var addPasswordResult = await userManager.AddPasswordAsync(userToDelete, RandomHelper.String().ToUpperInvariant() + RandomHelper.String()); Assert.IsTrue(addPasswordResult.Succeeded); }
public static MemCheckUser Create(int minimumCountOfDaysBetweenNotifs = 0, DateTime?lastNotificationUtcDate = null, bool subscribeToCardOnEdit = false, string?userName = null) { return(new MemCheckUser { MinimumCountOfDaysBetweenNotifs = minimumCountOfDaysBetweenNotifs, LastNotificationUtcDate = lastNotificationUtcDate ?? DateTime.MinValue, SubscribeToCardOnEdit = subscribeToCardOnEdit, UserName = userName ?? RandomHelper.String() }); }
public static async Task <Guid> CreateAsync(DbContextOptions <MemCheckDbContext> testDB, string?name = null, string?description = null) { using var dbContext = new MemCheckDbContext(testDB); var result = new Tag { Name = name ?? RandomHelper.String(), Description = description ?? RandomHelper.String() }; dbContext.Tags.Add(result); await dbContext.SaveChangesAsync(); return(result.Id); }
public static async Task <Guid> CreateAsync(DbContextOptions <MemCheckDbContext> testDB, Guid ownerId, string?description = null, int algorithmId = UnitTestsHeapingAlgorithm.ID) { using var dbContext = new MemCheckDbContext(testDB); var result = new Deck { Owner = await dbContext.Users.SingleAsync(u => u.Id == ownerId), Description = description ?? RandomHelper.String(), CardInDecks = Array.Empty <CardInDeck>(), HeapingAlgorithmId = algorithmId }; dbContext.Decks.Add(result); await dbContext.SaveChangesAsync(); return(result.Id); }
public static UpdateCard.Request RequestForAdditionalInfoChange(Card card, string additionalInfo, Guid?versionCreator = null, string?versionDescription = null) { return(new UpdateCard.Request( card.Id, versionCreator ?? card.VersionCreator.Id, card.FrontSide, card.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId), card.BackSide, card.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId), additionalInfo, card.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId), card.CardLanguage.Id, card.TagsInCards.Select(t => t.TagId), card.UsersWithView.Select(uwv => uwv.UserId), versionDescription ?? RandomHelper.String() )); }
public static UpdateCard.Request RequestForVisibilityChange(Card card, IEnumerable <Guid> userWithViewIds, Guid?versionCreator = null, string?versionDescription = null) { return(new UpdateCard.Request( card.Id, versionCreator ?? card.VersionCreator.Id, card.FrontSide, card.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId), card.BackSide, card.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId), card.AdditionalInfo, card.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId), card.CardLanguage.Id, card.TagsInCards.Select(t => t.TagId), userWithViewIds, versionDescription ?? RandomHelper.String() )); }
public static UpdateCard.Request RequestForImageChange(Card card, IEnumerable <Guid> frontImages, IEnumerable <Guid> backImages, IEnumerable <Guid> additionalInfoImages, Guid?versionCreator = null, string?versionDescription = null) { return(new UpdateCard.Request( card.Id, versionCreator ?? card.VersionCreator.Id, card.FrontSide, frontImages, card.BackSide, backImages, card.AdditionalInfo, additionalInfoImages, card.CardLanguage.Id, card.TagsInCards.Select(t => t.TagId), card.UsersWithView.Select(uwv => uwv.UserId), versionDescription ?? RandomHelper.String() )); }
public static UpdateCard.Request RequestForTagChange(Card card, IEnumerable <Guid> tagIds, string?versionDescription = null) { return(new UpdateCard.Request( card.Id, card.VersionCreator.Id, card.FrontSide, card.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId), card.BackSide, card.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId), card.AdditionalInfo, card.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId), card.CardLanguage.Id, tagIds, card.UsersWithView.Select(uwv => uwv.UserId), versionDescription ?? RandomHelper.String() )); }
public static async Task <SearchSubscription> CreateAsync(DbContextOptions <MemCheckDbContext> testDB, Guid subscriberId, string?name = null, string requiredText = "", Guid?excludedDeckId = null, DateTime?lastNotificationDate = null) { using var dbContext = new MemCheckDbContext(testDB); var result = new SearchSubscription { UserId = subscriberId, Name = name ?? RandomHelper.String(), ExcludedDeck = excludedDeckId == null ? Guid.Empty : excludedDeckId.Value, RequiredText = requiredText, RequiredTags = Array.Empty <RequiredTagInSearchSubscription>(), ExcludeAllTags = false, ExcludedTags = Array.Empty <ExcludedTagInSearchSubscription>(), LastRunUtcDate = lastNotificationDate != null ? lastNotificationDate.Value : DateTime.MinValue, RegistrationUtcDate = lastNotificationDate != null ? lastNotificationDate.Value : DateTime.MinValue }; dbContext.SearchSubscriptions.Add(result); await dbContext.SaveChangesAsync(); return(result); }
public static async Task <Card> CreateAsync(DbContextOptions <MemCheckDbContext> testDB, Guid versionCreatorId, DateTime?versionDate = null, IEnumerable <Guid>?userWithViewIds = null, Guid?language = null, IEnumerable <Guid>?tagIds = null, string?frontSide = null, string?backSide = null, string?additionalInfo = null, IEnumerable <Guid>?frontSideImages = null, IEnumerable <Guid>?additionalSideImages = null, string?versionDescription = null) { //userWithViewIds null means public card using var dbContext = new MemCheckDbContext(testDB); var creator = await dbContext.Users.Where(u => u.Id == versionCreatorId).SingleAsync(); var result = new Card { VersionCreator = creator, FrontSide = frontSide ?? RandomHelper.String(), BackSide = backSide ?? RandomHelper.String(), AdditionalInfo = additionalInfo ?? RandomHelper.String(), VersionDescription = versionDescription ?? RandomHelper.String(), VersionType = CardVersionType.Creation }; if (language == null) { language = await CardLanguagHelper.CreateAsync(testDB); } result.CardLanguage = await dbContext.CardLanguages.SingleAsync(l => l.Id == language); if (versionDate != null) { result.InitialCreationUtcDate = versionDate.Value; result.VersionUtcDate = versionDate.Value; } dbContext.Cards.Add(result); var usersWithView = new List <UserWithViewOnCard>(); if (userWithViewIds != null && userWithViewIds.Any()) { Assert.IsTrue(userWithViewIds.Any(id => id == versionCreatorId), "Version creator must be allowed to view"); foreach (var userWithViewId in userWithViewIds) { var userWithView = new UserWithViewOnCard { CardId = result.Id, UserId = userWithViewId }; dbContext.UsersWithViewOnCards.Add(userWithView); usersWithView.Add(userWithView); } } result.UsersWithView = usersWithView; var tags = new List <TagInCard>(); if (tagIds != null) { foreach (var tagId in tagIds) { var tagInCard = new TagInCard { CardId = result.Id, TagId = tagId }; dbContext.TagsInCards.Add(tagInCard); tags.Add(tagInCard); } } result.TagsInCards = tags; var images = new List <ImageInCard>(); if (frontSideImages != null) { foreach (var frontSideImage in frontSideImages) { var img = new ImageInCard() { ImageId = frontSideImage, CardId = result.Id, CardSide = ImageInCard.FrontSide }; dbContext.ImagesInCards.Add(img); images.Add(img); } } if (additionalSideImages != null) { foreach (var additionalSideImage in additionalSideImages) { var img = new ImageInCard() { ImageId = additionalSideImage, CardId = result.Id, CardSide = ImageInCard.AdditionalInfo }; dbContext.ImagesInCards.Add(img); images.Add(img); } } result.Images = images; await dbContext.SaveChangesAsync(); return(result); }