Exemplo n.º 1
0
        public async Task When_The_Event_Does_Not_Exist_Should_Return_Failure()
        {
            var eventRepository = new Mock <IEventRepository>();

            Maybe <Event> maybeEvent = null;

            eventRepository.Setup(it => it.FindById(It.IsAny <Guid>())).Returns(Task.FromResult(maybeEvent));

            var destroyEvent = new DestroyEvent(Guid.NewGuid());

            var handler = new DestroyEventHandler(eventRepository.Object);

            Result result = await handler.Handle(destroyEvent, CancellationToken.None);

            Assert.True(result.IsFailure);
        }
Exemplo n.º 2
0
        public async Task Should_Return_Success()
        {
            var eventRepository = new Mock <IEventRepository>();

            Maybe <Event> maybeEvent = new Event(Guid.NewGuid(), "Christmas", new DateTime(year: 2020, month: 6, day: 25));

            var destroyEvent = new DestroyEvent(Guid.NewGuid());

            eventRepository.Setup(it => it.FindById(It.IsAny <Guid>())).Returns(Task.FromResult(maybeEvent));

            var handler = new DestroyEventHandler(eventRepository.Object);

            Result result = await handler.Handle(destroyEvent, CancellationToken.None);

            Assert.True(result.IsSuccess);
        }
Exemplo n.º 3
0
        public async Task When_The_Event_Is_Not_Removed_Should_Return_Failure()
        {
            var eventRepository = new Mock <IEventRepository>();

            Maybe <Event> maybeEvent = new Event(Guid.NewGuid(), "Christmas", new DateTime(year: 2020, month: 6, day: 25));

            eventRepository.Setup(it => it.FindById(It.IsAny <Guid>())).Returns(Task.FromResult(maybeEvent));

            eventRepository.Setup(it => it.Remove(It.IsAny <Event>())).Returns(Task.FromResult(Result.Failure("Something has gone wrong...")));

            var destroyEvent = new DestroyEvent(Guid.NewGuid());

            var handler = new DestroyEventHandler(eventRepository.Object);

            Result result = await handler.Handle(destroyEvent, CancellationToken.None);

            Assert.True(result.IsFailure);
        }