Ejemplo n.º 1
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var flowReadRepositoryMock = new Mock <IFlowReadRepository>();

            flowReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var flowReadRepository = flowReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <FlowModel>(It.IsAny <object>())).Returns(new FlowModel());
            var mapper = mapperMock.Object;

            var query = new GetFlowQuery(id);

            var handler = new GetFlowQueryHandler(mapper, flowReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetFlowFailure);
        }
Ejemplo n.º 2
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var    id   = Guid.NewGuid();
            string name = "name";

            var flowReadRepositoryMock = new Mock <IFlowReadRepository>();

            flowReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Flow(id, name)));
            var flowReadRepository = flowReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <FlowModel>(It.IsAny <object>())).Returns(new FlowModel());
            var mapper = mapperMock.Object;

            var query = new GetFlowQuery(id);

            var handler = new GetFlowQueryHandler(mapper, flowReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <FlowModel>));
        }
Ejemplo n.º 3
0
        public async Task HandleShouldReturnFailWhenNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var flowReadRepositoryMock = new Mock <IFlowReadRepository>();

            flowReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var flowReadRepository = flowReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <FlowModel>(It.IsAny <object>())).Returns(new FlowModel());
            var mapper = mapperMock.Object;

            var query = new GetFlowQuery(id);

            var handler = new GetFlowQueryHandler(mapper, flowReadRepository);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotFound.Name);
        }