public void WasRequestRewritten_ChecksIfUrlRewriterIsTurnedOnOnlyOnce() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); UrlRewriteMocks request1 = CreateMockContext( isUrlRewriteOnForServer: false, isUrlRewriteOnForRequest: false ); UrlRewriteMocks request2 = CreateMockContext( isUrlRewriteOnForServer: false, isUrlRewriteOnForRequest: false ); // Act bool result1 = helper.WasRequestRewritten(request1.Context.Object); bool result2 = helper.WasRequestRewritten(request2.Context.Object); // Assert request1.WorkerRequest.Verify( c => c.GetServerVariable(UrlRewriterHelper.UrlRewriterEnabledServerVar), Times.Once() ); request2.WorkerRequest.Verify( c => c.GetServerVariable(UrlRewriterHelper.UrlRewriterEnabledServerVar), Times.Never() ); Assert.False(result1); Assert.False(result2); }
public void WasRequestRewritten_TrueIfUrlRewriterIsTurnedOnAndRequestWasRewritten() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); UrlRewriteMocks request = CreateMockContext(isUrlRewriteOnForServer: true, isUrlRewriteOnForRequest: true); // Act bool result = helper.WasRequestRewritten(request.Context.Object); // Assert Assert.True(result); request.WorkerRequest.Verify(); }
public void WasRequestRewritten_FalseIfUrlRewriterIsTurnedOff() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); UrlRewriteMocks request = CreateMockContext(isUrlRewriteOnForServer: false, isUrlRewriteOnForRequest: false); // Act bool result = helper.WasRequestRewritten(request.Context.Object); // Assert Assert.False(result); request.WorkerRequest.Verify(); request.WorkerRequest.Verify(wr => wr.GetServerVariable(UrlRewriterHelper.UrlWasRewrittenServerVar), Times.Never()); }
public void WasRequestRewritten_TrueIfUrlRewriterIsTurnedOnAndRequestWasRewritten() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock<HttpContextBase> requestMock = new Mock<HttpContextBase>(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlRewriterEnabledServerVar)).Returns("yes").Verifiable(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlWasRewrittenServerVar)).Returns("yes").Verifiable(); // Act bool result = helper.WasRequestRewritten(requestMock.Object); // Assert Assert.IsTrue(result); requestMock.Verify(); }
public void WasRequestRewritten_FalseIfUrlRewriterIsTurnedOff() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock<HttpContextBase> requestMock = new Mock<HttpContextBase>(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlRewriterEnabledServerVar)).Returns((string)null).Verifiable(); // Act bool result = helper.WasRequestRewritten(requestMock.Object); // Assert Assert.IsFalse(result); requestMock.Verify(); requestMock.Verify(c => c.Request.ServerVariables.Get(_urlWasRewrittenServerVar), Times.Never()); }
public void WasRequestRewritten_ChecksRequest_OnlyOnce_Positive() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); UrlRewriteMocks request1 = CreateMockContext(isUrlRewriteOnForServer: true, isUrlRewriteOnForRequest: true); // Act bool result1 = helper.WasRequestRewritten(request1.Context.Object); bool result2 = helper.WasRequestRewritten(request1.Context.Object); // Assert request1.WorkerRequest.Verify(c => c.GetServerVariable(UrlRewriterHelper.UrlWasRewrittenServerVar), Times.Once()); Assert.True(result1); Assert.True(result2); }
public void WasRequestRewritten_TrueIfUrlRewriterIsTurnedOnAndRequestWasRewritten() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock <HttpContextBase> requestMock = new Mock <HttpContextBase>(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlRewriterEnabledServerVar)).Returns("yes").Verifiable(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlWasRewrittenServerVar)).Returns("yes").Verifiable(); // Act bool result = helper.WasRequestRewritten(requestMock.Object); // Assert Assert.True(result); requestMock.Verify(); }
public void WasRequestRewritten_FalseIfUrlRewriterIsTurnedOff() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock <HttpContextBase> requestMock = new Mock <HttpContextBase>(); requestMock.Setup(c => c.Request.ServerVariables.Get(_urlRewriterEnabledServerVar)).Returns((string)null).Verifiable(); // Act bool result = helper.WasRequestRewritten(requestMock.Object); // Assert Assert.False(result); requestMock.Verify(); requestMock.Verify(c => c.Request.ServerVariables.Get(_urlWasRewrittenServerVar), Times.Never()); }
public void WasRequestRewritten_ChecksIfUrlRewriterIsTurnedOnOnlyOnce() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock<HttpContextBase> request1Mock = new Mock<HttpContextBase>(); request1Mock.Setup(c => c.Request.ServerVariables).Returns(new NameValueCollection()); Mock<HttpContextBase> request2Mock = new Mock<HttpContextBase>(); // Act bool result1 = helper.WasRequestRewritten(request1Mock.Object); bool result2 = helper.WasRequestRewritten(request2Mock.Object); // Assert request1Mock.Verify(c => c.Request.ServerVariables, Times.Once()); request2Mock.Verify(c => c.Request.ServerVariables, Times.Never()); Assert.IsFalse(result1); Assert.IsFalse(result2); }
public void WasRequestRewritten_ChecksIfUrlRewriterIsTurnedOnOnlyOnce() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); UrlRewriteMocks request1 = CreateMockContext(isUrlRewriteOnForServer: false, isUrlRewriteOnForRequest: false); UrlRewriteMocks request2 = CreateMockContext(isUrlRewriteOnForServer: false, isUrlRewriteOnForRequest: false); // Act bool result1 = helper.WasRequestRewritten(request1.Context.Object); bool result2 = helper.WasRequestRewritten(request2.Context.Object); // Assert request1.WorkerRequest.Verify(c => c.GetServerVariable(UrlRewriterHelper.UrlRewriterEnabledServerVar), Times.Once()); request2.WorkerRequest.Verify(c => c.GetServerVariable(UrlRewriterHelper.UrlRewriterEnabledServerVar), Times.Never()); Assert.False(result1); Assert.False(result2); }
public void WasRequestRewritten_ChecksIfUrlRewriterIsTurnedOnOnlyOnce() { // Arrange UrlRewriterHelper helper = new UrlRewriterHelper(); Mock <HttpContextBase> request1Mock = new Mock <HttpContextBase>(); request1Mock.Setup(c => c.Request.ServerVariables).Returns(new NameValueCollection()); Mock <HttpContextBase> request2Mock = new Mock <HttpContextBase>(); // Act bool result1 = helper.WasRequestRewritten(request1Mock.Object); bool result2 = helper.WasRequestRewritten(request2Mock.Object); // Assert request1Mock.Verify(c => c.Request.ServerVariables, Times.Once()); request2Mock.Verify(c => c.Request.ServerVariables, Times.Never()); Assert.False(result1); Assert.False(result2); }
internal static void ResetUrlRewriterHelper() { _urlRewriterHelper = new UrlRewriterHelper(); }