示例#1
0
        public void DeleteUserById_Action_Fails()
        {
            // Arrange
            GenericServiceResponse <bool> fakeResponse = null;

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.UserService.DeleteUser(It.IsAny <int>())).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericViewModel();

            var action = new DeleteUserById <GenericViewModel>(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericViewModel));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 1);
            Assert.IsTrue(result.HasErrors);
            Assert.IsNotNull(result.Success);
            Assert.IsInstanceOfType(result.Success, typeof(bool));
            Assert.IsFalse(result.Success);
        }
示例#2
0
        public void Invoke_EmptyGuid_DeleteNorSaveAreCalled()
        {
            // prepare
            var mockedUserRepository = new Mock <IUserRepository>();
            var mockedUnitOfWork     = new Mock <IUnitOfWork>();

            var action = new DeleteUserById(mockedUserRepository.Object, mockedUnitOfWork.Object);

            // action
            var result = action.Invoke(new Guid());

            // assert
            Assert.False(result);
            mockedUserRepository.Verify(r => r.Delete(It.IsAny <DataAccess.Models.User>()), Times.Never);
            mockedUnitOfWork.Verify(r => r.Save(), Times.Never);
            mockedUserRepository.Verify(r => r.GetById(It.IsAny <Guid>()), Times.Never);
        }
示例#3
0
        public void Invoke_ValidData_DeleteAndSaveAreCalled()
        {
            // prepare
            var guid       = Guid.NewGuid();
            var userFromDb = new DataAccess.Models.User
            {
                Id = guid
            };

            var mockedUserRepository = new Mock <IUserRepository>();

            mockedUserRepository.Setup(r => r.GetById(guid)).Returns(userFromDb);
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            var action = new DeleteUserById(mockedUserRepository.Object, mockedUnitOfWork.Object);

            // action
            var result = action.Invoke(guid);

            // assert
            Assert.True(result);
            mockedUserRepository.Verify(r => r.Delete(It.IsAny <DataAccess.Models.User>()), Times.Once());
            mockedUnitOfWork.Verify(r => r.Save(), Times.Once());
        }