Beispiel #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);
        }
Beispiel #2
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>();
        }
Beispiel #3
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);
        }
Beispiel #4
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>();
        }