Xunit.Assert.Null(object)

Here are the examples of the csharp api Xunit.Assert.Null(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

582 Examples 7

19 View Source File : DependencyScopeExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetService_ReturnsNull_IfServiceNotFound()
        {
            Service actual = _resolver.GetService<Service>();
            replacedert.Null(actual);
        }

19 View Source File : WebHookHandlerContextExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetDataOrDefault_HandlesNullContext()
        {
            // Arrange & Act
            object actual = WebHookHandlerContextExtensions.GetDataOrDefault<string>(null);

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task HEADIfRangeWithCurrentDateShouldReturn200Ok()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Content.Headers.LastModified.Value.ToString("r"));
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);

            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Equal(original.Content.Headers.LastModified, resp.Content.Headers.LastModified);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task HEADIfRangeWithOldEtagShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", "\"OldEtag\"");
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : FormsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void ParseForm()
        {
            IDictionary<string, object> environment = new Dictionary<string, object>();
            MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(OriginalFormsString));
            environment["owin.RequestBody"] = stream;

            IOwinRequest request = new OwinRequest(environment);

            IFormCollection form = request.ReadFormAsync().Result;
            replacedert.Equal("v1", form.Get("q1"));
            replacedert.Equal("v2,b", form.Get("Q2"));
            replacedert.Equal("v3,v4", form.Get("q3"));
            replacedert.Null(form.Get("q4"));
            replacedert.Equal("v5,v5", form.Get("Q5"));
            replacedert.Equal("v 6", form.Get("Q 6"));
            replacedert.True(stream.CanRead);
        }

19 View Source File : AuthenticationManagerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void NullUserReturnsNull()
        {
            IOwinContext context = new OwinContext();
            replacedert.Null(context.Request.User);
            replacedert.Null(context.Authentication.User);
        }

19 View Source File : PolicyHttpMessageHandlerTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task SendAsync_NoContextSet_CreatesNewContext()
        {
            // Arrange
            var policy = Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(10));
            var handler = new TestPolicyHttpMessageHandler(policy);

            Context context = null;
            var expected = new HttpResponseMessage();
            handler.OnSendAsync = (req, c, ct) =>
            {
                context = c;
                replacedert.NotNull(context);
                replacedert.Same(context, req.GetPolicyExecutionContext());
                return expected;
            };

            var request = new HttpRequestMessage();

            // Act
            var response = await handler.SendAsync(request, CancellationToken.None);

            // replacedert
            replacedert.NotNull(context);
            replacedert.Null(request.GetPolicyExecutionContext()); // We clean up the context if it was generated by the handler rather than caller supplied.
            replacedert.Same(expected, response);
        }

19 View Source File : RangeTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void Static_InValidRange()
        {
            using (var server = TestServer.Create(ValidRangeConfiguration))
            {
                var fileContent = File.ReadAllBytes(@"RequirementFiles/Dir1/RangeRequest.txt");

                //Invalid ranges invalid pos values
                var response = server.CreateRequest(@"RequirementFiles/Dir1/RangeRequest.txt").AddHeader("Range", "bytes=1-b").GetAsync().Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Invalid ranges invalid pos values
                response = server.CreateRequest(@"RequirementFiles/Dir1/RangeRequest.txt").AddHeader("Range", "bytes=*-*").GetAsync().Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Invalid ranges invalid pos values
                response = server.CreateRequest(@"RequirementFiles/Dir1/RangeRequest.txt").AddHeader("Range", "bytes=111111111111111111111111111111111111111111111111111132123111111111111111111111111111111111111111111111111111132123-111111111111111111111111111111111111111111111111111132123111111111111111111111111111111111111111111111111111132123").GetAsync().Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Invalid ranges invalid pos values
                response = server.CreateRequest(@"RequirementFiles/Dir1/RangeRequest.txt").AddHeader("Range", "bytes=-").GetAsync().Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Invalid ranges invalid pos values
                response = server.CreateRequest(@"RequirementFiles/Dir1/RangeRequest.txt").AddHeader("Range", "bytes=-,-,13-23").GetAsync().Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);
            }
        }

19 View Source File : WebHookReceiverManagerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetReceiver_Returns_Null_IfUnknownReceiver()
        {
            // Arrange
            MockReceiver multiReceiver = new MockReceiver();
            _receivers.Add(multiReceiver);
            IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object);

            // Act
            IWebHookReceiver actual = manager.GetReceiver("unknown");

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task IfRangeWithOldDateShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Content.Headers.LastModified.Value.Subtract(TimeSpan.FromDays(1)).ToString("r"));
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : ValidateModelAttributeTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void OnActionExecuting_HandlesModelStateSuccess()
        {
            // Arrange
            ModelState state = new ModelState();
            _actionContext.ModelState.Add("m1", state);

            // Act
            _validater.OnActionExecuting(_actionContext);

            // replacedert
            replacedert.Null(_actionContext.Response);
        }

