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); }
public async Task <BaseResponse> GetUserSession(int PartnerId, int CpartyId, int TerminalId) { AvihangUserSessions avihangUserSessions = new AvihangUserSessions(); AvihangUserInfo avihangUserInfo = new AvihangUserInfo(); BaseResponse baseResponse = new BaseResponse(); avihangUserSessions = _avihangUserSessionsRepository.GetByPartnerIdAndCpartyId(PartnerId, CpartyId).Result; if (getSessionState(avihangUserSessions) != Framework.Utility.SessionState.Ok) { var providers = _providersRepository.GetById((int)ProviderType.Avihang).Result; var providerApis = _providerApisRepository.GetByProviderId((int)ProviderType.Avihang).Result; string ApiUrl = providerApis.Where(a => a.Id == (int)AvihangApis.InternalUserSession).FirstOrDefault().Url; string Uri = $"{(providers.BaseUrl.EndsWith("/") ? providers.BaseUrl : providers.BaseUrl + "/")}{(ApiUrl.StartsWith("/") ? ApiUrl.Remove(0, 1) : ApiUrl)}"; Header header = new Header(Uri, 1, "application/json"); header.token = _avihangTokensService.GetToken(TerminalId).Result.Token; header.clientAgentInfo = "172.16.2.9"; header.clientIPAddress = "172.16.2.9"; header.terminalId = TerminalId; UserSessionRequest userSessionRequest = new UserSessionRequest(PartnerId, CpartyId); var preResponse = _factory.GetChannel().CallWebApi <BaseApiHeader, UserSessionRequest>(header, userSessionRequest); avihangUserSessions = new AvihangUserSessions(); avihangUserSessions.ResDate = DateTime.Now; baseResponse = Utilities.JsonTextToModel <BaseResponse>(preResponse.Content); baseResponse.CopyPropertiesTo(avihangUserSessions); baseResponse.info.CopyPropertiesTo(avihangUserSessions); baseResponse.info.CopyPropertiesTo(avihangUserInfo); await _avihangUserInfoRepository.Insert(avihangUserInfo); avihangUserSessions.AvihangUserInfoId = avihangUserInfo.Id; await _avihangUserSessionsRepository.Add(avihangUserSessions); await _avihangUserSessionsRepository.CommitAsync(); } return(baseResponse); }
//This method is invoked on every request. string GetTenantDB(UserSessionRequest userSessionRequest) { //Example //var tenant_id = userSessionRequest.LocalHttpContext.User.Claims.FirstOrDefault(x => x.Type.Equals("tenant_id")).Value; //return $"Data Source=client_db{tenant_id}.db;"; return($"Data Source=client_db.db;"); }
Given_a_valid_and_persisted_pet_registration_request_then_when_processed_returns_the_new_pet_data_and_updates_the_user_and_pet_repositories() { var sut = SetupMockMeJulieLogin(); ErrorMessage error; MockPetPersister.Setup(m => m.TryPersist(ref It.Ref <Pet> .IsAny, out error)) .Callback(new CallbackPet((ref Pet pet, out ErrorMessage errorCallback) => { pet.PetId = TestData.UsersPets.BurberryPetId + 1; errorCallback = null; })).Returns(true); MockPetMetricPersister.Setup(m => m.TryPersist(ref It.Ref <PetMetric> .IsAny, out error)) .Callback(new CallbackPetMetric((ref PetMetric metric, out ErrorMessage errorCallback) => { metric = new PetMetric(TestData.UsersPets.BurberryPetId + 1, TestData.AnimalMetrics.Confidence.MetricId, 0, DateTime.UtcNow); errorCallback = null; })).Returns(true); var request = new UserSessionRequest <NopePet>() { RequestType = RequestType.Create, Payload = NopePet.NewPet("Smeagle", TestData.Animals.ChihuahuaAnimalId), UserId = TestData.Users.MeJulie.UserId, PayloadType = typeof(NopePet) }; IResponse response; var result = sut.ProcessRequest(request, out response); Assert.IsTrue(result); Assert.IsNotNull(response as UserSessionPetResponse); var responseData = (response as UserSessionPetResponse).Pets; Assert.AreEqual(responseData.Count, 1); var newPet = responseData.First(item => item.PetName == "Smeagle"); AssertPetOwnerIsCorrect(newPet.Owner, TestData.Users.MeJulie); //Todo additional asserts }
public UserSessionPetResponse GetMyPets(int userId) { var sessionRequest = new UserSessionRequest <IUserSessionData>() { RequestType = RequestType.Read }; var userSessionState = _state.GetUserSession(userId); if (userSessionState == null) { var response = new UserSessionPetResponse(); return((UserSessionPetResponse)response.SetErrorResponse(new ErrorMessage(ErrorCode.UserSessionNotFound))); } { IResponse response; userSessionState.ProcessRequest(sessionRequest, out response); return((UserSessionPetResponse)response); } }
public void Given_a_request_for_a_users_session_data_then_when_processed_returns_correct_data() { var sut = SetupMockMeJulieLogin(); var request = new UserSessionRequest <UserSession>() { RequestType = RequestType.ReadAll, Payload = null, UserId = TestData.Users.MeJulie.UserId, PayloadType = typeof(UserSession) }; IResponse response; var result = sut.ProcessRequest(request, out response); Assert.IsTrue(result); Assert.IsNotNull(response as UserSessionResponse); var responseData = (response as UserSessionResponse).UserSession; AssertMeJuliesSessionDataIsCorrect(responseData); }