Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void ContainerCollectionCrud()
        {
            IContainer container = new Container();
            container.Name = "testContainer";
            container.BlobIds = new List<Guid>();
            container.OwnerUserId = Guid.NewGuid();

            for (int i = 0; i < 10; i++)
            {
                container.BlobIds.Add(Guid.NewGuid());
            }

            var newContainer = _provider.ContainerCreate(container);

            Assert.NotNull(newContainer, "Container should not be null");

            Assert.Equal(container.Name, newContainer.Name);
            Assert.Equal(container.OwnerUserId, newContainer.OwnerUserId);
            Assert.Equal(container.BlobIds.Count, newContainer.BlobIds.Count);

            for (int i = 0; i < container.BlobIds.Count; i++)
            {
                Assert.Equal(container.BlobIds[i], newContainer.BlobIds[i]);
            }

            newContainer.Name = "testContainer2";
            newContainer.OwnerUserId = Guid.NewGuid();

            for (int i = 0; i < 10; i++)
            {
                newContainer.BlobIds.Add(Guid.NewGuid());
            }

            Assert.True(_provider.ContainerUpdate(newContainer));

            container = newContainer;

            newContainer = _provider.ContainerRetrieve(container.Id);

            Assert.NotNull(newContainer);

            Assert.Equal(container.Name, newContainer.Name);
            Assert.Equal(container.OwnerUserId, newContainer.OwnerUserId);
            Assert.Equal(container.BlobIds.Count, newContainer.BlobIds.Count);

            for (int i = 0; i < container.BlobIds.Count; i++)
            {
                Assert.Equal(container.BlobIds[i], newContainer.BlobIds[i]);
            }

            Assert.True(_provider.ContainerDelete(newContainer), "Container could not be deleted");

            var deletedContainer = _provider.ContainerRetrieve(newContainer.Id);

            Assert.Null(deletedContainer);
        }