19 View Source File : HeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetMissing_null()
        {
            IHeaderDictionary headers = CreateHeaders(null);
            replacedert.Null(headers[CustomHeaderKey]);
            replacedert.Null(headers.Get(CustomHeaderKey));
            replacedert.Null(headers.GetValues(CustomHeaderKey));
            replacedert.Null(headers.GetCommaSeparatedValues(CustomHeaderKey));
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("")]
        [InlineData("0")]
        [InlineData("1-0")]
        [InlineData("-")]
        public async Task HEADSingleInvalidRangeIgnored(string range)
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.TryAddWithoutValidation("Range", "bytes=" + range);
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task HEADIfRangeWithoutRangeShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Headers.ETag.ToString());
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());

            req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Content.Headers.LastModified.Value.ToString("r"));
            resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : MicrosoftAuthentication.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory, Trait("FunctionalTests", "Security")]
        [InlineData(HostType.HttpListener)]
        public async Task Security_MicrosoftAuthenticationWithProvider(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer("katanatesting.com"))
            {
                //Edit the hosts file at c:\Windows\System32\drivers\etc\hosts and append this at the end before running the test
                //#My entries
                //127.0.0.1 katanatesting.com
                var hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
                if (!File.ReadAllText(hostsFilePath).Contains("127.0.0.1 katanatesting.com"))
                {
                    File.AppendAllText(hostsFilePath, "127.0.0.1 katanatesting.com");
                }

                string applicationUrl = deployer.Deploy(hostType, MicrosoftAuthenticationWithProviderConfiguration);
                //Fix application Url hostname
                applicationUrl = new UriBuilder(applicationUrl) { Host = "katanatesting.com" }.Uri.AbsoluteUri;

                var handler = new HttpClientHandler() { AllowAutoRedirect = false };
                var httpClient = new HttpClient(handler);

                // Unauthenticated request - verify Redirect url
                var response = await httpClient.GetAsync(applicationUrl);
                replacedert.Equal<string>("https://login.microsoftonline.com/common/oauth2/v2.0/authorize", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
                var queryItems = response.Headers.Location.ParseQueryString();
                replacedert.Equal<string>("code", queryItems["response_type"]);
                replacedert.Equal<string>("000000004C0F442C", queryItems["client_id"]);
                replacedert.Equal<string>(applicationUrl + "signin-microsoft", queryItems["redirect_uri"]);
                replacedert.Equal<string>("https://graph.microsoft.com/user.read", queryItems["scope"]);
                replacedert.Equal<string>("ValidStateData", queryItems["state"]);
                replacedert.Equal<string>("custom", queryItems["custom_redirect_uri"]);

                //This is just to generate a correlation cookie. Previous step would generate this cookie, but we have reset the handler now.
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                var correlationCookie = handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Microsoft"];
                replacedert.NotNull(correlationCookie);

                //Invalid state, but valid code
                response = await httpClient.GetAsync(GetMicrosoftSignInMockData(applicationUrl, state: "InvalidStateData"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Application"]);
                replacedert.NotNull(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Microsoft"]);

                //Valid state, but missing code
                handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetMicrosoftSignInMockData(applicationUrl, code: null));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Microsoft"]);

                //Valid code & Valid state
                handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetMicrosoftSignInMockData(applicationUrl));
                replacedert.Equal<string>("Microsoft", await response.Content.ReadreplacedtringAsync());
                var cookies = handler.CookieContainer.GetCookies(new Uri(applicationUrl));
                replacedert.NotNull(cookies[".AspNet.Application"]);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Microsoft"]);

                //Retry with valid credentials for a few times
                for (int retry = 0; retry < 4; retry++)
                {
                    response = await httpClient.GetAsync(applicationUrl);
                    replacedert.Equal<string>("Microsoft", await response.Content.ReadreplacedtringAsync());
                }

                //Valid state, but invalid code
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetMicrosoftSignInMockData(applicationUrl, code: "InvalidCode"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());

                //Valid state, trigger CertValidator
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetMicrosoftSignInMockData(applicationUrl, code: "InvalidCert"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());
            }
        }

19 View Source File : HttpRequestMessageExtensionsTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetPolicyExecutionContext_Null_ReturnsNull()
        {
            // Arrange
            var request = new HttpRequestMessage();
            request.Properties[HttpRequestMessageExtensions.PolicyExecutionContextKey] = null;

            // Act
            var actual = request.GetPolicyExecutionContext();

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : FormsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void ReadFromStreamTwice()
        {
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);
            writer.Write(OriginalFormsString);
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            IOwinRequest request = new OwinRequest();
            request.Body = stream;
            IFormCollection form = request.ReadFormAsync().Result;
            replacedert.Equal("v1", form.Get("q1"));
            replacedert.Equal("v2,b", form.Get("Q2"));
            replacedert.Equal("v3,v4", form.Get("q3"));
            replacedert.Null(form.Get("q4"));
            replacedert.Equal("v5,v5", form.Get("Q5"));
            replacedert.Equal("v 6", form.Get("Q 6"));

            form = request.ReadFormAsync().Result;
            replacedert.Equal("v1", form.Get("q1"));
            replacedert.Equal("v2,b", form.Get("Q2"));
            replacedert.Equal("v3,v4", form.Get("q3"));
            replacedert.Null(form.Get("q4"));
            replacedert.Equal("v5,v5", form.Get("Q5"));
            replacedert.Equal("v 6", form.Get("Q 6"));
        }

19 View Source File : WebHookHandlerContextExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(InvalidJObjectData))]
        public void GetDataOrDefault_ReturnsNullFromInvalidConversionToJObject(JToken data)
        {
            // Arrange
            _context.Data = data;

            // Act (Does not throw despite _context.RequestContext==null. Does not attempt conversion.)
            var actual = _context.GetDataOrDefault<JObject>();

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : GridifyEntityFrameworkTests.cs
License : MIT License
Project Creator : alirezanet

[Fact]
      public void EnreplacedyFrameworkServiceProviderCachingShouldNotThrowException()
      {
         // System.ArgumentException: An item with the same key has already been added. Key: Param_0

         // arrange
         var gq = new GridifyQuery { Filter = "name=n1|name=n2" };

         _dbContext.Users.Gridify(gq);
         _dbContext.Users.Gridify(gq);

         //act
         var exception = Record.Exception(() => _dbContext.Users.GridifyQueryable(gq));

         // replacedert
         replacedert.Null(exception);
      }

19 View Source File : WebHookReceiverManagerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetReceiver_Returns_Null_IfNoReceivers()
        {
            // Arrange
            IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object);

            // Act
            IWebHookReceiver actual = manager.GetReceiver(MockReceiverName);

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task IfRangeWithoutRangeShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Headers.ETag.ToString());
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());

            req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Content.Headers.LastModified.Value.ToString("r"));
            resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("0-0,2-2")]
        [InlineData("0-0,60-")]
        [InlineData("0-0,-2")]
        [InlineData("2-2,0-0")]
        [InlineData("0-0,2-2,4-4,6-6,8-8")]
        [InlineData("0-0,6-6,8-8,2-2,4-4")]
        public async Task MultipleValidRangesShouldServeFullContent(string ranges)
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("Range", "bytes=" + ranges);
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Equal("text/plain", resp.Content.Headers.ContentType.ToString());
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : GridifyEntityFrameworkTests.cs
License : MIT License
Project Creator : alirezanet

