public void ResolveContentId_ResolvesContentIDInUrl(string url, string expectedResolvedUrl) { Dictionary <string, string> contentIdToLocationMapping = new Dictionary <string, string>(); contentIdToLocationMapping.Add("1", "http://localhost/OData/Customers(42)"); string resolvedUrl = ContentIdHelpers.ResolveContentId(url, contentIdToLocationMapping); Assert.Equal(expectedResolvedUrl, resolvedUrl); }
public void AddLocationHeaderToMapping_DoesNotAddContentIdToLocationMapping_IfLocationIsNull() { // Arrange var response = new HttpResponseMessage(); var contentIdToLocationMapping = new Dictionary <string, string>(); var contentId = Guid.NewGuid().ToString(); // Act ContentIdHelpers.AddLocationHeaderToMapping(response, contentIdToLocationMapping, contentId); // Assert Assert.False(contentIdToLocationMapping.ContainsKey(contentId)); }
public void ResolveContentId_CannotResolveUnmatchedContentIDInUrl(string key, string url) { // Arrange Dictionary <string, string> contentIdToLocationMapping = new Dictionary <string, string>(); contentIdToLocationMapping.Add(key, "http://localhost/OData/Customers(42)"); // Act string resolvedUrl = ContentIdHelpers.ResolveContentId(url, contentIdToLocationMapping); // Assert Assert.Equal(url, resolvedUrl); }
public void ResolveContentId_CannotResolveInvalidContentIDInUrl() { // Arrange string url = "$$/Orders"; Dictionary <string, string> contentIdToLocationMapping = new Dictionary <string, string>(); contentIdToLocationMapping.Add("$", "http://localhost/OData/Customers(42)"); // Act string resolvedUrl = ContentIdHelpers.ResolveContentId(url, contentIdToLocationMapping); // Assert Assert.Equal(url, resolvedUrl); }
public void AddLocationHeaderToMapping_AddsContentIdToLocationMapping() { // Arrange var response = new HttpResponseMessage(); response.Headers.Location = new Uri("http://any"); var contentIdToLocationMapping = new Dictionary <string, string>(); var contentId = Guid.NewGuid().ToString(); // Act ContentIdHelpers.AddLocationHeaderToMapping(response, contentIdToLocationMapping, contentId); // Assert Assert.True(contentIdToLocationMapping.ContainsKey(contentId)); Assert.Equal(response.Headers.Location.AbsoluteUri, contentIdToLocationMapping[contentId]); }
public void ResolveContentId_ResolvesExactContentID(string url, string expectedResolvedUrl) { // Arrange Dictionary <string, string> contentIdToLocationMapping = new Dictionary <string, string>(); for (int id = 1; id < 101; id++) { contentIdToLocationMapping.Add(id.ToString(), string.Format("http://localhost/OData/Customers({0})", id)); } // Act string resolvedUrl = ContentIdHelpers.ResolveContentId(url, contentIdToLocationMapping); // Assert Assert.Equal(expectedResolvedUrl, resolvedUrl); }