public void BlobCollectionCrud() { IBlob blob = new Blob(); blob.KeyId = Guid.NewGuid(); blob.OwnerUserId = Guid.NewGuid(); var stream = new MemoryStream(); string expectedText = "Look at this line!"; using (var sw = new StreamWriter(stream, Encoding.Default, 1024, true)) { sw.Write(expectedText); } var newBlob = _provider.BlobCreate(blob); Assert.NotNull(newBlob, "Created blob was null"); Assert.True(newBlob.Id != Guid.Empty, "Blob.Id was not returned after create."); var worked = _provider.BlobUpdateStream(newBlob, stream); Assert.True(worked); var rBlob = _provider.BlobRetrieve(newBlob.Id); var rStream = _provider.BlobRetrieveStream(rBlob); Assert.NotNull(rBlob, "Retrieved blob was null."); Assert.Equal(rBlob.Id, newBlob.Id); Assert.Equal(blob.KeyId, rBlob.KeyId); Assert.Equal(blob.OwnerUserId, rBlob.OwnerUserId); String actualText; using (var sr = new StreamReader(rStream)) { actualText = sr.ReadToEnd(); } Assert.Equal(expectedText, actualText); string expectedText2 = "This is a longer string"; rStream = new MemoryStream(); using (var sw = new StreamWriter(rStream, Encoding.Default, 1024, true)) { sw.Write(expectedText2); } bool success = _provider.BlobUpdate(rBlob); Assert.True(success, "Could not update blob."); bool streamSuccess = _provider.BlobUpdateStream(rBlob, rStream); Assert.True(streamSuccess, "Could not update blob stream."); var updatedBlob = _provider.BlobRetrieve(rBlob.Id); var updatedStream = _provider.BlobRetrieveStream(updatedBlob); Assert.Equal(rBlob.Id, updatedBlob.Id); Assert.Equal(rBlob.KeyId, updatedBlob.KeyId); Assert.Equal(rBlob.OwnerUserId, updatedBlob.OwnerUserId); String actualText2; using (var sr = new StreamReader(updatedStream)) { actualText2 = sr.ReadToEnd(); } Assert.Equal(expectedText2, actualText2); Assert.True(_provider.BlobDelete(updatedBlob), "Blob could not be deleted"); var deletedBlob = _provider.BlobRetrieve(updatedBlob.Id); Assert.Null(deletedBlob, "Blob was not deleted."); }
public void FullUsageTest() { IUser user1 = new User(); user1.Username = "******"; var createdUser = _provider.UserCreate(user1); Assert.NotNull(createdUser); IUser user2 = new User(); user2.Username = "******"; var secondUser = _provider.UserCreate(user2); Assert.NotNull(secondUser); IContainer container = new Container(); container.Name = "TestContainer"; container.OwnerUserId = createdUser.Id; var createdContainer = _provider.ContainerCreate(container); Assert.NotNull(createdContainer); IBlob blob = new Blob(); blob.OwnerUserId = createdUser.Id; var createdBlob = _provider.BlobCreate(blob); Assert.NotNull(createdBlob); MemoryStream stream = new MemoryStream(); using (StreamWriter sw = new StreamWriter(stream)) { sw.Write("This is a test blob"); sw.Flush(); var blobUpdateSuccess = _provider.BlobUpdateStream(createdBlob, stream); Assert.True(blobUpdateSuccess); } createdContainer.BlobIds = new List<Guid>(); createdContainer.BlobIds.Add(createdBlob.Id); var updatedContainer = _provider.ContainerUpdate(createdContainer); Assert.True(updatedContainer); IBlob keyBlob = new Blob(); keyBlob.OwnerUserId = secondUser.Id; var createdKeyBlob = _provider.BlobCreate(keyBlob); Assert.NotNull(createdKeyBlob); MemoryStream keyStream = new MemoryStream(); using (StreamWriter sw = new StreamWriter(keyStream)) { sw.Write("Is this the key?!!!"); sw.Flush(); var blobUpdateSuccess = _provider.BlobUpdateStream(createdKeyBlob, keyStream); Assert.True(blobUpdateSuccess); } ITransfer transfer = new Transfer(); transfer.TargetBlobId = createdBlob.Id; transfer.KeyBlobId = createdKeyBlob.Id; transfer.TargetUserId = secondUser.Id; var createdTransfer = _provider.TransferCreate(transfer); Assert.NotNull(createdTransfer); IContainer secondUserContainer = new Container(); secondUserContainer.Name = "SecondUserContainer"; secondUserContainer.OwnerUserId = secondUser.Id; var secondUserCreatedContainer = _provider.ContainerCreate(secondUserContainer); Assert.NotNull(secondUserCreatedContainer); if (secondUserCreatedContainer.BlobIds == null) secondUserCreatedContainer.BlobIds = new List<Guid>(); var transfers = _provider.TransferRetrieveByList(t => t.TargetUserId == secondUser.Id && !t.Complete); Assert.NotNull(transfers); Assert.True(transfers.Any()); foreach (ITransfer trans in transfers) { if (!trans.KeyBlobId.Equals(Guid.Empty)) { IBlob transKeyBlob = _provider.BlobRetrieve(trans.KeyBlobId); Assert.NotNull(transKeyBlob); Stream transKeyStream = _provider.BlobRetrieveStream(transKeyBlob); Assert.NotNull(transKeyStream); //Add to keyring } secondUserCreatedContainer.BlobIds.Add(trans.TargetBlobId); trans.Complete = true; var updatedTrans = _provider.TransferUpdate(trans); Assert.True(updatedTrans); } var updatedSecondUserContainer = _provider.ContainerUpdate(secondUserCreatedContainer); Assert.True(updatedSecondUserContainer); }