Пример #1
0
        public async Task DeleteAsync_WithNullKey_ReturnsFalse()
        {
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            await context.Invitations.AddRangeAsync(
                new Invitation
            {
                Key = "key002"
            },
                new Invitation
            {
                Key = "key003"
            });

            context.SaveChanges();

            var invitationsService = new InvitationsService(new EfRepository <Invitation>(context),
                                                            null, null, null, null, null);

            // Act
            var result = await invitationsService.DeleteAsync(null);

            // Assert
            Assert.False(result);

            var invitationsCount = await context.Invitations.CountAsync();

            Assert.Equal(2, invitationsCount);
        }
Пример #2
0
        public async Task DeleteAsync_WithCorrectKey_WorksCorrectly()
        {
            const string testKey = "key111";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            await context.Invitations.AddRangeAsync(
                new Invitation
            {
                Key = testKey
            },
                new Invitation
            {
                Key = "key002"
            },
                new Invitation
            {
                Key = "key003"
            });

            context.SaveChanges();

            var invitationsService = new InvitationsService(new EfRepository <Invitation>(context),
                                                            null, null, null, null, null);

            // Act
            var result = await invitationsService.DeleteAsync(testKey);

            // Assert
            Assert.True(result);

            var invitationExists = await context.Invitations.AnyAsync(i => i.Key == testKey);

            Assert.False(invitationExists);
        }