[Fact]
      public void GridifyQueryableDateTimeShouldNotThrowException()
      {
         // arrange
         var gq = new GridifyQuery { OrderBy = "CreateDate" };

         // act
         var exception = Record.Exception(() => _dbContext.Users.GridifyQueryable(gq));

         // replacedert
         replacedert.Null(exception);
      }

19 View Source File : FormsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetMissing_null()
        {
            IFormCollection form = CreateForm(null);
            replacedert.Null(form[FormsItemKey]);
            replacedert.Null(form.Get(FormsItemKey));
            replacedert.Null(form.GetValues(FormsItemKey));
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("10-35")]
        public async Task HEADSingleValidRangeShouldReturnOk(string range)
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("Range", "bytes=" + range);
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : HttpApplicationExtensionsTest.cs
License : MIT License
Project Creator : aspnet

[Fact]
        public void GetUnityContainer_Should_Return_Null_If_Registered_WebObjectActivator_Is_Not_ContainerServiceProvider()
        {
            var app = new HttpApplication();
            var existingSP = new Mock<IServiceProvider>();
            HttpRuntime.WebObjectActivator = existingSP.Object;

            var container = app.GetUnityContainer();
            replacedert.Null(container);
        }

19 View Source File : QueryTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void ParseQuery()
        {
            IDictionary<string, object> environment = new Dictionary<string, object>();
            environment["owin.RequestQueryString"] = OriginalQueryString;
            IOwinRequest request = new OwinRequest(environment);
            replacedert.Equal(OriginalQueryString, request.QueryString.Value);

            IReadableStringCollection query = request.Query;
            replacedert.Equal("v1", query.Get("q1"));
            replacedert.Equal("v2,b", query.Get("Q2"));
            replacedert.Equal("v3,v4", query.Get("q3"));
            replacedert.Null(query.Get("q4"));
            replacedert.Equal("v5,v5", query.Get("Q5"));
            replacedert.Equal("v 6", query.Get("Q 6"));
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("")]
        [InlineData("0")]
        [InlineData("1-0")]
        [InlineData("-")]
        public async Task SingleInvalidRangeIgnored(string range)
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.TryAddWithoutValidation("Range", "bytes=" + range);
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task HEADIfRangeWithCurrentEtagShouldReturn200Ok()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Headers.ETag.ToString());
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);

            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Equal(original.Headers.ETag, resp.Headers.ETag);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : GoogleOAuth2Authentication.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory, Trait("FunctionalTests", "Security")]
        [InlineData(HostType.IIS)]
        [InlineData(HostType.HttpListener)]
        public async Task Security_GoogleOAuth2WithProvider(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType, GoogleOAuth2Configuration);
                var handler = new HttpClientHandler() { AllowAutoRedirect = false };
                var httpClient = new HttpClient(handler);

                // Unauthenticated request - verify Redirect url
                var response = await httpClient.GetAsync(applicationUrl);
                replacedert.Equal<string>("https://accounts.google.com/o/oauth2/v2/auth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
                var queryItems = response.Headers.Location.ParseQueryString();
                replacedert.Equal<string>("code", queryItems["response_type"]);
                replacedert.Equal<string>("offline", queryItems["access_type"]);
                replacedert.Equal<string>("581497791735-f9317hcnvcrg9cvl1jfc3tev7teqfump.apps.googleusercontent.com", queryItems["client_id"]);
                replacedert.Equal<string>(applicationUrl + "signin-google", queryItems["redirect_uri"]);
                replacedert.Equal<string>("openid profile email", queryItems["scope"]);
                replacedert.Equal<string>("ValidStateData", queryItems["state"]);
                replacedert.Equal<string>("custom", queryItems["custom_redirect_uri"]);

                //This is just to generate a correlation cookie. Previous step would generate this cookie, but we have reset the handler now.
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                var correlationCookie = handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Google"];
                replacedert.NotNull(correlationCookie);

                //Invalid state, but valid code
                response = await httpClient.GetAsync(GetMockData(applicationUrl, state: "InvalidStateData"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Application"]);
                replacedert.NotNull(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Google"]);

                //Valid state, but missing code
                handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetMockData(applicationUrl, code: null));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Application"]);

                //Valid code & Valid state
                //handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetMockData(applicationUrl));
                replacedert.Equal<string>("Google", response.Content.ReadreplacedtringAsync().Result);
                var cookies = handler.CookieContainer.GetCookies(new Uri(applicationUrl));
                replacedert.NotNull(cookies[".AspNet.Application"]);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Google"]);

                //Retry with valid credentials for a few times
                for (int retry = 0; retry < 4; retry++)
                {
                    response = await httpClient.GetAsync(applicationUrl);
                    replacedert.Equal<string>("Google", await response.Content.ReadreplacedtringAsync());
                }

                //Valid state, but invalid code
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetMockData(applicationUrl, code: "InvalidCode"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());

                //Valid state, trigger CertValidator
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetMockData(applicationUrl, code: "InvalidCert"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());
            }
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task HEADIfRangeWithOldDateShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            HttpResponseMessage original = await server.HttpClient.GetAsync("http://localhost/SubFolder/Ranges.txt");

            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", original.Content.Headers.LastModified.Value.Subtract(TimeSpan.FromDays(1)).ToString("r"));
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal(string.Empty, await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : OwinClientHandlerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void ExpectedKeysAreAvailable()
        {
            var handler = new OwinClientHandler(env =>
            {
                IOwinContext context = new OwinContext(env);

                replacedert.Equal("1.0", context.Get<string>("owin.Version"));
                replacedert.NotNull(context.Get<CancellationToken>("owin.CallCancelled"));
                replacedert.Equal("HTTP/1.1", context.Request.Protocol);
                replacedert.Equal("GET", context.Request.Method);
                replacedert.Equal("https", context.Request.Scheme);
                replacedert.Equal(string.Empty, context.Get<string>("owin.RequestPathBase"));
                replacedert.Equal("/A/Path/and/file.txt", context.Get<string>("owin.RequestPath"));
                replacedert.Equal("and=query", context.Get<string>("owin.RequestQueryString"));
                replacedert.NotNull(context.Request.Body);
                replacedert.NotNull(context.Get<IDictionary<string, string[]>>("owin.RequestHeaders"));
                replacedert.NotNull(context.Get<IDictionary<string, string[]>>("owin.ResponseHeaders"));
                replacedert.NotNull(context.Response.Body);
                replacedert.Equal(200, context.Get<int>("owin.ResponseStatusCode"));
                replacedert.Null(context.Get<string>("owin.ResponseReasonPhrase"));

                replacedert.Equal("example.com", context.Request.Headers.Get("Host"));

                return Task.FromResult(0);
            });
            var httpClient = new HttpClient(handler);
            httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query").Wait();
        }

19 View Source File : DefaultConfigurationLoaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void An_extra_segment_will_cause_the_match_to_fail()
        {
            var loader = new DefaultLoader();
            IList<string> errors = new List<string>();
            Action<IAppBuilder> configuration = loader.Load("Owin.Loader.Tests.DefaultConfigurationLoaderTests.Hello.Bar", errors);

            replacedert.Null(configuration);
            replacedert.NotEmpty(errors);
        }

19 View Source File : AdminRepositoryGetFeatureDefinitionTest.cs
License : Microsoft Public License
Project Creator : achimismaili

[Fact]
        public void CanGetFeatureDefinitionsFarm()
        {
            // Arrange

            //Act
            var featureDefinitions = repository.GetFeatureDefinitions(Microsoft.SharePoint.SPFeatureScope.Farm);

            var FDefinitionHealthyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWeb.Id);
            var FDefinitionHealthySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthySite.Id);
            var FDefinitionHealthyWebApp = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWebApp.Id);
            var FDefinitionHealthyFarm = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyFarm.Id);
            var FDefinitionFaultyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultyWeb.Id);
            var FDefinitionFaultySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultySite.Id);


            //replacedert
            replacedert.Null(FDefinitionHealthyWeb);
            replacedert.Null(FDefinitionHealthySite);
            replacedert.Null(FDefinitionHealthyWebApp);
            replacedert.NotNull(FDefinitionHealthyFarm);
            replacedert.Null(FDefinitionFaultyWeb);
            replacedert.Null(FDefinitionFaultySite);

        }

