public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var layoutReadRepositoryMock = new Mock <ILayoutReadRepository>();

            layoutReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var layoutReadRepository = layoutReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetLayoutQuery(id);

            var handler = new GetLayoutQueryHandler(mapper, layoutReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetLayoutFailure);
        }
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var id = Guid.NewGuid();

            var layoutReadRepositoryMock = new Mock <ILayoutReadRepository>();

            layoutReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Layout(id, "name")));
            var layoutReadRepository = layoutReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetLayoutQuery(id);

            var handler = new GetLayoutQueryHandler(mapper, layoutReadRepository);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <LayoutModel>));
        }
        public async Task HandleShouldReturnFailWhenNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var layoutReadRepositoryMock = new Mock <ILayoutReadRepository>();

            layoutReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var layoutReadRepository = layoutReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetLayoutQuery(id);

            var handler = new GetLayoutQueryHandler(mapper, layoutReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotFound.Name);
        }
Esempio n. 4
0
        public GetLayoutQuery Map(GetLayoutRequest request)
        {
            var id = new Guid(request.RouteId);

            var result = new GetLayoutQuery(id);

            return(result);
        }
Esempio n. 5
0
 public Task <IMongoQueryable <LayoutDto> > Handle(GetLayoutQuery request, CancellationToken cancellationToken)
 {
     if (string.IsNullOrEmpty(request.Id))
     {
         return(Task.FromResult(_mongoDBContext.Database().GetCollection <LayoutDto>(request.LayoutName).AsQueryable()));
     }
     else
     {
         return(Task.FromResult(_mongoDBContext.Database().GetCollection <LayoutDto>(request.LayoutName).AsQueryable().Where(x => x.Id == request.Id)));
     }
 }
Esempio n. 6
0
        public void ShouldContainNoErrors()
        {
            // Arrange
            var query = new GetLayoutQuery(id: Guid.NewGuid());

            // Act
            var validationResult = _validator.Validate(query);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
Esempio n. 7
0
        public async Task <IQueryable <LayoutDto> > Handle(GetLayoutQuery request, CancellationToken cancellationToken)
        {
            var query = _dbContext.Table <LayoutDto>(request.LayoutName);

            if (string.IsNullOrEmpty(request.Id))
            {
                return(query);
            }
            else
            {
                return(await Task.FromResult(query.Where(x => x.Id == request.Id)));
            }
        }
Esempio n. 8
0
        public void ShouldHaveLayoutNotFoundCustomFailureWhenIdIsGuidEmpty()
        {
            // Arrange
            var query = new GetLayoutQuery(id: Guid.Empty);

            // Act
            var validationResult = _validator.Validate(query);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("Id") && a.ErrorMessage.Contains(CustomFailures.LayoutNotFound));

            // Assert
            exists.Should().BeTrue();
        }