Exemplo n.º 1
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var    id   = Guid.NewGuid();
            var    name = "name";
            var    nameOnApplication = "nameOnApplication";
            string description       = "description";
            var    icon = new RemarkIcon(Guid.NewGuid());

            var remarkReadRepositoryMock = new Mock <IRemarkReadRepository>();

            remarkReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Remark(id, name, nameOnApplication, description, icon)));
            var remarkReadRepository = remarkReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetRemarkQuery(id);

            var handler = new GetRemarkQueryHandler(mapper, remarkReadRepository);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <RemarkModel>));
        }
Exemplo n.º 2
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var remarkReadRepositoryMock = new Mock <IRemarkReadRepository>();

            remarkReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var remarkReadRepository = remarkReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetRemarkQuery(id);

            var handler = new GetRemarkQueryHandler(mapper, remarkReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetRemarkFailure);
        }
Exemplo n.º 3
0
        public async Task HandleShouldReturnFailWhenNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var remarkReadRepositoryMock = new Mock <IRemarkReadRepository>();

            remarkReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var remarkReadRepository = remarkReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetRemarkQuery(id);

            var handler = new GetRemarkQueryHandler(mapper, remarkReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotFound.Name);
        }
        public void ShouldContainNoErrors()
        {
            // Arrange
            var query            = new GetRemarkQuery(id: Guid.NewGuid());
            var validationResult = _validator.Validate(query);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
        public void ShouldHaveRemarkNotFoundCustomFailureWhenIdIsGuidEmpty()
        {
            // Arrange
            var query = new GetRemarkQuery(id: Guid.Empty);

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

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