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

            var inputReadRepositoryMock = new Mock <IInputReadRepository>();

            inputReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var inputReadRepository = inputReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInputQuery(id);

            var handler = new GetInputQueryHandler(mapper, inputReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetInputFailure);
        }
Esempio n. 2
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var  id          = Guid.NewGuid();
            var  name        = "name";
            var  description = "description";
            Guid icon        = Guid.NewGuid();
            var  instruction = "instruction";

            var inputReadRepositoryMock = new Mock <IInputReadRepository>();

            inputReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Input(id, name, description, icon, instruction)));
            var inputReadRepository = inputReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInputQuery(id);

            var handler = new GetInputQueryHandler(mapper, inputReadRepository);

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

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

            var inputReadRepositoryMock = new Mock <IInputReadRepository>();

            inputReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var inputReadRepository = inputReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInputQuery(id);

            var handler = new GetInputQueryHandler(mapper, inputReadRepository);

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

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