Exemplo n.º 1
0
        public void Unlock_When_Update_Returns_Errors_Then_Returns_Errors()
        {
            // Arrange
            var repositoryUpdateConductorMock = new Mock <IRepositoryUpdateConductor <LockableEntity> >();

            repositoryUpdateConductorMock
            .Setup(m => m.Update(It.IsAny <LockableEntity>(), It.IsAny <long?>()))
            .ReturnsBasicErrorResult();

            var repositoryReadConductor = new Mock <IRepositoryReadConductor <LockableEntity> >()
                                          .SetupFindByIdReturnsGivenResult(1, new LockableEntity()).Object;
            var repositoryUpdateConductor = repositoryUpdateConductorMock.Object;

            var sut = new LockingConductor <LockableEntity>(
                logger: _logger,
                repositoryReadConductor: repositoryReadConductor,
                repositoryUpdateConductor: repositoryUpdateConductor
                );

            // Act
            var result = sut.Unlock(
                id: 1,
                unlockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(ErrorConstants.BASIC_ERROR_KEY);;
        }
Exemplo n.º 2
0
        public void Unlock_When_Record_Is_Unlocked_Then_Returns_Updated_Record()
        {
            // Arrange
            var repositoryUpdateConductorMock = new Mock <IRepositoryUpdateConductor <LockableEntity> >();

            repositoryUpdateConductorMock
            .Setup(m => m.Update(It.IsAny <LockableEntity>(), It.IsAny <long?>()))
            .ReturnsGivenResult(true);

            var repositoryReadConductor = new Mock <IRepositoryReadConductor <LockableEntity> >()
                                          .SetupFindByIdReturnsGivenResult(1, new LockableEntity()).Object;
            var repositoryUpdateConductor = repositoryUpdateConductorMock.Object;

            var sut = new LockingConductor <LockableEntity>(
                logger: _logger,
                repositoryReadConductor: repositoryReadConductor,
                repositoryUpdateConductor: repositoryUpdateConductor
                );

            // Act
            var result = sut.Unlock(
                id: 1,
                unlockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldNotHaveErrors();
            result.ResultObject.ShouldNotBeNull();
            result.ResultObject.IsLocked.ShouldBeFalse();
            result.ResultObject.LockedOn.ShouldBeNull();
            result.ResultObject.LockedUntil.ShouldBeNull();
            result.ResultObject.LockedById.ShouldBeNull();
        }
Exemplo n.º 3
0
        public void Unlock_When_FindById_Returns_Null_ResultObject_Then_Returns_Errors()
        {
            // Arrange
            var repositoryReadConductor = new Mock <IRepositoryReadConductor <LockableEntity> >()
                                          .SetupFindByIdReturnsGivenResult(1, null).Object;

            var sut = new LockingConductor <LockableEntity>(
                logger: _logger,
                repositoryReadConductor: repositoryReadConductor,
                repositoryUpdateConductor: null
                );

            // Act
            var result = sut.Unlock(
                id: 1,
                unlockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <Lockable> .ERROR_UNLOCK_RECORD_NOT_FOUND);
        }
Exemplo n.º 4
0
        public void Unlock_When_FindById_Returns_Errors_Then_Returns_Errors()
        {
            // Arrange
            var repositoryReadConductor = new Mock <IRepositoryReadConductor <LockableEntity> >()
                                          .SetupFindByIdReturnsBasicErrorResult(1).Object;

            var sut = new LockingConductor <LockableEntity>(
                logger: _logger,
                repositoryReadConductor: repositoryReadConductor,
                repositoryUpdateConductor: null
                );

            // Act
            var result = sut.Unlock(
                id: 1,
                unlockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(ErrorConstants.BASIC_ERROR_KEY);;
        }