Example #1
0
        /// <inheritdoc/>
        public virtual async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            IHttpActionResult   result   = GetInnerActionResult();
            HttpResponseMessage response = await result.ExecuteAsync(cancellationToken);

            response.Headers.Location = LocationHeader;
            ResultHelpers.AddEntityId(response, () => EntityId);

            return(response);
        }
Example #2
0
        public void AddEntityId_DoesNotAddEntityId_IfResponseStatusCodeIsOtherThanNoContent()
        {
            // Arrange
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            // Act
            ResultHelpers.AddEntityId(response, () => _entityId);

            // Assert
            Assert.False(response.Headers.Contains(ResultHelpers.EntityIdHeaderName));
        }
Example #3
0
        public void AddEntityId_AddsEntityId_IfResponseStatusCodeIsNoContent()
        {
            // Arrange
            var response = new HttpResponseMessage(HttpStatusCode.NoContent);

            // Act
            ResultHelpers.AddEntityId(response, () => _entityId);

            // Assert
            var entityIdHeaderValues = response.Headers.GetValues(ResultHelpers.EntityIdHeaderName).ToList();

            Assert.Single(entityIdHeaderValues);
            Assert.Equal(_entityId.ToString(), entityIdHeaderValues.Single());
        }
Example #4
0
        public void GenerateODataLink_ThrowsIdLinkNullForEntityIdHeader_IfEntitySetLinkBuilderReturnsNull()
        {
            // Arrange
            var linkBuilder = new Mock <NavigationSourceLinkBuilderAnnotation>();
            var model       = new CustomersModelWithInheritance();

            model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder.Object);
            var path    = new ODataPath(new EntitySetSegment(model.Customers));
            var request = new HttpRequestMessage();

            request.ODataProperties().Path = path;
            request.EnableHttpDependencyInjectionSupport(model.Model);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => ResultHelpers.GenerateODataLink(request, _entity, isEntityId: true),
                "The Id link builder for the entity set 'Customers' returned null. An Id link is required for the OData-EntityId header.");
        }
Example #5
0
 internal Uri GenerateLocationHeader()
 {
     return(ResultHelpers.GenerateODataLink(Request, Entity, isEntityId: false));
 }