public void allowed_remote_ip_will_give_null_result() { var mockContext = new Mock <HttpContext>(); //for remote , local ip != remote ip mockContext.Setup(x => x.Connection.LocalIpAddress).Returns(() => new IPAddress(IP_10_0_0_1)); mockContext.Setup(x => x.Connection.RemoteIpAddress).Returns(() => new IPAddress(IP_10_0_0_2)); var actionContext = new ActionContext( mockContext.Object, new Mock <RouteData>().Object, new Mock <ActionDescriptor>().Object ); var actionExecutingContext = new AuthorizationFilterContext( actionContext, new List <IFilterMetadata>() //, //new Dictionary<string, object>(), //new Mock<Controller>().Object ); var mockLogger = new Mock <ILogger <IPAddressVerification> >(); IPAddressVerification obj = new IPAddressVerification(realSettingsReader, mockLogger.Object); obj.OnAuthorization(actionExecutingContext); Assert.Null(actionExecutingContext.Result); }
public void local_ip_will_give_null_result() { var mockContext = new Mock <HttpContext>(); //local request = local ip==remote ip mockContext.Setup(x => x.Connection.LocalIpAddress).Returns(() => new IPAddress(IP_10_0_0_10)); mockContext.Setup(x => x.Connection.RemoteIpAddress).Returns(() => new IPAddress(IP_10_0_0_10)); var actionContext = new ActionContext( mockContext.Object, new Mock <RouteData>().Object, new Mock <ActionDescriptor>().Object ); var actionExecutingContext = new AuthorizationFilterContext( actionContext, new List <IFilterMetadata>() ); var mockLogger = new Mock <ILogger <IPAddressVerification> >(); IPAddressVerification obj = new IPAddressVerification(realSettingsReader, mockLogger.Object); obj.OnAuthorization(actionExecutingContext); Assert.Null(actionExecutingContext.Result); }