public void BlobRetrieveByKeyAndOwner() { Guid ownerId = Guid.NewGuid(); IBlob blob = new Blob(); blob.OwnerUserId = ownerId; Guid trustedId1 = Guid.NewGuid(); Guid trustedId2 = Guid.NewGuid(); Guid trustedId3 = Guid.NewGuid(); blob.TrustedUserIds.Add(trustedId1); blob.TrustedUserIds.Add(trustedId2); blob.TrustedUserIds.Add(trustedId3); string key1 = "key1"; string value1 = "value1"; blob.Info.Add(key1, value1); var newBlob = _provider.BlobCreate(blob); Assert.IsNotNull(newBlob); Assert.IsTrue(newBlob.Id != Guid.Empty); var blobs = _provider.BlobRetrieveByList(b => (b.OwnerUserId == ownerId || b.TrustedUserIds.Contains(ownerId)) && b.Info.ContainsKey(key1)); Assert.IsTrue(blobs.Any()); blobs = _provider.BlobRetrieveByList(b => (b.OwnerUserId == ownerId || b.TrustedUserIds.Contains(ownerId)) && (b.Info.ContainsKey(key1) && b.Info.ContainsValue(value1))); Assert.IsTrue(blobs.Any()); }
public void BlobCollectionCrud() { IBlob blob = new Blob(); blob.OwnerUserId = Guid.NewGuid(); for (int i = 0; i < 100; i++) { blob.Info.Add("test" + i, "val" + i); } Guid trustedUser = Guid.NewGuid(); blob.TrustedUserIds.Add(trustedUser); var newBlob = _provider.BlobCreate(blob); Assert.IsNotNull(newBlob, "Created blob was null"); Assert.IsTrue(newBlob.Id != Guid.Empty, "Blob.Id was not returned after create."); var blobs = _provider.BlobRetrieveByList(b => (b.OwnerUserId == trustedUser || b.TrustedUserIds.Exists(u => u == trustedUser))); Assert.IsTrue(blobs.Any()); var rBlob = _provider.BlobRetrieve(newBlob.Id); Assert.IsNotNull(rBlob, "Retrieved blob was null."); Assert.AreEqual(rBlob.Id, newBlob.Id); Assert.AreEqual(blob.OwnerUserId, rBlob.OwnerUserId); Assert.AreEqual(blob.Info.Count, rBlob.Info.Count); foreach (var pair in rBlob.Info) { Assert.AreEqual(rBlob.Info[pair.Key], pair.Value); } for (int i = 101; i < 201; i++) { rBlob.Info.Add("test" + i, "val" + i); } bool success = _provider.BlobUpdate(rBlob); Assert.IsTrue(success, "Could not update blob."); var updatedBlob = _provider.BlobRetrieve(rBlob.Id); Assert.AreEqual(rBlob.Id, updatedBlob.Id); Assert.AreEqual(rBlob.OwnerUserId, updatedBlob.OwnerUserId); foreach (var pair in updatedBlob.Info) { Assert.AreEqual(rBlob.Info[pair.Key], pair.Value); } Assert.IsTrue(_provider.BlobDelete(updatedBlob), "Blob could not be deleted"); var deletedBlob = _provider.BlobRetrieve(updatedBlob.Id); Assert.IsNull(deletedBlob, "Blob was not deleted."); }
public void FullUsageTest() { IUser user1 = new User(); user1.Username = "******"; var createdUser = _provider.UserCreate(user1); Assert.IsNotNull(createdUser); IUser user2 = new User(); user2.Username = "******"; var secondUser = _provider.UserCreate(user2); Assert.IsNotNull(secondUser); IContainer container = new Container(); container.Name = "TestContainer"; container.OwnerUserId = createdUser.Id; var createdContainer = _provider.ContainerCreate(container); Assert.IsNotNull(createdContainer); IBlob blob = new Blob(); blob.OwnerUserId = createdUser.Id; var createdBlob = _provider.BlobCreate(blob); Assert.IsNotNull(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.IsTrue(blobUpdateSuccess); //} createdContainer.BlobIds = new List<Guid>(); createdContainer.BlobIds.Add(createdBlob.Id); var updatedContainer = _provider.ContainerUpdate(createdContainer); Assert.IsTrue(updatedContainer); IBlob keyBlob = new Blob(); keyBlob.OwnerUserId = secondUser.Id; var createdKeyBlob = _provider.BlobCreate(keyBlob); Assert.IsNotNull(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.IsTrue(blobUpdateSuccess); //} ITransfer transfer = new Transfer(); transfer.TargetBlobId = createdBlob.Id; transfer.KeyId = createdKeyBlob.Id; transfer.TargetUserId = secondUser.Id; var createdTransfer = _provider.TransferCreate(transfer); Assert.IsNotNull(createdTransfer); IContainer secondUserContainer = new Container(); secondUserContainer.Name = "SecondUserContainer"; secondUserContainer.OwnerUserId = secondUser.Id; var secondUserCreatedContainer = _provider.ContainerCreate(secondUserContainer); Assert.IsNotNull(secondUserCreatedContainer); if (secondUserCreatedContainer.BlobIds == null) secondUserCreatedContainer.BlobIds = new List<Guid>(); var transfers = _provider.TransferRetrieveByList(t => t.TargetUserId == secondUser.Id && !t.Complete); Assert.IsNotNull(transfers); Assert.IsTrue(transfers.Any()); foreach (ITransfer trans in transfers) { if (!trans.KeyId.Equals(Guid.Empty)) { IKey transKey = _provider.KeyRetrieve(trans.KeyId); Assert.IsNotNull(transKey); //Assert.IsNotNull(transKey.KeyData); //Add to keyring } secondUserCreatedContainer.BlobIds.Add(trans.TargetBlobId); trans.Complete = true; var updatedTrans = _provider.TransferUpdate(trans); Assert.IsTrue(updatedTrans); } var updatedSecondUserContainer = _provider.ContainerUpdate(secondUserCreatedContainer); Assert.IsTrue(updatedSecondUserContainer); }
public void BlobRetrieveByTrustedUser() { Guid ownerId = Guid.NewGuid(); IBlob blob = new Blob(); blob.OwnerUserId = ownerId; Guid trustedId1 = Guid.NewGuid(); Guid trustedId2 = Guid.NewGuid(); Guid trustedId3 = Guid.NewGuid(); blob.TrustedUserIds.Add(trustedId1); blob.TrustedUserIds.Add(trustedId2); blob.TrustedUserIds.Add(trustedId3); var newBlob = _provider.BlobCreate(blob); Assert.IsNotNull(newBlob); Assert.IsTrue(newBlob.Id != Guid.Empty); var blobs = _provider.BlobRetrieveByList(b => b.OwnerUserId == trustedId1 || b.TrustedUserIds.Contains(trustedId1)); Assert.IsTrue(blobs.Any()); blobs = _provider.BlobRetrieveByList(b => b.OwnerUserId == trustedId2 || b.TrustedUserIds.Contains(trustedId2)); Assert.IsTrue(blobs.Any()); blobs = _provider.BlobRetrieveByList(b => b.OwnerUserId == trustedId3 || b.TrustedUserIds.Contains(trustedId3)); Assert.IsTrue(blobs.Any()); }
public void BlobRetrieveByOwner() { Guid ownerId = Guid.NewGuid(); IBlob blob = new Blob(); blob.OwnerUserId = ownerId; var newBlob = _provider.BlobCreate(blob); Assert.IsNotNull(newBlob); Assert.IsTrue(newBlob.Id != Guid.Empty); var blobs = _provider.BlobRetrieveByList(b => b.OwnerUserId == ownerId); Assert.IsTrue(blobs.Any()); }
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.IsNotNull(newBlob, "Created blob was null"); Assert.IsTrue(newBlob.Id != Guid.Empty, "Blob.Id was not returned after create."); var worked = _provider.BlobUpdateStream(newBlob, stream); Assert.IsTrue(worked); var rBlob = _provider.BlobRetrieve(newBlob.Id); var rStream = _provider.BlobRetrieveStream(rBlob); Assert.IsNotNull(rBlob, "Retrieved blob was null."); Assert.AreEqual(rBlob.Id, newBlob.Id); Assert.AreEqual(blob.KeyId, rBlob.KeyId); Assert.AreEqual(blob.OwnerUserId, rBlob.OwnerUserId); String actualText; using (var sr = new StreamReader(rStream)) { actualText = sr.ReadToEnd(); } Assert.AreEqual(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.IsTrue(success, "Could not update blob."); bool streamSuccess = _provider.BlobUpdateStream(rBlob, rStream); Assert.IsTrue(streamSuccess, "Could not update blob stream."); var updatedBlob = _provider.BlobRetrieve(rBlob.Id); var updatedStream = _provider.BlobRetrieveStream(updatedBlob); Assert.AreEqual(rBlob.Id, updatedBlob.Id); Assert.AreEqual(rBlob.KeyId, updatedBlob.KeyId); Assert.AreEqual(rBlob.OwnerUserId, updatedBlob.OwnerUserId); String actualText2; using (var sr = new StreamReader(updatedStream)) { actualText2 = sr.ReadToEnd(); } Assert.AreEqual(expectedText2, actualText2); Assert.IsTrue(_provider.BlobDelete(updatedBlob), "Blob could not be deleted"); var deletedBlob = _provider.BlobRetrieve(updatedBlob.Id); Assert.IsNull(deletedBlob, "Blob was not deleted."); }