示例#1
0
 public override string ToString()
 {
     if (_entityTag == null)
     {
         return(HttpDateParser.DateToString(_date.Value));
     }
     return(_entityTag.ToString());
 }
        public void ToString_UseDifferentETags_AllSerializedCorrectly()
        {
            EntityTagHeaderValue etag = new EntityTagHeaderValue("\"e tag\"");
            Assert.Equal("\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"e tag\"", true);
            Assert.Equal("W/\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"\"", false);
            Assert.Equal("\"\"", etag.ToString());
        }
示例#3
0
        public void Test_GetETagEntityTagHeaderValueFromETagString()
        {
            //Arrange
            string Version  = "10";
            string Expected = WeakETagString(Version);

            //Act
            System.Net.Http.Headers.EntityTagHeaderValue Result = Pyro.Common.Tools.HttpHeaderSupport.GetETagEntityTagHeaderValueFromETagString(Expected);

            //Assert
            Assert.AreEqual(Result.ToString(), Expected);
        }
        public void CreateEntry_SetsEtagToNotNull_IfWithConcurrencyProperty()
        {
            // Arrange
            Mock<IEdmStructuralProperty> mockConcurrencyProperty = new Mock<IEdmStructuralProperty>();
            mockConcurrencyProperty.SetupGet(s => s.ConcurrencyMode).Returns(EdmConcurrencyMode.Fixed);
            mockConcurrencyProperty.SetupGet(s => s.Name).Returns("City");
            SelectExpandNode selectExpandNode = new SelectExpandNode
            {
                SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object, mockConcurrencyProperty.Object }
            };
            ODataProperty[] properties = new[] { new ODataProperty(), new ODataProperty() };
            Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
            serializer.CallBase = true;
            serializer
                .Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
                .Returns(properties[0]);
            serializer
                .Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(1), _entityInstanceContext))
                .Returns(properties[1]);

            MockHttpRequestMessage request = new MockHttpRequestMessage();
            HttpConfiguration configuration = new HttpConfiguration();
            Mock<IETagHandler> mockETagHandler = new Mock<IETagHandler>();
            string tag = "\"'anycity'\"";
            EntityTagHeaderValue etagHeaderValue = new EntityTagHeaderValue(tag, isWeak: true);
            mockETagHandler.Setup(e => e.CreateETag(It.IsAny<IDictionary<string, object>>())).Returns(etagHeaderValue);
            configuration.SetETagHandler(mockETagHandler.Object);
            request.SetConfiguration(configuration);
            _entityInstanceContext.Request = request;

            // Act
            ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);

            // Assert
            Assert.Equal(etagHeaderValue.ToString(), entry.ETag);
        }