Exemple #1
0
        public void GetObjectByKeyWithAllAttributes()
        {
            ResourceManagementClient client   = new ResourceManagementClient();
            ResourceObject           resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName);
            string newID = Guid.NewGuid().ToString();

            try
            {
                UnitTestHelper.PopulateTestUserData(resource, newID);
                resource.Save();

                resource = client.GetResourceByKey(UnitTestHelper.ObjectTypeUnitTestObjectName, AttributeNames.AccountName, newID);

                UnitTestHelper.ValidateTestUserData(resource);
            }
            finally
            {
                if (resource != null && !resource.IsPlaceHolder)
                {
                    client.DeleteResource(resource);
                }
            }
        }
        public void XpathPredicateGroupOrTest()
        {
            string          testValue1    = "test1";
            string          testValue2    = "test2";
            string          nonMatchValue = "test3";
            XPathQuery      predicate1    = new XPathQuery(UnitTestHelper.AttributeStringSV, ComparisonOperator.Equals, testValue1);
            XPathQuery      predicate2    = new XPathQuery(UnitTestHelper.AttributeStringMV, ComparisonOperator.Equals, testValue2);
            XPathQueryGroup group         = new XPathQueryGroup(GroupOperator.Or, predicate1, predicate2);

            string expected = string.Format("(({0} = '{1}') or ({2} = '{3}'))", UnitTestHelper.AttributeStringSV, testValue1, UnitTestHelper.AttributeStringMV, testValue2);

            ResourceObject matchObject    = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeStringSV, testValue1);
            ResourceObject nonMatchObject = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeStringSV, nonMatchValue);

            try
            {
                this.SubmitXpath(group, expected, matchObject);
            }
            finally
            {
                UnitTestHelper.CleanupTestResources(matchObject, nonMatchObject);
            }
        }
Exemple #3
0
        public void TestMVReferenceIsPresent()
        {
            object queryValue = null;

            ResourceObject nonMatchResource  = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceMV, null);
            ResourceObject nonMatchResource2 = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceMV, null);

            ResourceObject matchResource = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceMV, new List <object>()
            {
                nonMatchResource.ObjectID, nonMatchResource.ObjectID
            });


            try
            {
                string expected = string.Format("/{0}[({1} = /*)]", UnitTestHelper.ObjectTypeUnitTestObjectName, UnitTestHelper.AttributeReferenceMV, XPathQuery.MaxDate);
                this.SubmitXpath(queryValue, expected, UnitTestHelper.AttributeReferenceMV, ComparisonOperator.IsPresent, GroupOperator.And, matchResource);
            }
            finally
            {
                UnitTestHelper.CleanupTestResources(matchResource, nonMatchResource);
            }
        }
        public void DeleteAllValueStringMV()
        {
            ResourceManagementClient client   = new ResourceManagementClient();
            ResourceObject           resource = null;

            try
            {
                // Create the empty object
                resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName);
                UnitTestHelper.PopulateTestUserData(resource);
                client.SaveResource(resource);

                // Re-get the object
                resource = client.GetResource(resource.ObjectID);

                // Make the changes
                resource.Attributes[UnitTestHelper.AttributeStringMV].RemoveValues();
                Assert.AreEqual(1, resource.PendingChanges.Count);
                Assert.IsTrue(resource.Attributes[UnitTestHelper.AttributeStringMV].IsNull);

                // Submit the changes
                client.SaveResource(resource);

                // Ensure there are no pending changes
                Assert.AreEqual(0, resource.PendingChanges.Count);

                resource = client.GetResource(resource.ObjectID);
                Assert.IsTrue(resource.Attributes[UnitTestHelper.AttributeStringMV].IsNull);
            }
            finally
            {
                if (resource != null && !resource.IsPlaceHolder)
                {
                    client.DeleteResource(resource);
                }
            }
        }
Exemple #5
0
        public void CreateByConstructorSaveWithClientComposite()
        {
            ResourceManagementClient client = new ResourceManagementClient();

            List <ResourceObject> resources = new List <ResourceObject>();


            for (int i = 0; i < 5; i++)
            {
                ResourceObject resource = new ResourceObject(UnitTestHelper.ObjectTypeUnitTestObjectName, client);
                Assert.AreEqual(OperationType.Create, resource.ModificationType);
                Assert.AreEqual(true, resource.IsPlaceHolder);
                UnitTestHelper.PopulateTestUserData(resource);
                resources.Add(resource);
            }

            try
            {
                client.SaveResources(resources);
                foreach (ResourceObject resource in resources)
                {
                    Assert.AreEqual(false, resource.IsPlaceHolder);
                    Assert.AreEqual(OperationType.Update, resource.ModificationType);
                    Assert.AreEqual(0, resource.PendingChanges.Count);
                    Assert.IsTrue(resource.ObjectID.IsGuid);
                    Assert.AreNotEqual(resource.ObjectID.GetGuid(), Guid.Empty);

                    ResourceObject resourceFetched = client.GetResource(resource.ObjectID);

                    UnitTestHelper.ValidateTestUserData(resourceFetched);
                }
            }
            finally
            {
                client.DeleteResources(resources.Where(r => r != null && !r.IsPlaceHolder));
            }
        }
