コード例 #1
0
ファイル: RedisProviderTest.cs プロジェクト: aluitink/Ojibwe
        public void TransferCollectionCrud()
        {
            ITransfer transfer = new Transfer();
            transfer.TargetUserId = Guid.NewGuid();
            transfer.TargetBlobId = Guid.NewGuid();
            transfer.KeyId = Guid.NewGuid();

            var newTransfer = _provider.TransferCreate(transfer);

            Assert.IsNotNull(newTransfer);

            Assert.AreEqual(transfer.KeyId, newTransfer.KeyId);
            Assert.AreEqual(transfer.TargetBlobId, newTransfer.TargetBlobId);
            Assert.AreEqual(transfer.TargetUserId, newTransfer.TargetUserId);

            newTransfer.TargetUserId = Guid.NewGuid();
            newTransfer.TargetBlobId = Guid.NewGuid();
            newTransfer.KeyId = Guid.NewGuid();

            Assert.IsTrue(_provider.TransferUpdate(newTransfer));

            transfer = newTransfer;

            newTransfer = _provider.TransferRetrieve(transfer.Id);

            Assert.AreEqual(transfer.KeyId, newTransfer.KeyId);
            Assert.AreEqual(transfer.TargetBlobId, newTransfer.TargetBlobId);
            Assert.AreEqual(transfer.TargetUserId, newTransfer.TargetUserId);

            Assert.IsTrue(_provider.TransferDelete(newTransfer), "Transfer could not be deleted");

            var t = _provider.TransferRetrieve(newTransfer.Id);

            Assert.IsNull(t);
        }
コード例 #2
0
ファイル: RedisProviderTest.cs プロジェクト: aluitink/Ojibwe
        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);
        }