コード例 #1
0
ファイル: FakeHttpRequest.cs プロジェクト: nhsevidence/Snooze
 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";
 }
コード例 #2
0
ファイル: RequestTests.cs プロジェクト: mike-schenk/faken
        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));
        }
コード例 #3
0
        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"));
            }
        }
コード例 #4
0
 public void SetUp()
 {
     _collection = new FakeHttpFileCollection();
 }
コード例 #5
0
        public void SetUp()
        {
            var collection = new FakeHttpFileCollection();

            _collection = collection;
        }