public void TestMultivaluePhoneRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVPhone", new List <string>()
     {
         "98765431", "456789456"
     }, "99994444");
 }
 public void TestMultivalueEmailRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVEmail", new List <string>()
     {
         "*****@*****.**", "*****@*****.**"
     }, "*****@*****.**");
 }
 public void TestMultivalueDateRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVDate", new List <string>()
     {
         "2018-01-08", "2018-01-09"
     }, "2017-01-01");
 }
 public void TestMultivalueStringRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVString", new List <string>()
     {
         "testmvstring1", "testmvstring2"
     }, "testmvstring3");
 }
 public void TestMultivalueDoubleRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVDouble", new List <double>()
     {
         2.1D, 3.1D
     }, new List <string>()
     {
         "2.1", "3.1"
     }, 1.8D);
 }
 public void TestMultivalueLongRoundTrip()
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip("TestMVInt", new List <long>()
     {
         2L, 3L
     }, new List <string>()
     {
         "2", "3"
     }, 4L);
 }
        private static List <T1> GetReturnedValues <T1>(string fieldName, User u)
        {
            object value = u.CustomSchemas[TestSchemaName][fieldName];

            if (value is JArray jarray)
            {
                return(UserCustomSchemaTests.GetValuesFromJArray <T1>(jarray));
            }

            if (value is IList list)
            {
                return(UserCustomSchemaTests.GetValuesFromList <T1>(list));
            }

            throw new NotSupportedException("The array type was unknown");
        }
 public void TestSingleValueDateRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVDate", "2018-01-01", "2018-01-02");
 }
 public void TestSingleValueStringRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVString", "testsvstring", "replacementstring");
 }
        private static void TestMultivalueRoundTrip <T1, T2>(string fieldName, IList <T1> expectedGoogleValue, IList <T2> expectedFimValues, T1 valueToAdd)
        {
            string testAttributeName            = $"{UserCustomSchemaTests.TestSchemaName}_{fieldName}";
            AdapterCustomSchemaField schemaItem = GetFieldAdapter(testAttributeName);

            User u = DeserializeTestUser();

            CSEntryChange x = CSEntryChange.Create();

            x.ObjectModificationType = ObjectModificationType.Add;

            // Convert the user object into a series of attribute changes

            IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList();

            AttributeChange change = result.FirstOrDefault(t => t.Name == testAttributeName);

            Assert.IsNotNull(change);
            CollectionAssert.AreEquivalent(expectedFimValues.ToArray(), change.GetValueAdds <T2>().ToArray());

            // Reverse the process and convert the attribute changes onto a new user
            x.AttributeChanges.Add(change);

            User ux = new User();

            schemaItem.UpdateField(x, ux);

            List <T1> returnedValues = UserCustomSchemaTests.GetReturnedValues <T1>(fieldName, ux);

            CollectionAssert.AreEquivalent(expectedGoogleValue.ToArray(), returnedValues);

            // Add a value
            ValueChange add1 = ValueChange.CreateValueAdd(valueToAdd);

            change = AttributeChange.CreateAttributeUpdate(testAttributeName, new List <ValueChange>()
            {
                add1
            });
            x = CSEntryChange.Create();
            x.ObjectModificationType = ObjectModificationType.Update;
            x.AttributeChanges.Add(change);
            schemaItem.UpdateField(x, ux);

            returnedValues = UserCustomSchemaTests.GetReturnedValues <T1>(fieldName, ux);

            IList <object> e = expectedGoogleValue.Cast <object>().ToList();

            e.Add(valueToAdd);

            CollectionAssert.AreEquivalent(e.ToArray(), returnedValues);

            // Remove a value

            ValueChange delete1 = ValueChange.CreateValueDelete(valueToAdd);

            change = AttributeChange.CreateAttributeUpdate(testAttributeName, new List <ValueChange>()
            {
                delete1
            });
            x = CSEntryChange.Create();
            x.ObjectModificationType = ObjectModificationType.Update;
            x.AttributeChanges.Add(change);
            schemaItem.UpdateField(x, ux);

            returnedValues = UserCustomSchemaTests.GetReturnedValues <T1>(fieldName, ux);

            CollectionAssert.AreEquivalent(expectedGoogleValue.ToArray(), returnedValues);

            // Delete the attribute

            change = AttributeChange.CreateAttributeDelete(testAttributeName);
            x      = CSEntryChange.Create();
            x.ObjectModificationType = ObjectModificationType.Update;
            x.AttributeChanges.Add(change);

            schemaItem.UpdateField(x, ux);
            Assert.AreEqual(Constants.NullValuePlaceholder, (string)ux.CustomSchemas[TestSchemaName][fieldName]);
        }
 private static void TestMultivalueRoundTrip <T1>(string fieldName, IList <T1> expectedValue, T1 valueToAdd)
 {
     UserCustomSchemaTests.TestMultivalueRoundTrip(fieldName, expectedValue, expectedValue, valueToAdd);
 }
 private static void TestSingleValueRoundTrip <T1>(string fieldName, T1 expectedValue, T1 valueForUpdateTest)
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip(fieldName, expectedValue, expectedValue, valueForUpdateTest);
 }
 public void TestSingleValueBooleanRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVBool", true, false);
 }
 public void TestSingleValueDoubleRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVDouble", 0.6822871999174D, "0.6822871999174", 0.9);
 }
 public void TestSingleValueEmailRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVEmail", "*****@*****.**", "*****@*****.**");
 }
 public void TestSingleValueLongRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVInt", 44L, 99L);
 }
 public void TestSingleValuePhoneRoundTrip()
 {
     UserCustomSchemaTests.TestSingleValueRoundTrip("TestSVPhone", "123456789", "987654321");
 }