public void CreateByConstructorSaveOnObject() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = null; try { resource = new ResourceObject(UnitTestHelper.ObjectTypeUnitTestObjectName, client); Assert.AreEqual(OperationType.Create, resource.ModificationType); Assert.AreEqual(true, resource.IsPlaceHolder); UnitTestHelper.PopulateTestUserData(resource); resource.Save(); 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); resource = client.GetResource(resource.ObjectID); UnitTestHelper.ValidateTestUserData(resource); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void GetObjectByIDWithSelectedAttributes() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); List <string> attributesToGet = new List <string>() { UnitTestHelper.AttributeBooleanSV, UnitTestHelper.AttributeStringSV, UnitTestHelper.AttributeReferenceMV }; try { UnitTestHelper.PopulateTestUserData(resource); resource.Save(); resource = client.GetResource(resource.ObjectID, attributesToGet); UnitTestHelper.ValidateSelectedAttributePresence(resource, attributesToGet); UnitTestHelper.ValidateTestUserData(resource, attributesToGet); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void GetObjectByMultipleKeysWithAllAttributes() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); string newID = Guid.NewGuid().ToString(); Dictionary <string, object> keys = new Dictionary <string, object>(); keys.Add(AttributeNames.AccountName, newID); keys.Add(UnitTestHelper.AttributeStringSV, UnitTestHelper.TestDataString1); try { UnitTestHelper.PopulateTestUserData(resource, newID); resource.Save(); resource = client.GetResourceByKey(UnitTestHelper.ObjectTypeUnitTestObjectName, keys); UnitTestHelper.ValidateTestUserData(resource); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void PutCompositeTestMultipleUpdates() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource1 = null; ResourceObject resource2 = null; try { // Create the empty object resource1 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); UnitTestHelper.PopulateTestUserData(resource1); client.SaveResource(resource1); resource2 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); UnitTestHelper.PopulateTestUserData(resource2); client.SaveResource(resource2); resource1.Refresh(); resource2.Refresh(); // Make the changes resource1.Attributes[UnitTestHelper.AttributeStringSV].SetValue(UnitTestHelper.TestDataString2); resource2.Attributes[UnitTestHelper.AttributeStringSV].SetValue(UnitTestHelper.TestDataString3); client.SaveResources(new List <ResourceObject>() { resource1, resource2 }); // Ensure there are no pending changes Assert.AreEqual(0, resource1.PendingChanges.Count); Assert.AreEqual(0, resource2.PendingChanges.Count); resource1 = client.GetResource(resource1.ObjectID); resource2 = client.GetResource(resource2.ObjectID); Assert.AreEqual(UnitTestHelper.TestDataString2, resource1.Attributes[UnitTestHelper.AttributeStringSV].StringValue); Assert.AreEqual(UnitTestHelper.TestDataString3, resource2.Attributes[UnitTestHelper.AttributeStringSV].StringValue); } finally { if (resource1 != null && !resource1.IsPlaceHolder) { client.DeleteResource(resource1); } if (resource2 != null && !resource2.IsPlaceHolder) { client.DeleteResource(resource2); } } }
public void DeleteFirstValueBinaryMV() { 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.AttributeBinaryMV].RemoveValue(UnitTestHelper.TestDataBinary1MV[0]); Assert.AreEqual(1, resource.PendingChanges.Count); List <byte[]> expectedValues = new List <byte[]>(); expectedValues.Add(UnitTestHelper.TestDataBinary1MV[1]); expectedValues.Add(UnitTestHelper.TestDataBinary1MV[2]); this.AreByteArraysEqual(expectedValues, resource.Attributes[UnitTestHelper.AttributeBinaryMV].BinaryValues); // Submit the changes client.SaveResource(resource); // Ensure there are no pending changes Assert.AreEqual(0, resource.PendingChanges.Count); resource = client.GetResource(resource.ObjectID); this.AreByteArraysEqual(expectedValues, resource.Attributes[UnitTestHelper.AttributeBinaryMV].BinaryValues); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void DeleteFirstValueStringMV() { 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].RemoveValue(UnitTestHelper.TestDataString1MV[0]); Assert.AreEqual(1, resource.PendingChanges.Count); CollectionAssert.AreEqual(new string[2] { UnitTestHelper.TestDataString1MV[1], UnitTestHelper.TestDataString1MV[2] }, resource.Attributes[UnitTestHelper.AttributeStringMV].StringValues); // Submit the changes client.SaveResource(resource); // Ensure there are no pending changes Assert.AreEqual(0, resource.PendingChanges.Count); resource = client.GetResource(resource.ObjectID); CollectionAssert.AreEqual(new string[2] { UnitTestHelper.TestDataString1MV[1], UnitTestHelper.TestDataString1MV[2] }, resource.Attributes[UnitTestHelper.AttributeStringMV].StringValues); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void GetObjectByIDWithAllAttributes() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); try { UnitTestHelper.PopulateTestUserData(resource); resource.Save(); resource = client.GetResource(resource.ObjectID); UnitTestHelper.ValidateTestUserData(resource); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
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 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)); } }
public void DeleteAllValueTextMV() { 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.AttributeTextMV].RemoveValues(); Assert.AreEqual(1, resource.PendingChanges.Count); Assert.IsTrue(resource.Attributes[UnitTestHelper.AttributeTextMV].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.AttributeTextMV].IsNull); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
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); } } }