Пример #1
0
        public void Lock_When_Record_Is_Successfully_Locked_Then_Returns_Updated_Result()
        {
            // 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;

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

            var result = sut.Lock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                lockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldNotHaveErrors();
            result.ResultObject.ShouldNotBeNull();
            result.ResultObject.LockedById.ShouldBe(1);
            result.ResultObject.LockedUntil.ShouldNotBeNull();
        }
Пример #2
0
        public void Lock_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.Lock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                lockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(ErrorConstants.BASIC_ERROR_KEY);;
        }
Пример #3
0
        public void Lock_When_Record_Is_Already_Locked_Then_Returns_Errors()
        {
            // Arrange
            var record = new LockableEntity()
            {
                LockedUntil = GetFifteenMinutesInTheFuture()
            };

            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.Lock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                lockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <LockableEntity> .ERROR_LOCK_RECORD_ALREADY_LOCKED);
        }
Пример #4
0
        public void Lock_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.Lock(
                id: 1,
                lockUntil: GetFifteenMinutesInTheFuture(),
                lockedById: 1
                );

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <Lockable> .ERROR_LOCK_RECORD_NOT_FOUND);
        }
Пример #5
0
        public void Lock_When_LockUntil_Is_In_The_Past_Then_Returns_Errors()
        {
            // Arrange
            var repositoryReadConductor = new Mock <IRepositoryReadConductor <LockableEntity> >()
                                          .SetupFindByIdReturnsGivenResult(1, new LockableEntity()).Object;

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

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

            // Assert
            result.ShouldNotBeNull();
            result.ShouldHaveErrorsFor(LockingConductor <LockableEntity> .ERROR_LOCK_TIME_IN_PAST);
        }