示例#1
0
            public void SendsWhenFileExistsWithPrefix()
            {
                const string prefix = "prefix";
                const string folder = "sendresponse-b";
                var          root   = new PublicFolder {
                    Prefix = prefix, FolderPath = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString())
                };
                var folderpath = Path.Combine(root.FolderPath, folder);
                var properties = new Dictionary <string, object> {
                    { "PathInfo", $"/{prefix}/{folder}" }
                };
                var context = Mocks.HttpContext(properties);

                // Create the directory
                if (!Directory.Exists(folderpath))
                {
                    Directory.CreateDirectory(folderpath);
                }

                // Create the required file
                var filepath = Path.Combine(folderpath, root.DefaultFileName);

                using (var sw = File.CreateText(filepath)) { sw.WriteLine("Hello"); }

                root.RespondWithFile(context);
                context.Response.Received().SendResponse(filepath, true);

                CleanUp(root.FolderPath);
            }
示例#2
0
            public void DoesNotSendWhenFileDoesNotExist()
            {
                var properties = new Dictionary <string, object> {
                    { "PathInfo", "/no/file/here" }
                };
                var context = Mocks.HttpContext(properties);
                var root    = new PublicFolder();

                root.RespondWithFile(context);

                context.Response.DidNotReceiveWithAnyArgs().SendResponse(HttpStatusCode.Ok);
            }
示例#3
0
            public void DoesNotSendWhenHttpVerbIsNotGetOrHead()
            {
                var properties = new Dictionary <string, object> {
                    { "HttpMethod", HttpMethod.POST }
                };
                var context = Mocks.HttpContext(properties);
                var root    = new PublicFolder();

                root.RespondWithFile(context);

                context.Response.DidNotReceiveWithAnyArgs().SendResponse(HttpStatusCode.Ok);
            }
示例#4
0
            public void DoesNotSendWhenPathInfoDoesNotMatchPrefix()
            {
                var properties = new Dictionary <string, object> {
                    { "PathInfo", "/some/file.txt" }
                };
                var context = Mocks.HttpContext(properties);
                var root    = new PublicFolder {
                    Prefix = "test"
                };

                root.RespondWithFile(context);

                context.Response.DidNotReceiveWithAnyArgs().SendResponse(HttpStatusCode.Ok);
            }