19 View Source File : WebHookStoreTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("1", true)]
        [InlineData("7", true)]
        [InlineData("unknown", false)]
        public async Task LookupWebHooksAsync_ReturnsExpectedItem(string id, bool present)
        {
            // Arrange
            await Initialize();

            // Act
            var actual = await _store.LookupWebHookAsync(TestUser, id);

            // replacedert
            if (present)
            {
                replacedert.NotNull(actual);
                replacedert.Equal(id, actual.Id);
            }
            else
            {
                replacedert.Null(actual);
            }
        }

19 View Source File : FormsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void ReadFromStream()
        {
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);
            writer.Write(OriginalFormsString);
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            IOwinRequest request = new OwinRequest();
            request.Body = stream;
            IFormCollection form = request.ReadFormAsync().Result;
            replacedert.Equal("v1", form.Get("q1"));
            replacedert.Equal("v2,b", form.Get("Q2"));
            replacedert.Equal("v3,v4", form.Get("q3"));
            replacedert.Null(form.Get("q4"));
            replacedert.Equal("v5,v5", form.Get("Q5"));
            replacedert.Equal("v 6", form.Get("Q 6"));
        }

19 View Source File : HttpRequestMessageExtensionsTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void SetPolicyExecutionContext_WithNull_SetsNull()
        {
            // Arrange
            var request = new HttpRequestMessage();
            request.Properties[HttpRequestMessageExtensions.PolicyExecutionContextKey] = new Context(Guid.NewGuid().ToString());

            // Act
            request.SetPolicyExecutionContext(null);

            // replacedert
            var actual = request.Properties[HttpRequestMessageExtensions.PolicyExecutionContextKey];
            replacedert.Null(actual);
        }

