Ejemplo n.º 1
0
        public void UserService_DeleteAsync_DeletesAndReturnsOK()
        {
            // Arrange
            var ids = new string[] { "dummyEntryId1" };

            var dbEntry = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = true,
                Password = "******" };

            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId1")).Returns(Task.FromResult<DBUser>(dbEntry));
            mockAppUserManager.Setup(x => x.DeleteAsync(dbEntry)).Returns(Task.FromResult(IdentityResult.Success));

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.DeleteAsync(ids).Wait();

            //Assert
            mockAppUserManager.Verify(m => m.DeleteAsync(It.IsIn(new DBUser[] { dbEntry })), Times.Once());
        }
Ejemplo n.º 2
0
        public void UserService_DeleteAsync_ReturnsDeleteError()
        {
            // Arrange
            var ids = new string[] { "dummyEntryId1", "dummyEntryId11" };

            var dbEntry = new DBUser { Id = "dummyEntryId1", UserName = "******", Email = "Email2", LDAPAuthenticated_bl = true, Password = "******" };


            var mockAppUserManager = new Mock<IAppUserManager>();
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId11")).Returns(Task.FromResult<DBUser>(null));
            mockAppUserManager.Setup(x => x.FindByIdAsync("dummyEntryId1")).Returns(Task.FromResult<DBUser>(dbEntry));
            mockAppUserManager.Setup(x => x.DeleteAsync(dbEntry)).Returns(Task.FromResult(IdentityResult.Failed(new[] { "Error deleting dbentry" })));

            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();

            var dbUserService = new DBUserService(mockDbContextScopeFac.Object, mockAppUserManager.Object, true);

            //Act   
            dbUserService.DeleteAsync(ids).Wait();

            //Assert
            
        }