Exemple #6
0
        public void GetObjectByKeyFailsOnMultipleResults()
        {
            ResourceManagementClient client    = new ResourceManagementClient();
            ResourceObject           resource1 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName);
            ResourceObject           resource2 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName);
            string newID = Guid.NewGuid().ToString();

            try
            {
                UnitTestHelper.PopulateTestUserData(resource1);
                resource1.Save();

                UnitTestHelper.PopulateTestUserData(resource2);
                resource2.Save();

                try
                {
                    resource1 = client.GetResourceByKey(UnitTestHelper.ObjectTypeUnitTestObjectName, UnitTestHelper.AttributeStringSV, UnitTestHelper.TestDataString1);
                    Assert.Fail("The expectedXpath exception was not thrown");
                }
                catch (TooManyResultsException)
                {
                }
            }
            finally
            {
                if (resource1 != null && !resource1.IsPlaceHolder)
                {
                    client.DeleteResource(resource1);
                }

                if (resource2 != null && !resource2.IsPlaceHolder)
                {
                    client.DeleteResource(resource2);
                }
            }
        }
        public void XpathExpressionNestedTest()
        {
            string          testValue1      = "test1";
            XPathQuery      predicate1      = new XPathQuery(UnitTestHelper.AttributeStringSV, ComparisonOperator.Equals, testValue1);
            XPathExpression childExpression = new XPathExpression(UnitTestHelper.ObjectTypeUnitTestObjectName, predicate1);
            XPathQuery      predicate2      = new XPathQuery(UnitTestHelper.AttributeReferenceSV, ComparisonOperator.Equals, childExpression);
            XPathExpression expression      = new XPathExpression(UnitTestHelper.ObjectTypeUnitTestObjectName, predicate2);

            string expected = string.Format("/{0}[({1} = /{0}[({2} = '{3}')])]", UnitTestHelper.ObjectTypeUnitTestObjectName, UnitTestHelper.AttributeReferenceSV, UnitTestHelper.AttributeStringSV, testValue1);

            ResourceObject filterTargetObject = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeStringSV, testValue1);
            ResourceObject childObject1       = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceSV, filterTargetObject.ObjectID);
            ResourceObject childObject2       = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceSV, filterTargetObject.ObjectID);
            ResourceObject childObject3       = UnitTestHelper.CreateTestResource(UnitTestHelper.AttributeReferenceSV, filterTargetObject.ObjectID);

            try
            {
                this.SubmitXpath(expression, expected, childObject1, childObject2, childObject3);
            }
            finally
            {
                UnitTestHelper.CleanupTestResources(filterTargetObject, childObject1, childObject2, childObject3);
            }
        }
        public static void PrepareRMSForUnitTests()
        {
            ResourceObject objectClass = CreateUnitTestObjectTypeIfDoesntExist();

            ResourceObject svStringAttribute    = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeStringSV, null, false, AttributeType.String);
            ResourceObject mvStringAttribute    = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeStringMV, null, true, AttributeType.String);
            ResourceObject svIntegerAttribute   = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeIntegerSV, null, false, AttributeType.Integer);
            ResourceObject mvIntegerAttribute   = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeIntegerMV, null, true, AttributeType.Integer);
            ResourceObject svReferenceAttribute = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeReferenceSV, null, false, AttributeType.Reference);
            ResourceObject mvReferenceAttribute = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeReferenceMV, null, true, AttributeType.Reference);
            ResourceObject svTextAttribute      = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeTextSV, null, false, AttributeType.Text);
            ResourceObject mvTextAttribute      = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeTextMV, null, true, AttributeType.Text);
            ResourceObject svDateTimeAttribute  = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeDateTimeSV, null, false, AttributeType.DateTime);
            ResourceObject mvDateTimeAttribute  = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeDateTimeMV, null, true, AttributeType.DateTime);
            ResourceObject svBinaryAttribute    = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeBinarySV, null, false, AttributeType.Binary);
            ResourceObject mvBinaryAttribute    = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeBinaryMV, null, true, AttributeType.Binary);
            ResourceObject svBooleanAttribute   = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeBooleanSV, null, false, AttributeType.Boolean);
            ResourceObject accountNameAttribute = UnitTestHelper.CreateAttributeTypeIfDoesntExist(AttributeNames.AccountName, null, false, AttributeType.String);

            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svStringAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvStringAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svIntegerAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvIntegerAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svReferenceAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvReferenceAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svTextAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvTextAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svDateTimeAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvDateTimeAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svBinaryAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, mvBinaryAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, svBooleanAttribute);
            UnitTestHelper.CreateBindingIfDoesntExist(objectClass, accountNameAttribute);

            client.RefreshSchema();
        }
 static UnitTestHelper()
 {
     UnitTestHelper.PrepareRMSForUnitTests();
     UnitTestHelper.CreateReferenceTestObjects();
 }