protected async Task <T> CreateSupportingDocument <T>(string url, string fileName = "file.txt", Guid?documentId = null) { var registerRequest = new SupportingDocumentRegisterRequest { FileName = fileName, FileSize = 1024 }; var registerUploadResult = Deserialize <SupportingDocumentRegisterResult>(await Browser.Post($"{url}/registerUpload", w => { w.User(User); w.JsonBody(registerRequest); }), HttpStatusCode.Created); var completeUploadUrl = documentId.HasValue ? $"{url}/{documentId.Value}/completeUpload" : $"{url}/completeUpload"; var response = Deserialize <T>(await Browser.Post(completeUploadUrl, w => { w.User(User); w.JsonBody(registerUploadResult); }), HttpStatusCode.Created); return(response); }
public async Task RegisterUpload_WhenAmazonS3Url_ShouldReturnIsGDNFalse() { // Arrange const string fileUri = "http://url.com/123123?asd&X-Amz-Signature=234234234234"; var gdamUserId = new string(Enumerable.Repeat('1', 24).ToArray()); var userIdentity = new UserIdentity { Email = "*****@*****.**", GdamUserId = gdamUserId }; var costId = Guid.NewGuid(); var request = new SupportingDocumentRegisterRequest(); _gdamClientMock.Setup(c => c.RegisterFileUpload(gdamUserId, It.IsAny <RegisterFileUploadRequest>())) .ReturnsAsync(new RegisterFileUploadResponse { Files = new[] { new RegisterFileUploadResponse.File { FileUri = fileUri, } } }); // Act var result = await _supportingDocumentsService.RegisterUpload(costId, request, userIdentity); // Assert result.IsGDN.Should().BeFalse(); }
public void When_FileSizeIsEqualToMaximum_Should_BeValid() { // Arrange _appSettings.MaxFileUploadSize = 1;// MB _validator = new SupportingDocumentUploadValidator(_appSettingsOptionsMock.Object); var toValidate = new SupportingDocumentRegisterRequest { FileSize = 1024 * 1024 // Bytes }; // Act var result = _validator.Validate(toValidate); // Assert result.IsValid.Should().BeTrue(); }
public async Task RegisterUpload_WhenValidInput_ShouldRegisterFileInGdam() { // Arrange const string fileName = "Test file.pdf"; var gdamUserId = new string(Enumerable.Repeat('1', 24).ToArray()); var userIdentity = new UserIdentity { Email = "*****@*****.**", GdamUserId = gdamUserId }; var costId = Guid.NewGuid(); var fileSize = 100; var request = new SupportingDocumentRegisterRequest { FileName = fileName, FileSize = fileSize }; _gdamClientMock.Setup(c => c.RegisterFileUpload(gdamUserId, It.IsAny <RegisterFileUploadRequest>())) .ReturnsAsync(new RegisterFileUploadResponse { Files = new[] { new RegisterFileUploadResponse.File { FileId = "234234234", FileUri = "http://url.com/id", } } }); // Act await _supportingDocumentsService.RegisterUpload(costId, request, userIdentity); // Assert _gdamClientMock.Verify(c => c.RegisterFileUpload( gdamUserId, It.Is <RegisterFileUploadRequest>(r => r.Files.Length > 0 && r.Files[0].Size.Equals(fileSize)) ), Times.Once); }
public async Task RegisterUpload_WhenValidInput_ShouldReturnFileUriAndFileIdTakenFromGDN() { // Arrange const string fileName = "Test file.pdf"; const string fileId = "234234234"; const string fileUri = "http://url.com/123123"; var gdamUserId = new string(Enumerable.Repeat('1', 24).ToArray()); var userIdentity = new UserIdentity { Email = "*****@*****.**", GdamUserId = gdamUserId }; var costId = Guid.NewGuid(); var request = new SupportingDocumentRegisterRequest { FileName = fileName }; _gdamClientMock.Setup(c => c.RegisterFileUpload(gdamUserId, It.IsAny <RegisterFileUploadRequest>())) .ReturnsAsync(new RegisterFileUploadResponse { Files = new[] { new RegisterFileUploadResponse.File { FileId = fileId, FileUri = fileUri, } } }); // Act var result = await _supportingDocumentsService.RegisterUpload(costId, request, userIdentity); // Assert result.FileUri.Should().Be(fileUri); result.FileId.Should().Be(fileId); }