예제 #1
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var instructionReadRepositoryMock = new Mock <IInstructionReadRepository>();

            instructionReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var instructionReadRepository = instructionReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInstructionQuery(id);

            var handler = new GetInstructionQueryHandler(mapper, instructionReadRepository);

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

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

            var instructionReadRepositoryMock = new Mock <IInstructionReadRepository>();

            instructionReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Instruction(id, "name", "description", "icon", "content", "image", "video")));
            var instructionReadRepository = instructionReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInstructionQuery(id);

            var handler = new GetInstructionQueryHandler(mapper, instructionReadRepository);

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

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

            var instructionReadRepositoryMock = new Mock <IInstructionReadRepository>();

            instructionReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var instructionReadRepository = instructionReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

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

            var query = new GetInstructionQuery(id);

            var handler = new GetInstructionQueryHandler(mapper, instructionReadRepository);

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

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