public void TestUploadSound_Null() { Initializer.Reset(); StorageService storage = new StorageService(); Assert.IsFalse(storage.UploadSound(_info1, _nullBuffer)); Assert.IsFalse(storage.UploadSound(_info2, _nullBuffer)); Assert.IsTrue(storage.UploadSound(_info1, _emptyBuffer)); Assert.IsFalse(storage.UploadSound(_info1, _nullBuffer)); }
public HttpResponseMessage PostSound([FromUri] string id, [FromUri] string versionNumber, [FromBody] FileUploadRequest fileRequest) { using (IDatabaseService database = new DatabaseService()) { User user = RequestContext.GetAuthenticatedUser(); Device device = RequestContext.GetDevice(); long indiagramId; long version; if (!long.TryParse(id, out indiagramId) || !long.TryParse(versionNumber, out version)) { return Request.CreateBadRequestResponse(); } if (!database.HasIndiagramVersion(user.Id, version)) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Version not found"); } if (!database.CanPushInVersion(device.UserId, device.Id, version)) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Can not update in this version, version is closed or didn't created by this device"); } IndiagramInfo indiagramInfo = database.GetLastIndiagramInfo(user.Id, indiagramId); if (indiagramInfo == null) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Indiagram not found"); } if (indiagramInfo.Version != version) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Can not modify old indiagram version"); } string filename = fileRequest.Filename; byte[] buffer = fileRequest.Content; IStorageService storageService = new StorageService(); if (!storageService.UploadSound(indiagramInfo, buffer)) { return Request.CreateErrorResponse(HttpStatusCode.Conflict, "Indiagram sound already exists and can't be replaced"); } database.SetIndiagramSound(indiagramInfo, filename, buffer); return Request.CreateEmptyGoodReponse(); } }