Beispiel #1
0
        public UserSessionPetCareResponse UpdatePetMetrics(int userId, int petId, int interactionId)
        {
            var userSessionState = _state.GetUserSession(userId);

            if (userSessionState == null)
            {
                var errorResponse = new UserSessionPetCareResponse();
                return(errorResponse.SetErrorResponse(new ErrorMessage(ErrorCode.UserSessionNotFound)));
            }

            var payload = new UserPetCareAction()
            {
                UserId        = userId,
                PetId         = petId,
                InteractionId = interactionId
            };

            var sessionRequest = new UserSessionRequest <IUserSessionData>()
            {
                Payload     = payload,
                RequestType = RequestType.Update,
                UserId      = userId
            };

            IResponse response;

            userSessionState.ProcessRequest(sessionRequest, out response);
            return((UserSessionPetCareResponse)response);
        }
        Given_a_UserPetCareAction_request_with_default_payload_fields_then_when_validated_returns_false_with_correct_error(
            int petId, int interactionId, int userId)
        {
            //Arrange
            var payload = new UserPetCareAction()
            {
                UserId        = userId,
                PetId         = petId,
                InteractionId = interactionId
            };

            //Act
            ErrorMessage error;
            var          result = _sut.IsValid(TestData.Users.MeJulie, payload, out error);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(error.Code, ErrorCode.MissingField);

            if (userId == default(int))
            {
                StringAssert.Contains(nameof(payload.UserId), error.Message);
            }
            if (interactionId == default(int))
            {
                StringAssert.Contains(nameof(payload.InteractionId), error.Message);
            }
            if (petId == default(int))
            {
                StringAssert.Contains(nameof(payload.PetId), error.Message);
            }
        }
Beispiel #3
0
        public PetVital UpdatePetVital(IList <MetricInteraction> metricInteraction, UserPetCareAction petCareAction)
        {
            var pet       = _petRepository.Find(petCareAction.PetId);
            var metricIds = metricInteraction.Select(m => m.MetricId);

            var petMetric = _petRepository.FindAssociated(pet)
                            .FirstOrDefault(pm => metricIds.Contains(pm.MetricId));

            var speciesVital = _speciesBuilder.Create(pet.AnimalId).HealthMetrics
                               .FirstOrDefault(vital => metricIds.Contains(vital.VitalId));

            var speciesCareAction = speciesVital?.RequiredCareActions
                                    .FirstOrDefault(careAction => careAction.InteractionId == petCareAction.InteractionId);

            return(_petVitalBuilder.Rebuild(petMetric, speciesVital, speciesCareAction));
        }
        public void Setup()
        {
            _petMetrics = new List <PetMetric>();
            _petMetrics.AddRange(TestData.UsersPets.BurberryPetMetrics);
            _petMetrics.AddRange(TestData.UsersPets.VersacePetMetrics);

            _nonReponsiveMetricIds = _petMetrics.Select(petMetric => petMetric.MetricId + 5).ToList();
            _reponsiveMetricIds    = _petMetrics.Select(petMetric => petMetric.MetricId).ToList();

            _mockInteractionRepository = new Mock <IRepository <Interaction, MetricInteraction> >();
            _mockPetRepository         = new Mock <IRepository <Pet, PetMetric> >();

            _mockPetRepository.Setup(m => m.FindAssociatedById(It.IsAny <int>()))
            .Returns(TestData.UsersPets.VersacePetMetrics);

            _validPayload = new UserPetCareAction()
            {
                PetId         = TestData.UsersPets.VersacePetId,
                InteractionId = TestData.Interactions.TakeSelfieWithInteractionId,
                UserId        = TestData.Users.MeJulieUserId
            };

            _sut = new PetCareActionValidator(_mockPetRepository.Object, _mockInteractionRepository.Object);
        }
Beispiel #5
0
 public PetVital RebuildPetVital(IList <MetricInteraction> metricInteraction, UserPetCareAction petCareAction)
 {
     return(_nopePetBuilder.UpdatePetVital(metricInteraction, petCareAction));
 }