Exemplo n.º 1
0
        public async Task <IActionResult> Insert([FromBody] CreateInterestDTO createInterestDTO)
        {
            if (createInterestDTO == null)
            {
                return(BadRequest(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty));
            }
            var result = await _interestService.InsertInterest(createInterestDTO);

            if (!result.IsSuccessed)
            {
                return(BadRequest(result.GetErrorString()));
            }
            return(Ok(result.IsSuccessed));
        }
Exemplo n.º 2
0
        public async Task <Result> InsertInterest(CreateInterestDTO createInterestDTO)
        {
            if (createInterestDTO == null)
            {
                return(Result.Fail(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty));
            }
            var interestResult = Interest.Create(createInterestDTO.InterestName, createInterestDTO.InterestDescription);

            if (!interestResult.IsSuccessed)
            {
                return(Result.Fail(interestResult.GetErrorString()));
            }

            _interestRepository.Create(interestResult.Value);
            return(await _interestRepository.SaveChangesAsync(InterestErrorMessages.Error_Occured_While_Inserting_Interest));
        }
Exemplo n.º 3
0
        public async Task Insert_Should_Return_Ok_Result_When_Valid_InterestsDTO_Is_Passed()
        {
            var testDto = new CreateInterestDTO();

            var mockInterestsService = new Mock <IInterestService>();

            mockInterestsService.Setup(x => x.InsertInterest(testDto)).ReturnsAsync(Result.Ok());

            var controller = new InterestController(mockInterestsService.Object);
            var result     = await controller.Insert(testDto);

            var contentResult = result as OkObjectResult;

            contentResult.StatusCode.Should().Be(200);
            contentResult.Value.Should().BeAssignableTo <bool>();
            var actualValue = contentResult.Value as bool?;

            actualValue.Should().BeTrue();
        }
Exemplo n.º 4
0
        public async Task InsertInterest_Should_Return_Success_Result()
        {
            var mockObject = new CreateInterestDTO()
            {
                InterestDescription = _mockInterestDTO.InterestDescription,
                InterestName        = _mockInterestDTO.InterestName
            };
            var mockMapper             = new Mock <IMapper>();
            var mockInterestRepository = new Mock <IInterestRepository>();

            mockMapper.Setup(x => x.Map <Interest>(It.IsAny <CreateInterestDTO>())).Returns(_mockInterest);
            mockInterestRepository.Setup(x => x.Create(It.IsAny <Interest>()));
            mockInterestRepository.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).ReturnsAsync(Result.Ok());

            var interestService = new InterestService(mockInterestRepository.Object, mockMapper.Object);
            var result          = await interestService.InsertInterest(mockObject);

            result.IsSuccessed.Should().BeTrue();
        }
Exemplo n.º 5
0
        public async Task InsertInterest_Should_Return_Failure_Result_When_Error_Occurs_While_Saving()
        {
            var mockObject = new CreateInterestDTO()
            {
                InterestDescription = _mockInterestDTO.InterestDescription,
                InterestName        = _mockInterestDTO.InterestName
            };
            var mockInterestRepository = new Mock <IInterestRepository>();

            mockInterestRepository.Setup(x => x.Create(It.IsAny <Interest>()));
            mockInterestRepository.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).ReturnsAsync(Result.Fail <Interest>(Constants.InterestErrorMessages.Error_Occured_While_Updating_Interest));

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Interest>(It.IsAny <CreateInterestDTO>())).Returns(_mockInterest);

            var interestService = new InterestService(mockInterestRepository.Object, mockMapper.Object);
            var result          = await interestService.InsertInterest(mockObject);

            result.IsSuccessed.Should().BeFalse();
            result.GetErrorString().Should().Be(Constants.InterestErrorMessages.Error_Occured_While_Updating_Interest);
        }