本文整理汇总了C#中ODataAction类的典型用法代码示例。如果您正苦于以下问题:C# ODataAction类的具体用法?C# ODataAction怎么用?C# ODataAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataAction类属于命名空间,在下文中一共展示了ODataAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyGettersAndSettersTest
public void PropertyGettersAndSettersTest()
{
Uri metadata = new Uri("http://odata.org/operationMetadata");
string title = "OperationTitle";
Uri target = new Uri("http://odata.org/operationtarget");
ODataAction action = new ODataAction()
{
Metadata = metadata,
Title = title,
Target = target,
};
this.Assert.AreSame(metadata, action.Metadata, "Expected reference equal values for property 'Metadata'.");
this.Assert.AreEqual(title, action.Title, "Expected equal Title values.");
this.Assert.AreSame(target, action.Target, "Expected reference equal values for property 'Target'.");
ODataFunction function = new ODataFunction()
{
Metadata = metadata,
Title = title,
Target = target,
};
this.Assert.AreSame(metadata, function.Metadata, "Expected reference equal values for property 'Metadata'.");
this.Assert.AreEqual(title, function.Title, "Expected equal Title values.");
this.Assert.AreSame(target, function.Target, "Expected reference equal values for property 'Target'.");
}
示例2: AddAction
/// <summary>
/// Add action to feed.
/// </summary>
/// <param name="action">The action to add.</param>
public void AddAction(ODataAction action)
{
ExceptionUtils.CheckArgumentNotNull(action, "action");
if (!this.actions.Contains(action))
{
this.actions.Add(action);
}
}
示例3: DefaultValuesTest
public void DefaultValuesTest()
{
ODataAction action = new ODataAction();
this.Assert.IsNull(action.Metadata, "Expected null default value for property 'Metadata'.");
this.Assert.IsNull(action.Title, "Expected null default value for property 'Title'.");
this.Assert.IsNull(action.Target, "Expected null default value for property 'Target'.");
ODataFunction function = new ODataFunction();
this.Assert.IsNull(function.Metadata, "Expected null default value for property 'Metadata'.");
this.Assert.IsNull(function.Title, "Expected null default value for property 'Title'.");
this.Assert.IsNull(function.Target, "Expected null default value for property 'Target'.");
}
示例4: MissingOperationGeneratorTests
public MissingOperationGeneratorTests()
{
this.model = new EdmModel();
this.container = new EdmEntityContainer("Fake", "Container");
this.functionEdmMetadata = new EdmFunction("Fake", "FakeFunction", EdmCoreModel.Instance.GetInt32(false), true /*isBound*/, null, true /*isComposable*/);
this.actionEdmMetadata = new EdmAction("Fake", "FakeAction", EdmCoreModel.Instance.GetInt32(false), true/*isBound*/, null /*entitySetPath*/);
this.model.AddElement(this.container);
this.model.AddElement(this.actionEdmMetadata);
this.model.AddElement(this.functionEdmMetadata);
this.allOperations = new EdmOperation[] { this.actionEdmMetadata, this.functionEdmMetadata };
this.odataAction = new ODataAction {Metadata = new Uri("http://temp.org/$metadata#Fake.FakeAction")};
this.odataFunction = new ODataFunction {Metadata = new Uri("http://temp.org/$metadata#Fake.FakeFunction")};
}
示例5: PropertySettersNullTest
public void PropertySettersNullTest()
{
Uri metadata = new Uri("http://odata.org/operationMetadata");
string title = "OperationTitle";
Uri target = new Uri("http://odata.org/operationtarget");
ODataAction action = new ODataAction()
{
Metadata = metadata,
Title = title,
Target = target,
};
action.Metadata = null;
action.Title = null;
action.Target = null;
this.Assert.IsNull(action.Metadata, "Expected null value for property 'Metadata'.");
this.Assert.IsNull(action.Title, "Expected null value for property 'Title'.");
this.Assert.IsNull(action.Target, "Expected null value for property 'Target'.");
ODataFunction function = new ODataFunction()
{
Metadata = metadata,
Title = title,
Target = target,
};
function.Metadata = null;
function.Title = null;
function.Target = null;
this.Assert.IsNull(function.Metadata, "Expected null value for property 'Metadata'.");
this.Assert.IsNull(function.Title, "Expected null value for property 'Title'.");
this.Assert.IsNull(function.Target, "Expected null value for property 'Target'.");
}
示例6: CreateODataAction
public virtual ODataAction CreateODataAction(IEdmAction action, EntityInstanceContext entityInstanceContext)
{
if (action == null)
{
throw Error.ArgumentNull("action");
}
if (entityInstanceContext == null)
{
throw Error.ArgumentNull("entityInstanceContext");
}
ODataMetadataLevel metadataLevel = entityInstanceContext.SerializerContext.MetadataLevel;
IEdmModel model = entityInstanceContext.EdmModel;
ActionLinkBuilder builder = model.GetActionLinkBuilder(action);
if (builder == null)
{
return null;
}
if (ShouldOmitAction(action, builder, metadataLevel))
{
return null;
}
Uri target = builder.BuildActionLink(entityInstanceContext);
if (target == null)
{
return null;
}
Uri baseUri = new Uri(entityInstanceContext.Url.CreateODataLink(new MetadataPathSegment()));
Uri metadata = new Uri(baseUri, "#" + CreateMetadataFragment(action));
ODataAction odataAction = new ODataAction
{
Metadata = metadata,
};
bool alwaysIncludeDetails = metadataLevel == ODataMetadataLevel.FullMetadata;
// Always omit the title in minimal/no metadata modes.
if (alwaysIncludeDetails)
{
EmitTitle(model, action, odataAction);
}
// Omit the target in minimal/no metadata modes unless it doesn't follow conventions.
if (alwaysIncludeDetails || !builder.FollowsConventions)
{
odataAction.Target = target;
}
return odataAction;
}
示例7: CreateEntry_Calls_CreateODataAction_ForEachSelectAction
public void CreateEntry_Calls_CreateODataAction_ForEachSelectAction()
{
// Arrange
ODataAction[] actions = new ODataAction[] { new ODataAction(), new ODataAction() };
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedActions = { new Mock<IEdmAction>().Object, new Mock<IEdmAction>().Object }
};
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer.Setup(s => s.CreateODataAction(selectExpandNode.SelectedActions.ElementAt(0), _entityInstanceContext)).Returns(actions[0]).Verifiable();
serializer.Setup(s => s.CreateODataAction(selectExpandNode.SelectedActions.ElementAt(1), _entityInstanceContext)).Returns(actions[1]).Verifiable();
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
Assert.Equal(actions, entry.Actions);
serializer.Verify();
}
示例8: TestSetTitleAnnotation_UsesNameIfNoTitleAnnotationIsPresent
public void TestSetTitleAnnotation_UsesNameIfNoTitleAnnotationIsPresent()
{
// Arrange
IEdmActionImport action = CreateFakeActionImport(CreateFakeContainer("Container"), "Action");
IEdmDirectValueAnnotationsManager annonationsManager = CreateFakeAnnotationsManager();
IEdmModel model = CreateFakeModel(annonationsManager);
ODataAction odataAction = new ODataAction();
// Act
ODataEntityTypeSerializer.EmitTitle(model, action.Operation, odataAction);
// Assert
Assert.Equal(action.Operation.Name, odataAction.Title);
}
示例9: CreateODataAction_IncludesEverything_ForFullMetadata
public void CreateODataAction_IncludesEverything_ForFullMetadata()
{
// Arrange
string expectedContainerName = "Container";
string expectedNamespace = "NS";
string expectedActionName = "Action";
string expectedTarget = "aa://Target";
string expectedMetadataPrefix = "http://Metadata";
IEdmEntityContainer container = CreateFakeContainer(expectedContainerName);
IEdmAction action = CreateFakeAction(expectedNamespace, expectedActionName, isBindable: true);
ActionLinkBuilder linkBuilder = new ActionLinkBuilder((a) => new Uri(expectedTarget),
followsConventions: true);
IEdmDirectValueAnnotationsManager annotationsManager = CreateFakeAnnotationsManager();
annotationsManager.SetActionLinkBuilder(action, linkBuilder);
annotationsManager.SetIsAlwaysBindable(action);
IEdmModel model = CreateFakeModel(annotationsManager);
UrlHelper url = CreateMetadataLinkFactory(expectedMetadataPrefix);
EntityInstanceContext context = CreateContext(model, url);
context.SerializerContext.MetadataLevel = ODataMetadataLevel.FullMetadata;
// Act
ODataAction actualAction = _serializer.CreateODataAction(action, context);
// Assert
string expectedMetadata = expectedMetadataPrefix + "#" + expectedNamespace + "." + expectedActionName;
ODataAction expectedAction = new ODataAction
{
Metadata = new Uri(expectedMetadata),
Target = new Uri(expectedTarget),
Title = expectedActionName
};
AssertEqual(expectedAction, actualAction);
}
示例10: TryReadOperation
/// <summary>
/// Reads a an m:action or m:function in atom:entry.
/// </summary>
/// <param name="entryState">The reader entry state for the entry being read.</param>
/// <returns>true, if the m:action or m:function was read succesfully, false otherwise.</returns>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element m:action|m:function - The m:action or m:function element to read.
/// Post-Condition: Any - The node after the m:action or m:function element if it was read by this method.
/// XmlNodeType.Element m:action|m:function - The m:action or m:function element to read if it was not read by this method.
/// </remarks>
private bool TryReadOperation(IODataAtomReaderEntryState entryState)
{
Debug.Assert(entryState != null, "entryState != null");
this.XmlReader.AssertNotBuffering();
this.AssertXmlCondition(XmlNodeType.Element);
Debug.Assert(
this.XmlReader.NamespaceURI == AtomConstants.ODataMetadataNamespace,
"The XML reader must be on a metadata (m:*) element for this method to work.");
bool isAction = false;
if (this.XmlReader.LocalNameEquals(this.ODataActionElementName))
{
// m:action
isAction = true;
}
else if (!this.XmlReader.LocalNameEquals(this.ODataFunctionElementName))
{
// not an m:function either
return false;
}
ODataOperation operation;
if (isAction)
{
operation = new ODataAction();
entryState.Entry.AddAction((ODataAction)operation);
}
else
{
operation = new ODataFunction();
entryState.Entry.AddFunction((ODataFunction)operation);
}
string operationName = this.XmlReader.LocalName; // for error reporting
while (this.XmlReader.MoveToNextAttribute())
{
if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
{
string attributeValue = this.XmlReader.Value;
if (this.XmlReader.LocalNameEquals(this.ODataOperationMetadataAttribute))
{
// For metadata, if the URI is relative we don't attempt to make it absolute using the service
// base URI, because the ODataOperation metadata URI is relative to $metadata.
operation.Metadata = this.ProcessUriFromPayload(attributeValue, this.XmlReader.XmlBaseUri, /*makeAbsolute*/ false);
}
else if (this.XmlReader.LocalNameEquals(this.ODataOperationTargetAttribute))
{
operation.Target = this.ProcessUriFromPayload(attributeValue, this.XmlReader.XmlBaseUri);
}
else if (this.XmlReader.LocalNameEquals(this.ODataOperationTitleAttribute))
{
operation.Title = this.XmlReader.Value;
}
// skip unknown attributes
}
}
if (operation.Metadata == null)
{
throw new ODataException(ODataErrorStrings.ODataAtomEntryAndFeedDeserializer_OperationMissingMetadataAttribute(operationName));
}
if (operation.Target == null)
{
throw new ODataException(ODataErrorStrings.ODataAtomEntryAndFeedDeserializer_OperationMissingTargetAttribute(operationName));
}
// skip the content of m:action/m:function
this.XmlReader.Skip();
return true;
}
示例11: AddDuplicateAction
public void AddDuplicateAction()
{
var action = new ODataAction() { Metadata = new Uri("http://odata.org/metadata"), Target = new Uri("http://odata.org/target"), Title = "TestAction", };
this.odataEntry.AddAction(action);
this.odataEntry.AddAction(action);
this.odataEntry.Actions.Count().Should().Be(1);
this.odataEntry.Actions.First().Should().Be(action);
}
示例12: AdvertiseServiceAction
public bool AdvertiseServiceAction(DataServiceOperationContext operationContext, ServiceAction serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize)
{
throw new NotImplementedException();
}
示例13: CheckForUnmodifiedTarget
internal void CheckForUnmodifiedTarget(ODataAction action, Func<Uri> computeOriginalTarget)
{
if (!this.interpreter.ShouldIncludeOperationMetadata(PayloadMetadataKind.Operation.Target, () => !ReferenceEquals(action.Target, computeOriginalTarget())))
{
action.Target = null;
}
}
示例14: CheckForUnmodifiedTitle
internal void CheckForUnmodifiedTitle(ODataAction action, string originalTitle)
{
if (!this.interpreter.ShouldIncludeOperationMetadata(PayloadMetadataKind.Operation.Title, () => action.Title != originalTitle))
{
action.Title = null;
}
}
示例15: SetTarget
internal void SetTarget(ODataAction action, bool isAlwaysAvailable, Func<Uri> computeTarget)
{
Debug.Assert(action != null, "action != null");
if (!isAlwaysAvailable || this.interpreter.ShouldIncludeOperationMetadata(PayloadMetadataKind.Operation.Target, () => false))
{
Debug.Assert(computeTarget != null, "computeTarget != null");
action.Target = computeTarget();
}
}