Example #1
0
        public async Task RemoveActor_WithoutActor_False()
        {
            //Arrange
            var context = GenerateEnumerableEmptyContextMock();
            //context.Setup(x => x.Actors.FindAsync(It.IsAny<int>())).ReturnsAsync(null);
            var service = new ActorsService(context.Object);

            //Act
            var result = await service.RemoveActor(1);

            //Assert
            Assert.False(result);
        }
Example #2
0
        public async Task RemoveActor_HasActor_True()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            //Act
            var result = await service.RemoveActor(1);

            //Assert
            Assert.True(result);
        }
Example #3
0
        public async Task RemoveActor_HasActor_RemoveAndSaveChanges()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            //Act
            await service.RemoveActor(1);

            //Assert
            context.Verify(x => x.Actors.Remove(It.IsAny <Actor>()), Times.Once);
            context.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once);
        }