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 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 TestDeleteAssociatedOccurrencePositive()
        {
            var param = new IdParam
            {
                Id = 20
            };

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

            _occurrencesList.Add(associated1);

            var response = _controller.DeleteAssociatedOccurrence(param).Result;
            var okResult = response.Should().BeOfType <NoContentResult>().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);
        }
        public void TestGetUserTypesPositive()
        {
            var associated1 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = _testUser.Id,
                Type         = "like",
                OccurrenceId = 1
            };
            var associated2 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = _testUser.Id,
                Type         = "heart",
                OccurrenceId = 1
            };
            var associated3 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = _testUser.Id,
                Type         = "follow",
                OccurrenceId = 1
            };

            _occurrencesList.Add(associated1);
            _occurrencesList.Add(associated2);
            _occurrencesList.Add(associated3);

            var response   = _controller.GetUserTypes().Result;
            var okResult   = response.Should().BeOfType <OkObjectResult>().Subject;
            var returnList = okResult.Value.Should().BeAssignableTo <IEnumerable <string> >().Subject.ToList();

            returnList[0].Should().Be("like");
            returnList[1].Should().Be("heart");
            returnList[2].Should().Be("follow");
        }
        public void TestDeleteAssociatedOccurrenceNegative()
        {
            var param = new IdParam
            {
                Id = 21
            };

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

            _occurrencesList.Add(associated1);

            var response     = _controller.DeleteAssociatedOccurrence(param).Result;
            var okResult     = response.Should().BeOfType <NotFoundObjectResult>().Subject;
            var returnString = okResult.Value.Should().BeAssignableTo <string>().Subject;
        }
        public void TestGetUserTypesNegative()
        {
            var falseId     = "falseTestId";
            var associated1 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = falseId,
                Type         = "like",
                OccurrenceId = 1
            };
            var associated2 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = falseId,
                Type         = "heart",
                OccurrenceId = 1
            };
            var associated3 = new AssociatedOccurrences
            {
                ApplicationUser = _testUser,
                Id = 20,
                ApplicationUserId = falseId,
                Type         = "follow",
                OccurrenceId = 1
            };

            _occurrencesList.Add(associated1);
            _occurrencesList.Add(associated2);
            _occurrencesList.Add(associated3);

            var response     = _controller.GetUserTypes().Result;
            var okResult     = response.Should().BeOfType <NotFoundObjectResult>().Subject;
            var returnString = okResult.Value.Should().BeAssignableTo <string>().Subject;

            returnString.Should().Be("User doesnt have any lists");
        }