public void Should_Return_Validation_Error_When_Invalid_Data_Given() { // Checked in the Request Validation: applicationSettingsMock.Expect(x => x.MaxFileSizeForUpload) .Repeat.Any() .Return(FileSize.Create(2, FileSize.Unit.Megabyte)); // Pass the Bootstrapper with Mocks into the Testing Browser: var browser = new Browser(bootstrapper); // Define the When Action: var result = browser.Post("/file/upload", with => { with.Header("Accept", "application/json"); with.HttpRequest(); }); // Check the Results: Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); // Deserialize the Error: var error = new JsonSerializer().Deserialize <ServiceErrorModel>(result); Assert.AreEqual(ServiceErrorEnum.ValidationError, error.Code); Assert.AreEqual("Validation failed for Request Parameters: (Parameter = Title, Errors = ('Title' must not be empty.), Parameter = Tags, Errors = (Length of the array is not between 1 and 5.), Parameter = File, Errors = ('File' must not be empty.))", error.Details); }
public void Stores_File_Correctly_When_Correct_Data_Given() { rootPathProviderMock.Expect(x => x.GetRootPath()) .Repeat.Once() .Return(GetBasePath()); applicationSettingsMock.Expect(x => x.FileUploadDirectory) .Repeat.Once() .Return(string.Empty); var fileName = "person.txt"; var fileContent = new StringBuilder() .AppendLine("FirstName;LastName;BirthDate") .AppendLine("Philipp;Wagner;1986/05/12") .AppendLine("Max;Mustermann;2014/01/01"); Assert.AreEqual(true, Create(fileName, fileContent.ToString())); using (var fileReader = new FileStream(GetAbsolutePath(fileName), FileMode.Open)) { var fileUploadResult = handler.HandleUpload(fileName, fileReader).Result; Assert.AreEqual(true, Exists(fileUploadResult.Identifier)); Assert.AreEqual(true, Delete(fileUploadResult.Identifier)); } Assert.AreEqual(true, Delete(fileName)); }