CreateGroup_GroupWithSuchNameAlreadyExists_ThrowExceptionThatSuchGroupNameExists() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase( "CreateGroup_GroupWithSuchNameAlreadyExists_ThrowExceptionThatSuchGroupNameExists") .Options; using (var context = new ApplicationDbContext(options)) { context.Add(new EmojiGroup { Name = "Emotion" }); context.SaveChanges(); var emojiService = new EmojiService(context); Assert.Throws <SuchGroupNameAlreadyExists>(() => { emojiService.CreateGroup(new CreateGroupEmojiInputModel { Name = "Emotion" }); }); } }
CreateGroup_OneNormalGroup_DatabaseContainsGroup() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase( "CreateGroup_OneNormalGroup_DatabaseContainsGroup") .Options; using (var context = new ApplicationDbContext(options)) { var emojiService = new EmojiService(context); emojiService.CreateGroup(new CreateGroupEmojiInputModel { Name = "1", Priority = 1, EmojiSequence = "😐 😌 🤗" }); Assert.Equal(1, context.EmojiGroups.Count()); var emojiGroup = context.EmojiGroups.Include(p => p.Emojis).FirstOrDefault(); Assert.NotNull(emojiGroup); Assert.Equal("1", emojiGroup.Name); Assert.Equal(1, emojiGroup.Priority); Assert.Equal(3, emojiGroup.Emojis.Count()); } }