Ejemplo n.º 1
0
        public void ShouldNotThrowWhenNonVoidMethodIsSynchronizedCorrectly()
        {
            //GIVEN
            var wrappedObjectMock = Substitute.For <IMyService>();
            var service           = new SemaphoreSynchronizedMyService(wrappedObjectMock, Semaphore());

            //WHEN - THEN
            service.Should().SynchronizeAccessTo(s => s.CallWithResult("alabama"), Blocking.On(service.Lock), wrappedObjectMock);
        }
Ejemplo n.º 2
0
        public async Task ShouldThrowWhenAsyncMethodDoesNotExitSynchronizationOnException()
        {
            //GIVEN
            var wrappedObjectMock = Substitute.For <IMyService>();
            var service           = new SemaphoreSynchronizedMyService(wrappedObjectMock, Semaphore());

            //WHEN - THEN
            await service.Awaiting(s => s.Should().SynchronizeAsyncAccessTo(s => s.AsyncCallNotExitedOnException(1), Blocking.On(service.Lock), wrappedObjectMock))
            .Should().ThrowExactlyAsync <XunitException>();
        }
Ejemplo n.º 3
0
        public void ShouldThrowWhenVoidMethodDoesNotExitSynchronizationOnException()
        {
            //GIVEN
            var wrappedObjectMock = Substitute.For <IMyService>();
            var service           = new SemaphoreSynchronizedMyService(wrappedObjectMock, Semaphore());

            //WHEN - THEN
            new Action(() =>
                       service.Should().SynchronizeAccessTo(s => s.VoidCallNotExitedOnException(1), Blocking.On(service.Lock), wrappedObjectMock))
            .Should().ThrowExactly <ReceivedCallsException>();
        }
Ejemplo n.º 4
0
        public async Task ShouldNotThrowWhenAsyncMethodIsSynchronizedCorrectly()
        {
            //GIVEN
            var wrappedObjectMock = Substitute.For <IMyService>();
            var service           = new SemaphoreSynchronizedMyService(wrappedObjectMock, Semaphore());

            //WHEN - THEN
            await service.Should().SynchronizeAsyncAccessTo(
                s => s.AsyncCall(1),
                Blocking.On(service.Lock),
                wrappedObjectMock);
        }
Ejemplo n.º 5
0
        public void ShouldThrowWhenNonVoidMethodDoesNotExitSynchronization()
        {
            //GIVEN
            var wrappedObjectMock = Substitute.For <IMyService>();
            var service           = new SemaphoreSynchronizedMyService(wrappedObjectMock, Semaphore());

            //WHEN - THEN
            new Action(() =>
                       service.Should().SynchronizeAccessTo(s => s.CallWithResultNotExited("alabama"),
                                                            Blocking.On(service.Lock), wrappedObjectMock))
            .Should().ThrowExactly <XunitException>();
        }