public void GenerateActionLink_ThrowsArgumentNull_EntityInstanceContext() { EntityInstanceContext entityContext = null; IEdmActionImport action = new Mock <IEdmActionImport>().Object; Assert.ThrowsArgumentNull(() => entityContext.GenerateActionLink(action.Action), "entityContext"); }
public void GenerateActionLink_ThrowsActionNotBoundToEntity_IfActionHasNoParameters() { EntityInstanceContext entityContext = new EntityInstanceContext(); Mock <IEdmAction> action = new Mock <IEdmAction>(); action.Setup(a => a.Parameters).Returns(Enumerable.Empty <IEdmOperationParameter>()); action.Setup(a => a.Name).Returns("SomeAction"); Assert.ThrowsArgument( () => entityContext.GenerateActionLink(action.Object), "action", "The action 'SomeAction' is not bound to an entity. Only actions that are bound to entities can have action links."); }
public void GenerateActionLink_GeneratesLinkWithoutCast_IfEntitySetTypeMatchesActionEntityType() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.Customers, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.Customer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer); Assert.Equal("http://localhost/Customers(42)/upgrade", link.AbsoluteUri); }
public void GenerateActionLink_ReturnsNull_ForContainment() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.OrderLines, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.OrderLine.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.Tag); // Assert Assert.Null(link); }
public void GenerateActionLink_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType_ForSingleton() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.Mary, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeSpecialCustomer); // Assert Assert.Equal("http://localhost/Mary/NS.SpecialCustomer/specialUpgrade", link.AbsoluteUri); }
public void GenerateActionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType() { // Arrange IEdmEntitySet specialCustomers = new EdmEntitySet(_model.Container, "SpecialCustomers", _model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, EntitySet = specialCustomers, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer); Assert.Equal("http://localhost/SpecialCustomers(42)/NS.Customer/upgrade", link.AbsoluteUri); }
public void GenerateActionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType_ForSingleton() { // Arrange IEdmSingleton me = new EdmSingleton(_model.Container, "Me", _model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = me, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer); // Assert Assert.Equal("http://localhost/Me/NS.Customer/NS.upgrade", link.AbsoluteUri); }
static Uri LinkFor(EntityInstanceContext context, string actionName, params TokenState[] requiredStates) { Contract.Requires(context != null); if (!context.EdmObject.TryGetPropertyValue("state", out var value)) { return(null); } if (!ShouldAdvertiseAction((TokenState)value, requiredStates)) { return(null); } var model = context.EdmModel; var qualifiedName = $"{model.EntityContainer.Namespace}.{actionName}"; var operation = model.FindDeclaredBoundOperations(qualifiedName, context.EntityType).Single(); return(context.GenerateActionLink(operation)); }
public void GenerateActionLink_ReturnsNull_ForContainment() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.OrderLines, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.OrderLine.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.Tag); // Assert Assert.Null(link); }
public void GenerateActionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType_ForSingleton() { // Arrange IEdmSingleton me = new EdmSingleton(_model.Container, "Me", _model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = me, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer); // Assert Assert.Equal("http://localhost/Me/NS.Customer/upgrade", link.AbsoluteUri); }
public void GenerateActionLink_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType_ForSingleton() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.Mary, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeSpecialCustomer); // Assert Assert.Equal("http://localhost/Mary/NS.SpecialCustomer/specialUpgrade", link.AbsoluteUri); }
public void GenerateActionLink_GeneratesLinkWithoutCast_IfEntitySetTypeMatchesActionEntityType() { // Arrange HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.Customers, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.Customer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer); Assert.Equal("http://localhost/Customers(42)/upgrade", link.AbsoluteUri); }
public void GenerateActionLink_ThrowsActionNotBoundToEntity_IfActionHasNoParameters() { EntityInstanceContext entityContext = new EntityInstanceContext(); Mock<IEdmAction> action = new Mock<IEdmAction>(); action.Setup(a => a.Parameters).Returns(Enumerable.Empty<IEdmOperationParameter>()); action.Setup(a => a.Name).Returns("SomeAction"); Assert.ThrowsArgument( () => entityContext.GenerateActionLink(action.Object), "action", "The action 'SomeAction' is not bound to an entity. Only actions that are bound to entities can have action links."); }
public void GenerateActionLink_ThrowsArgumentNull_Action() { EntityInstanceContext entityContext = new EntityInstanceContext(); Assert.ThrowsArgumentNull(() => entityContext.GenerateActionLink(action: null), "action"); }
public void GenerateActionLink_ThrowsArgumentNull_Action() { EntityInstanceContext entityContext = new EntityInstanceContext(); Assert.ThrowsArgumentNull(() => entityContext.GenerateActionLink(action: null), "action"); }