19 View Source File : RangeTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory, Trait("FunctionalTests", "General")]
        [InlineData(HostType.HttpListener)]
        public void Static_ValidRange(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(hostType, ValidRangeConfiguration);
                var httpClient = new HttpClient() { BaseAddress = new Uri(applicationUrl) };
                var fileContent = File.ReadAllBytes(@"RequirementFiles/Dir1/RangeRequest.txt");

                //Range with 1 bytes starting at 0
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(0, 0);
                var response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 0 && response.Content.Headers.ContentRange.To == 0);
                replacedert.Equal<long?>(1, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, 0);

                //Range with 1 bytes starting at 9
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(9, 9);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 9 && response.Content.Headers.ContentRange.To == 9);
                replacedert.Equal<long?>(1, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 9, 9);

                //Range with 2 bytes starting at 5
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(5, 6);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 5 && response.Content.Headers.ContentRange.To == 6);
                replacedert.Equal<long?>(2, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 5, 6);

                //Range with 500 bytes starting at 0
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(0, 499);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 0 && response.Content.Headers.ContentRange.To == 499);
                replacedert.Equal<long?>(500, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, 499);

                //Range with second 500 bytes starting at 500
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(500, 999);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 500 && response.Content.Headers.ContentRange.To == 999);
                replacedert.Equal<long?>(500, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 500, 999);

                //-500
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(null, 500);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == fileContent.Length - 500 && response.Content.Headers.ContentRange.To == fileContent.Length - 1);
                replacedert.Equal<long?>(500, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, fileContent.Length - 500, fileContent.Length - 1);

                //0-
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(0, null);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 0 && response.Content.Headers.ContentRange.To == fileContent.Length - 1);
                replacedert.Equal<long?>(fileContent.Length, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, fileContent.Length - 1);

                //10-
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(10, null);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 10 && response.Content.Headers.ContentRange.To == fileContent.Length - 1);
                replacedert.Equal<long?>(fileContent.Length - 10, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 10, fileContent.Length - 1);

                //0-10*10000
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(0, 10 * 10000);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.PartialContent, response.StatusCode);
                replacedert.True(response.Content.Headers.ContentRange.HasRange &&
                    response.Content.Headers.ContentRange.Unit == "bytes" && response.Content.Headers.ContentRange.Length == fileContent.Length &&
                    response.Content.Headers.ContentRange.From == 0 && response.Content.Headers.ContentRange.To == fileContent.Length - 1);
                replacedert.Equal<long?>(fileContent.Length, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, fileContent.Length - 1);

                //9500-
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(9500, null);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
                replacedert.Equal<long?>(0, response.Content.Headers.ContentLength);

                //-0
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(null, 0);
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
                replacedert.Equal<long?>(0, response.Content.Headers.ContentLength);

                //Invalid ranges last-post > first-pos
                httpClient.DefaultRequestHeaders.Range = null;
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Range", "bytes=100-50");
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Invalid Customized ranges 'pages' instead of 'bytes'. We don't understand what this is. So we should return the full page. 
                httpClient.DefaultRequestHeaders.Remove("Range");
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Range", "pages=1-b");
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long>(fileContent.Length, response.Content.Headers.ContentLength.Value);

                //Multi range requests - not understand we serve the entire file
                httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue();
                httpClient.DefaultRequestHeaders.Range.Ranges.Add(new RangeItemHeaderValue(1, 2));
                httpClient.DefaultRequestHeaders.Range.Ranges.Add(new RangeItemHeaderValue(5, 12));
                httpClient.DefaultRequestHeaders.Range.Ranges.Add(new RangeItemHeaderValue(22, 32));
                response = httpClient.GetAsync(@"RequirementFiles/Dir1/RangeRequest.txt").Result;
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                replacedert.Null(response.Content.Headers.ContentRange);
                replacedert.Equal<long?>(fileContent.Length, response.Content.Headers.ContentLength);
                CompareBytes(fileContent, response.Content.ReadAsByteArrayAsync().Result, 0, fileContent.Length - 1);
            }
        }

