Пример #1
0
        public void TestGetUserPreferencesForUser_ValidInput_ReturnsPreferences()
        {
            //Arrange
            Guid   userUid = new Guid("e96d6ded-826e-4cfc-a04e-a07963ba2a80");
            string keyName = "Key1";
            string version = "1.0";
            List <UserPreference> userPreferenceList = new List <UserPreference>
            {
                new UserPreference {
                    PreferenceJson = "JSON1", PreferenceKeyName = "Key1", SchemaVersion = "1.0"
                },
            };

            transaction.Get <UserPreference>(Arg.Any <string>()).Returns(userPreferenceList);

            //Act
            var resultList = preferenceService.GetUserPreferencesForUser(userUid, keyName, version);


            //Assert
            Assert.Equal(userPreferenceList, resultList);
            transaction.Received(1).Get <UserPreference>(Arg.Is <string>(x => x.Contains(keyName) && x.Contains(version)));
        }
Пример #2
0
        public ActionResult <UserPreference> GetTargetUserPreferencesForUserAndKey(
            string userUid, string schemaVersion = null, string keyName = null)
        {
            try
            {
                if (!Guid.TryParse(userUid, out var targetUserUid))
                {
                    logger.LogError("Invalid UserUID {0}", userUid);
                    return(BadRequest("Invalid UserUID"));
                }

                List <UserPreference> preferences;
                try
                {
                    preferences = _preferenceService.GetUserPreferencesForUser(targetUserUid, schemaVersion, keyName);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex.Message + ex.StackTrace);
                    return(StatusCode(500, new Exception("Unable to read from db ")));
                }

                if (!string.IsNullOrEmpty(keyName))
                {
                    var preference = preferences.FirstOrDefault();
                    return(Ok(preference));
                }

                return(Ok(preferences));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An exception has occurred");
                return(StatusCode(500));
            }
        }