public FakeHttpRequest() { SetUrl(new Uri("http://localhost")); _cookies = new HttpCookieCollection(); _form = new NameValueCollection(); _queryString = new NameValueCollection(); _serverVariables = new NameValueCollection(); _files = new FakeHttpFileCollection(); _headers = new NameValueCollection(); _context = new FakeHttpContext(this); _httpMethod = "GET"; }
public void Can_add_and_read_from_files() { var request = new FakeHttpRequest(); var files = new FakeHttpFileCollection(); var bytes = Encoding.UTF8.GetBytes("These are file contents"); var fileContents = new MemoryStream(); fileContents.Write(bytes, 0, bytes.Length); fileContents.Flush(); fileContents.Position = 0; var file = new FakeHttpPostedFile("SomeFile.txt", "text/plain", fileContents); files.Add("FileFormFieldValue", file); request.SetFiles(files); Assert.That(request.Files.Count, Is.EqualTo(1)); Assert.That(request.Files[0].FileName, Is.EqualTo("SomeFile.txt")); Assert.That(request.Files[0].ContentType, Is.EqualTo("text/plain")); Assert.That(request.Files[0].ContentLength, Is.EqualTo(fileContents.Length)); }
public void Field_names_are_not_case_sensitive() { var testSubject = new FakeHttpFileCollection(); const string formFieldNameInMixedCase = "FileFormFieldValue"; for (int i = 0; i < 4; i++) { // simulate an uploaded file var bytes = Encoding.UTF8.GetBytes("These are file contents"); var fileContents = new MemoryStream(bytes, false); var file = new FakeHttpPostedFile("SomeFile" + i + ".txt", "text/plain", fileContents); var fieldNameToAdd = formFieldNameInMixedCase + i; testSubject.Add(fieldNameToAdd, file); } Assert.That(testSubject.Count, Is.EqualTo(4)); for (int i = 0; i < 4; i++) { // retrieve each one using different variations of case and make sure we get the right one var fieldNameToRetrieve = formFieldNameInMixedCase + i; var foundFile = testSubject[fieldNameToRetrieve.ToUpperInvariant()]; Assert.That(foundFile, Is.Not.Null); Assert.That(foundFile.FileName, Is.EqualTo("SomeFile" + i + ".txt")); foundFile = testSubject[fieldNameToRetrieve.ToLowerInvariant()]; Assert.That(foundFile, Is.Not.Null); Assert.That(foundFile.FileName, Is.EqualTo("SomeFile" + i + ".txt")); TextInfo text = CultureInfo.CurrentCulture.TextInfo; var formFieldNameInTitleCase = text.ToTitleCase(fieldNameToRetrieve); foundFile = testSubject[formFieldNameInTitleCase]; Assert.That(foundFile, Is.Not.Null); Assert.That(foundFile.FileName, Is.EqualTo("SomeFile" + i + ".txt")); } }
public void SetUp() { _collection = new FakeHttpFileCollection(); }
public void SetUp() { var collection = new FakeHttpFileCollection(); _collection = collection; }