19 View Source File : WebHookHandlerContextExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(InvalidJArrayData))]
        public void GetDataOrDefault_ReturnsNullFromInvalidConversionToJArray(JToken data)
        {
            // Arrange
            _context.Data = data;

            // Act (Does not throw despite _context.RequestContext==null. Does not attempt conversion.)
            var actual = _context.GetDataOrDefault<JArray>();

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : HeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void SetNullOrEmpty_Remove()
        {
            IHeaderDictionary headers;

            headers = CreateHeaders(CustomHeaderRawValues);
            headers[CustomHeaderKey] = null;
            replacedert.Null(headers[CustomHeaderKey]);

            headers = CreateHeaders(CustomHeaderRawValues);
            headers[CustomHeaderKey] = string.Empty;
            replacedert.Null(headers[CustomHeaderKey]);

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.Set(CustomHeaderKey, null);
            replacedert.Null(headers.Get(CustomHeaderKey));

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.Set(CustomHeaderKey, string.Empty);
            replacedert.Null(headers.Get(CustomHeaderKey));

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.SetValues(CustomHeaderKey, (string[])null);
            replacedert.Null(headers.GetValues(CustomHeaderKey));

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.SetValues(CustomHeaderKey, new string[0]);
            replacedert.Null(headers.GetValues(CustomHeaderKey));

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.SetCommaSeparatedValues(CustomHeaderKey, (string[])null);
            replacedert.Null(headers.GetCommaSeparatedValues(CustomHeaderKey));

            headers = CreateHeaders(CustomHeaderRawValues);
            headers.SetCommaSeparatedValues(CustomHeaderKey, new string[0]);
            replacedert.Null(headers.GetCommaSeparatedValues(CustomHeaderKey));
        }

19 View Source File : WebHookHandlerContextExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(InvalidJValueData))]
        public void GetDataOrDefault_ReturnsNullFromInvalidConversionToJValue(JToken data)
        {
            // Arrange
            _context.Data = data;

            // Act (Does not throw despite _context.RequestContext==null. Does not attempt conversion.)
            var actual = _context.GetDataOrDefault<JValue>();

            // replacedert
            replacedert.Null(actual);
        }

