Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/godfisk 586/redirect module handle url with slash in the end #21

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from

Conversation

grom8255
Copy link

@grom8255 grom8255 commented May 11, 2018

fixes #13
The essence of the change is in the following tests:

CustomRedirect spec
  CustomRedirectCollection spec
    describe CustomRedirectCollection with exact match
      Given the redirect rule is http://mysite/test => http://mysite, exactMatch=True
        when url is 'http://mysite/test' then it's redirected to 'http://mysite' (29ms)
        (CHANGE) when url is 'http://mysite/test/' then it's redirected to 'http://mysite' (0ms)
        when url is 'http://mysite/testme' then it does not redirect (1ms)
        when url is 'http://mysite/testme' then it does not redirect (0ms)
        and includeQueryString=true
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite?query=my-query' (1ms)
        and includeQueryString=false
          when url is 'http://mysite/test' then it's redirected to 'http://mysite' (1ms)
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite' (0ms)
    describe CustomRedirectCollection exact match false and append match to new url false
      Given the redirect rule is http://mysite/test => http://mysite, exactNatch=False, appendMatchToNewUrl=False
        when url is 'http://mysite/test' then it's redirected to 'http://mysite' (0ms)
        (CHANGE) when url is 'http://mysite/test/' then it's redirected to 'http://mysite' (0ms)
        when url is 'http://mysite/testme' then it's redirected to 'http://mysite' (0ms)
        when url is 'http://mysite/test/me' then it's redirected to 'http://mysite' (0ms)
        and includeQueryString=true
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite?query=my-query' (0ms)
        and includeQueryString=false
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite' (0ms)
    describe CustomRedirectCollection exact match false and append match to new url true
      Given the redirect rule is http://mysite/test => http://mysite, exactNatch=False, appendMatchToNewUrl=True
        when url is 'http://mysite/test' then it's redirected to 'http://mysite' (0ms)
        (CHANGE)when url is 'http://mysite/test/' then it's redirected to 'http://mysite' (0ms)**
        when url is 'http://mysite/testme' then it's redirected to 'http://mysiteme' (0ms)
        when url is 'http://mysite/test/me' then it's redirected to 'http://mysite/me' (0ms)
        and includeQueryString=true
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite?query=my-query' (0ms)
          when url is 'http://mysite/testme?query=my-query' then it's redirected to 'http://mysiteme?query=my-query' (0ms)
        and includeQueryString=false
          when url is 'http://mysite/test?query=my-query' then it's redirected to 'http://mysite' (0ms)
          when url is 'http://mysite/testme?query=my-query' then it's redirected to 'http://mysiteme' (0ms)
    describe CustomRedirectCollection query string merge
      Given the redirect rule is http://mysite/test => http://mysite?a=1&b=2, exactMatch=True, appendMatchToNewUrl=True
        when url is 'http://mysite/test?a=0&x=0' then it's redirected to 'http://mysite?a=1&b=2&x=0' (0ms)
        when url is 'http://mysite/test/?x=0' then it's redirected to 'http://mysite?a=1&b=2&x=0' (0ms)
    (CHANGE) describe CustomRedirectCollection protocol invariant rule
      Given the redirect rule is //mysite/test => //mysite, exactMatch=True, appendMatchToNewUrl=True
        when url is 'http://mysite/test' then it's redirected to '//mysite' (0ms)
        when url is 'https://mysite/test' then it's redirected to '//mysite' (0ms)
      Given the redirect rule is //mysite/test => https://mysite, exactMatch=True, appendMatchToNewUrl=True
        when url is 'http://mysite/test' then it's redirected to 'https://mysite' (0ms)
        when url is 'https://mysite/test' then it's redirected to 'https://mysite' (0ms)
    describe CustomRedirectCollection wildcard append works with rule for relative url
      Given the redirect rule is /test => http://mysite
        when url is 'http://mysite/test' then it's redirected to 'http://mysite' (0ms)
        when url is 'http://mysite/testme' then it's redirected to 'http://mysiteme' (0ms)
        when url is 'http://mysite/test/me' then it's redirected to 'http://mysite/me' (0ms)
        when url is 'http://mysite/test/me?a=0&b=1' then it's redirected to 'http://mysite/me?a=0&b=1' (0ms)

@@ -462,9 +447,9 @@
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerPort>51181</DevelopmentServerPort>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Roman982 please move the settings outside the project (to .user file)

@@ -23,6 +25,14 @@ public CustomRedirect(string oldUrl, string newUrl, bool appendMatchToNewUrl, bo

}

public CustomRedirect(CustomRedirect redirect)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state and notFoundErrorCount are missed in the copy ctor

@@ -23,6 +25,16 @@ public CustomRedirect(string oldUrl, string newUrl, bool appendMatchToNewUrl, bo

}

public CustomRedirect(CustomRedirect redirect)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks strange that "copy" stor has differnt logic with Copy method, I think it would be better to have two differrent methods with corresponding names instead.

public string OldUrl { get; set; }
public string OldUrl
{
get => UrlStandardizer.Standardize(_oldUrl);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks strange that UrlStandardizer.Standardize method used for both get and set.

[TestCase("http://www.website.com/test/x1", "/sjomatskolen/x1")]
[TestCase("http://www.website.com/test/x2/", "/sjomatskolen/x2")]
[TestCase("http://www.website.com/test/x3/?a=b", "/sjomatskolen/x3?a=b")]
public void the_original_redirect_newurl_remains_unchanged(string url, string expectedRedirect)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected redirect is not used


context[$"Given the redirect rule is http://mysite/test => http://mysite, exactMatch={exactMatch}"] = () =>
{
before = () => redirects = new CustomRedirectCollection { new CustomRedirect("http://mysite/test", "http://mysite", appendMatchToNewUrl, exactMatch, true) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have the last parameter name here


context[$"Given the redirect rule is http://mysite/test => http://mysite, exactNatch={exactMatch}, appendMatchToNewUrl={appendMatchToNewUrl}"] = () =>
{
before = () => redirects = new CustomRedirectCollection { new CustomRedirect("http://mysite/test", "http://mysite", appendMatchToNewUrl, exactMatch, true) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be nice to test case when new ULR has / at the end (http://mysite/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants