public async Task <IActionResult> PostAssociatedOccurrence([FromBody] PostAssociatedOccurrencesParams param)
        {
            ApplicationUser user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Unauthorized());
            }

            var occurrences = new AssociatedOccurrences
            {
                ApplicationUserId = user.Id,
                OccurrenceId      = param.OccurrenceId,
                Type = param.TypeOfAssociation
            };

            var query  = _repo.GetAll();
            var result = query.FirstOrDefault(x =>
                                              (x.ApplicationUserId == user.Id) && (x.OccurrenceId == param.OccurrenceId) &&
                                              (x.Type == param.TypeOfAssociation));

            if (result != null)
            {
                return(BadRequest("Occurence already exists for user with this type"));
            }
            _repo.Add(occurrences);

            var occurencesDto = _mapper.Map <AssociatedOccurrencesDTO>(occurrences);

            return(Ok(occurencesDto));
        }
        public void TestPostAssociatedOccurrenceNegative()
        {
            var param = new PostAssociatedOccurrencesParams
            {
                OccurrenceId      = 20,
                TypeOfAssociation = "like"
            };

            var AssociatedDTO = new AssociatedOccurrencesDTO
            {
                ApplicationUserId = _testUser.Id,
                Id           = 500,
                OccurrenceId = 20,
                Type         = "like"
            };


            var associated1 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 30,
                ApplicationUserId = _testUser.Id,
                Type         = "like",
                OccurrenceId = 20
            };

            _occurrencesList.Add(associated1);

            _mockMapper.Setup(x =>
                              x.Map <AssociatedOccurrencesDTO>(It.IsAny <AssociatedOccurrences>())).Returns(AssociatedDTO);


            var response = _controller.PostAssociatedOccurrence(param).Result;
            var okResult = response.Should().BeOfType <BadRequestObjectResult>().Subject;
        }
        public void TestPostAssociatedOccurrencePositive()
        {
            var param = new PostAssociatedOccurrencesParams
            {
                OccurrenceId      = 20,
                TypeOfAssociation = "like"
            };

            var AssociatedDTO = new AssociatedOccurrencesDTO
            {
                ApplicationUserId = _testUser.Id,
                Id           = 500,
                OccurrenceId = 20,
                Type         = "like"
            };

            var associated1 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 30,
                ApplicationUserId = _testUser.Id,
                Type         = "like",
                OccurrenceId = 1
            };

            _occurrencesList.Add(associated1);

            _mockMapper.Setup(x =>
                              x.Map <AssociatedOccurrencesDTO>(It.IsAny <AssociatedOccurrences>())).Returns(AssociatedDTO);

            var response    = _controller.PostAssociatedOccurrence(param).Result;
            var okResult    = response.Should().BeOfType <OkObjectResult>().Subject;
            var occurrences = okResult.Value.Should().BeAssignableTo <AssociatedOccurrencesDTO>().Subject;

            occurrences.ApplicationUserId.Should().Be("testID");
            occurrences.Type.Should().Be("like");
            occurrences.Id.Should().Be(500);
            occurrences.OccurrenceId.Should().Be(20);
        }