19 View Source File : AdminRepositoryGetFeatureDefinitionTest.cs
License : Microsoft Public License
Project Creator : achimismaili

[Fact]
        public void CanGetFeatureDefinitionsSite()
        {
            // Arrange

            //Act
            var featureDefinitions = repository.GetFeatureDefinitions(Microsoft.SharePoint.SPFeatureScope.Site);

            var FDefinitionHealthyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWeb.Id);
            var FDefinitionHealthySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthySite.Id);
            var FDefinitionHealthyWebApp = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWebApp.Id);
            var FDefinitionHealthyFarm = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyFarm.Id);
            var FDefinitionFaultyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultyWeb.Id);
            var FDefinitionFaultySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultySite.Id);


            //replacedert
            replacedert.Null(FDefinitionHealthyWeb);
            replacedert.NotNull(FDefinitionHealthySite);
            replacedert.Null(FDefinitionHealthyWebApp);
            replacedert.Null(FDefinitionHealthyFarm);
            replacedert.Null(FDefinitionFaultyWeb);
            replacedert.NotNull(FDefinitionFaultySite);

        }

19 View Source File : WebHookQueueHandlerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Succeeds()
        {
            // Arrange
            _queueHandlerMock.Setup<Task>(q => q.EnqueueAsync(It.Is<WebHookQueueContext>(c => ValidateContext(c))))
                .Returns(Task.FromResult(true))
                .Verifiable();

            // Act
            await _queueHandlerMock.Object.ExecuteAsync(TestReceiver, _context);

            // replacedert
            _queueHandlerMock.Verify();
            replacedert.Null(_context.Response);
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task IfRangeWithOldEtagShouldServeFullContent()
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.Add("If-Range", "\"OldEtag\"");
            req.Headers.Add("Range", "bytes=0-10");
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
            replacedert.Equal(62, resp.Content.Headers.ContentLength);
            replacedert.Equal("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", await resp.Content.ReadreplacedtringAsync());
        }

19 View Source File : ServerFactoryLoaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData(null)]
        [InlineData("")]
        [InlineData("OwinServerFactory")]
        [InlineData("Microsoft.Owin")]
        [InlineData("Microsoft.Owin.Hosting")]
        [InlineData("Microsoft.Owin.Hosting.Tests.MissingServerFactory")]
        [InlineData("Microsoft.Owin.Hosting.Tests.Nested.MissingServerFactory")]
        public void LoadWithWrongreplacedemblyOrType_ReturnsNull(string data)
        {
            var loader = new ServerFactoryLoader(new ServerFactoryActivator(ServicesFactory.Create()));
            IServerFactoryAdapter serverFactory = loader.Load(data);
            replacedert.Null(serverFactory);
        }

19 View Source File : AdminRepositoryGetFeatureDefinitionTest.cs
License : Microsoft Public License
Project Creator : achimismaili

[Fact]
        public void CanGetFeatureDefinitionsWeb()
        {
            // Arrange

            //Act
            var featureDefinitions = repository.GetFeatureDefinitions(Microsoft.SharePoint.SPFeatureScope.Web);

            var FDefinitionHealthyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWeb.Id);
            var FDefinitionHealthySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthySite.Id);
            var FDefinitionHealthyWebApp = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWebApp.Id);
            var FDefinitionHealthyFarm = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyFarm.Id);
            var FDefinitionFaultyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultyWeb.Id);
            var FDefinitionFaultySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultySite.Id);


            //replacedert
            replacedert.NotNull(FDefinitionHealthyWeb);
            replacedert.Null(FDefinitionHealthySite);
            replacedert.Null(FDefinitionHealthyWebApp);
            replacedert.Null(FDefinitionHealthyFarm);
            replacedert.NotNull(FDefinitionFaultyWeb);
            replacedert.Null(FDefinitionFaultySite);

        }

19 View Source File : AdminRepositoryGetFeatureDefinitionTest.cs
License : Microsoft Public License
Project Creator : achimismaili

[Fact]
        public void CanGetFeatureDefinitionsWebApp()
        {
            // Arrange

            //Act
            var featureDefinitions = repository.GetFeatureDefinitions(Microsoft.SharePoint.SPFeatureScope.WebApplication);

            var FDefinitionHealthyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWeb.Id);
            var FDefinitionHealthySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthySite.Id);
            var FDefinitionHealthyWebApp = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyWebApp.Id);
            var FDefinitionHealthyFarm = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.HealthyFarm.Id);
            var FDefinitionFaultyWeb = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultyWeb.Id);
            var FDefinitionFaultySite = featureDefinitions.FirstOrDefault(f => f.Id == TestContent.TestFeatures.FaultySite.Id);


            //replacedert
            replacedert.Null(FDefinitionHealthyWeb);
            replacedert.Null(FDefinitionHealthySite);
            replacedert.NotNull(FDefinitionHealthyWebApp);
            replacedert.Null(FDefinitionHealthyFarm);
            replacedert.Null(FDefinitionFaultyWeb);
            replacedert.Null(FDefinitionFaultySite);

        }

