public void ResultDoesNotIncludeFormTagAndSubmitButtonWhenNotRequested() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); string expectedResult = @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div></div>"; // Act var actualResult = fileUpload.GetHtml(name: null, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: false, includeFormTag: false, addText: null, uploadText: null); Assert.AreEqual(expectedResult, actualResult.ToString()); }
public void RenderThrowsWhenNumberOfFilesIsLessThanZero() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); ExceptionAssert.ThrowsArgGreaterThanOrEqualTo( () => fileUpload.GetHtml(name: null, initialNumberOfFiles: -2, allowMoreFilesToBeAdded: false, includeFormTag: false, addText: "", uploadText: ""), "initialNumberOfFiles", "0"); }
public void ResultDoesNotIncludeAnchorTagNorAddTextWhenNotRequested() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); string customAddText = "Add More"; string expectedResult = @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div></div>"; // Act var result = fileUpload.GetHtml(name: null, allowMoreFilesToBeAdded: false, includeFormTag: false, addText: customAddText, uploadText: null, initialNumberOfFiles: 1); // Assert Assert.AreEqual(expectedResult, result.ToString()); }
public void ResultIncludesCorrectNumberOfInputFields() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); string expectedResult = @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div><div><input name=""fileUpload"" type=""file"" /></div>" + @"<div><input name=""fileUpload"" type=""file"" /></div></div>"; // Act var actualResult = fileUpload.GetHtml(name: null, initialNumberOfFiles: 3, allowMoreFilesToBeAdded: false, includeFormTag: false, addText: null, uploadText: null); // Assert Assert.AreEqual(expectedResult, actualResult.ToString()); }
public void ResultIncludesFormTagAndSubmitButtonWhenRequested() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); string expectedResult = @"<form action="""" enctype=""multipart/form-data"" method=""post""><div class=""file-upload"" id=""file-upload-0"">" + @"<div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><input type=""submit"" value=""Upload"" /></div></form>"; // Act var actualResult = fileUpload.GetHtml(name: null, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: false, includeFormTag: true, addText: null, uploadText: null); // Assert Assert.AreEqual(expectedResult, actualResult.ToString()); }
public void ResultIncludesAnchorTagWithCorrectAddText() { // Arrange var fileUpload = new FileUploadImplementation(GetContext()); string customAddText = "Add More"; string expectedResult = _fileUploadScript + @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><a href=""#"" onclick=""FileUploadHelper.addInputElement(0, "fileUpload"); return false;"">" + customAddText + "</a></div>"; // Act var result = fileUpload.GetHtml(name: null, allowMoreFilesToBeAdded: true, includeFormTag: false, addText: customAddText, initialNumberOfFiles: 1, uploadText: null); // Assert Assert.AreEqual(expectedResult, result.ToString()); }
public void FileUploadUsesNamePropertyInJavascript() { // Arrange var context = GetContext(); string name = "foobar"; string expectedResult = _fileUploadScript + @"<form action="""" enctype=""multipart/form-data"" method=""post""><div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><a href=""#"" onclick=""FileUploadHelper.addInputElement(0, "foobar"); return false;"">Add more files</a><input type=""submit"" value=""Upload"" /></div></form>"; // Act var result = new FileUploadImplementation(context).GetHtml(name: name, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: true, addText: null, uploadText: null); // Assert Assert.AreEqual(expectedResult, result.ToString()); }
public void FileUploadGeneratesUniqueIdsForMultipleCallsForCommonRequest() { // Arrange var context = GetContext(); string expectedResult1 = @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div><div><input name=""fileUpload"" type=""file"" /></div>" + @"<div><input name=""fileUpload"" type=""file"" /></div></div>"; string expectedResult2 = @"<form action="""" enctype=""multipart/form-data"" method=""post""><div class=""file-upload"" id=""file-upload-1""><div><input name=""fileUpload"" type=""file"" /></div>" + @"<div><input name=""fileUpload"" type=""file"" /></div></div><div class=""file-upload-buttons""><input type=""submit"" value=""Upload"" /></div></form>"; // Act var result1 = new FileUploadImplementation(context).GetHtml(name: null, initialNumberOfFiles: 3, allowMoreFilesToBeAdded: false, includeFormTag: false, addText: null, uploadText: null); var result2 = new FileUploadImplementation(context).GetHtml(name: null, initialNumberOfFiles: 2, allowMoreFilesToBeAdded: false, includeFormTag: true, addText: null, uploadText: null); // Assert Assert.AreEqual(expectedResult1, result1.ToString()); Assert.AreEqual(expectedResult2, result2.ToString()); }
public void FileUploadGeneratesScriptOncePerRequest() { // Arrange var context = GetContext(); string expectedResult1 = _fileUploadScript + @"<div class=""file-upload"" id=""file-upload-0""><div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><a href=""#"" onclick=""FileUploadHelper.addInputElement(0, "fileUpload"); return false;"">Add more files</a></div>"; string expectedResult2 = @"<form action="""" enctype=""multipart/form-data"" method=""post""><div class=""file-upload"" id=""file-upload-1""><div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><a href=""#"" onclick=""FileUploadHelper.addInputElement(1, "fileUpload"); return false;"">Add more files</a><input type=""submit"" value=""Upload"" /></div></form>"; string expectedResult3 = @"<form action="""" enctype=""multipart/form-data"" method=""post""><div class=""file-upload"" id=""file-upload-2"">" + @"<div><input name=""fileUpload"" type=""file"" /></div></div>" + @"<div class=""file-upload-buttons""><input type=""submit"" value=""Upload"" /></div></form>"; // Act var result1 = new FileUploadImplementation(context).GetHtml(name: null, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: false, addText: null, uploadText: null); var result2 = new FileUploadImplementation(context).GetHtml(name: null, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: true, addText: null, uploadText: null); var result3 = new FileUploadImplementation(context).GetHtml(name: null, initialNumberOfFiles: 1, allowMoreFilesToBeAdded: false, includeFormTag: true, addText: null, uploadText: null); // Assert Assert.AreEqual(expectedResult1, result1.ToString()); Assert.AreEqual(expectedResult2, result2.ToString()); Assert.AreEqual(expectedResult3, result3.ToString()); }