Exemplo n.º 1
0
        public void ExtendLock_When_Lock_Time_Is_In_Past_Then_Returns_Errors()
        {
            // Arrange
            var record = new LockableEntity()
            {
                LockedById  = 1,
                LockedUntil = DateTimeOffset.Now.AddMinutes(10)
            };

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

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

            // Act
            var result = sut.ExtendLock(
                id: 1,
                lockUntil: DateTimeOffset.Now.AddMinutes(-15),
                updatedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <LockableEntity> .ERROR_EXTEND_LOCK_LOCK_TIME_IN_PAST);
        }
Exemplo n.º 2
0
        public void ExtendLock_When_Record_Is_Locked_By_Another_User_Then_Returns_Errors()
        {
            // Arrange
            var record = new LockableEntity()
            {
                LockedById  = 2,
                LockedUntil = DateTimeOffset.Now.AddMinutes(15)
            };

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

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

            // Act
            var result = sut.ExtendLock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                updatedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <LockableEntity> .ERROR_EXTEND_LOCK_LOCKED_BY_DIFFERENT_USER);
        }
Exemplo n.º 3
0
        public void ExtendLock_When_Record_Is_Not_Locked_Then_Returns_Errors()
        {
            // Arrange
            var record = new LockableEntity()
            {
                LockedUntil = null
            };

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

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

            // Act
            var result = sut.ExtendLock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                updatedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <LockableEntity> .ERROR_EXTEND_LOCK_RECORD_NOT_LOCKED);
        }
Exemplo n.º 4
0
        public void ExtendLock_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.ExtendLock(1, GetFifteenMinutesInTheFuture(), 1);

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(ErrorConstants.BASIC_ERROR_KEY);;
        }
Exemplo n.º 5
0
        public void ExtendLock_When_Lock_Time_Is_Extended_Then_Returns_Updated_Record()
        {
            // Arrange
            var lockedUntil = DateTimeOffset.Now.AddMinutes(5);
            var record      = new LockableEntity()
            {
                LockedById  = 1,
                LockedOn    = DateTimeOffset.Now,
                LockedUntil = lockedUntil
            };

            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, record).Object;
            var repositoryUpdateConductor = repositoryUpdateConductorMock.Object;

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

            // Act
            var result = sut.ExtendLock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                updatedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldNotHaveErrors();
            result.ResultObject.ShouldNotBeNull();
            result.ResultObject.LockedUntil.ShouldNotBeNull();
            result.ResultObject.LockedUntil.Value.ShouldBeGreaterThan(lockedUntil);
        }
Exemplo n.º 6
0
        public void ExtendLock_When_Update_Returns_Errors_Then_Returns_Errors()
        {
            var record = new LockableEntity()
            {
                LockedById  = 1,
                LockedOn    = DateTimeOffset.Now,
                LockedUntil = DateTimeOffset.Now.AddMinutes(5)
            };

            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, record).Object;
            var repositoryUpdateConductor = repositoryUpdateConductorMock.Object;

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

            // Act
            var result = sut.ExtendLock(
                id: 1,
                lockUntil: DateTimeOffset.Now.AddMinutes(15),
                updatedById: 1
                );

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