19 View Source File : FacebookAuthentication.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory, Trait("FunctionalTests", "Security")]
        [InlineData(HostType.IIS)]
        [InlineData(HostType.HttpListener)]
        public async Task Security_FacebookAuthentication(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(hostType, FacebookAuthenticationConfiguration);

                var handler = new HttpClientHandler() { AllowAutoRedirect = false };
                var httpClient = new HttpClient(handler);

                // Unauthenticated request - verify Redirect url
                var response = await httpClient.GetAsync(applicationUrl);
                replacedert.Equal<string>("https://www.facebook.com/v2.8/dialog/oauth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
                var queryItems = response.Headers.Location.ParseQueryString();
                replacedert.Equal<string>("code", queryItems["response_type"]);
                replacedert.Equal<string>("550624398330273", queryItems["client_id"]);
                replacedert.Equal<string>(applicationUrl + "signin-facebook", queryItems["redirect_uri"]);
                replacedert.Equal<string>("public_profile,email,read_friendlists,user_checkins", queryItems["scope"]);
                replacedert.Equal<string>("ValidStateData", queryItems["state"]);
                replacedert.Equal<string>("custom", queryItems["custom_redirect_uri"]);

                //This is just to generate a correlation cookie. Previous step would generate this cookie, but we have reset the handler now.
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                var correlationCookie = handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Facebook"];
                replacedert.NotNull(correlationCookie);

                //Invalid state, but valid code
                response = await httpClient.GetAsync(GetFacebookSignInMockData(applicationUrl, state: "InvalidStateData"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Application"]);
                replacedert.NotNull(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Facebook"]);

                //Valid state, but missing code
                handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetFacebookSignInMockData(applicationUrl, code: null));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", await response.Content.ReadreplacedtringAsync());
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Facebook"]);

                //Valid code & Valid state
                handler.CookieContainer.Add(correlationCookie);
                response = await httpClient.GetAsync(GetFacebookSignInMockData(applicationUrl));
                replacedert.Equal<string>("Facebook", response.Content.ReadreplacedtringAsync().Result);
                var cookies = handler.CookieContainer.GetCookies(new Uri(applicationUrl));
                replacedert.NotNull(cookies[".AspNet.Application"]);
                replacedert.Null(handler.CookieContainer.GetCookies(new Uri(applicationUrl))[".AspNet.Correlation.Facebook"]);

                //Retry with valid credentials for a few times
                for (int retry = 0; retry < 4; retry++)
                {
                    response = await httpClient.GetAsync(applicationUrl);
                    replacedert.Equal<string>("Facebook", response.Content.ReadreplacedtringAsync().Result);
                }

                //Valid state, but invalid code
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetFacebookSignInMockData(applicationUrl, code: "InvalidCode"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", response.Content.ReadreplacedtringAsync().Result);

                //Valid state, trigger CertValidator
                httpClient = new HttpClient(handler = new HttpClientHandler());
                response = await httpClient.GetAsync(applicationUrl);
                response = await httpClient.GetAsync(GetFacebookSignInMockData(applicationUrl, code: "InvalidCert"));
                replacedert.Equal<HttpStatusCode>(HttpStatusCode.InternalServerError, response.StatusCode);
                replacedert.Equal<string>("SignIn_Failed", response.Content.ReadreplacedtringAsync().Result);
            }
        }

19 View Source File : RangeHeaderTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [InlineData("1000-1001")] // Out of range
        public async Task HEADSingleNotSatisfiableRangeReturnsOk(string range)
        {
            TestServer server = TestServer.Create(app => app.UseFileServer());
            var req = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Ranges.txt");
            req.Headers.TryAddWithoutValidation("Range", "bytes=" + range);
            HttpResponseMessage resp = await server.HttpClient.SendAsync(req);
            replacedert.Equal(HttpStatusCode.OK, resp.StatusCode);
            replacedert.Null(resp.Content.Headers.ContentRange);
        }

19 View Source File : QueryTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetMissing_null()
        {
            IReadableStringCollection query = CreateQuery(null);
            replacedert.Null(query[QueryItemKey]);
            replacedert.Null(query.Get(QueryItemKey));
            replacedert.Null(query.GetValues(QueryItemKey));
        }

See More Examples