public async void SupportsCustomSerialization()
    {
        var client         = new Client(application, CustomSerializer.Create());
        var collectionName = Path.GetRandomFileName();
        var collection     = client.GetCollection(collectionName);
        var key            = Guid.NewGuid().ToString();

        try
        {
            await collection.AddOrUpdateAsync(key, new Product { Category = ProductCategory.Sprocket, Id = 1 });

            await SearchHelper.WaitForConsistency(collection, "*", 1);

            var searchResult = await collection.SearchAsync <JObject>("value.id: 1");

            Assert.Collection(searchResult.Items,
                              result =>
            {
                Assert.Equal(key, result.PathMetadata.Key);
                Assert.Equal(ProductCategory.Sprocket.ToString(), result.Value.Value <string>("category"));
            }
                              );

            Assert.Equal(1, searchResult.TotalCount);
        }
        finally
        {
            await client.DeleteCollectionAsync(collectionName);
        }
    }
    public async void SupportsCustomSerialization()
    {
        var client            = new Client(application, CustomSerializer.Create());
        var productsName      = Path.GetRandomFileName();
        var usersName         = Path.GetRandomFileName();
        var productCollection = client.GetCollection(productsName);
        var userCollection    = client.GetCollection(usersName);

        var productKey = Guid.NewGuid().ToString();
        var userKey    = Guid.NewGuid().ToString();

        await productCollection.AddOrUpdateAsync(productKey, new Product { Id = 1, Category = ProductCategory.Sprocket });

        await userCollection.AddOrUpdateAsync(userKey, new User()
        {
            Id = 1, Name = "Wayne Gretzky"
        });

        GraphNode fromNode = new GraphNode {
            CollectionName = usersName, Key = userKey
        };
        GraphNode toNode = new GraphNode {
            CollectionName = productsName, Key = productKey
        };

        try
        {
            await client.LinkAsync(fromNode, "purchased", toNode);

            var retrievedProducts = await userCollection.GetLinkAsync <Product>(userKey, "purchased");

            Assert.Equal(1, retrievedProducts.Count);
            Assert.Equal(ProductCategory.Sprocket, retrievedProducts.Items[0].Value.Category);
        }
        finally
        {
            await client.UnlinkAsync(fromNode, "purchased", toNode);

            await client.DeleteCollectionAsync(productsName);

            await client.DeleteCollectionAsync(usersName);
        }
    }
    public async void SupportsCustomSerialization()
    {
        var client     = new Client(application, CustomSerializer.Create());
        var collection = client.GetCollection(collectionName);
        var item       = new Product {
            Id = 3, Name = "Bread", Description = "Whole Grain Bread", Price = 2.75M, Rating = 3, Category = ProductCategory.Widget
        };
        var key = Guid.NewGuid().ToString();

        var kvMetaData = await collection.AddOrUpdateAsync(key, item);

        Assert.Equal(collectionName, kvMetaData.CollectionName);
        Assert.Equal(key, kvMetaData.Key);
        Assert.True(kvMetaData.VersionReference.Length > 0);

        var kvObject = await collection.GetAsync <JObject>(kvMetaData.Key);

        Assert.Equal(ProductCategory.Widget.ToString(), kvObject.Value["category"].Value <string>());
    }
Beispiel #4
0
    public async void SupportsCustomSerialization()
    {
        var client           = new Client(application, CustomSerializer.Create());
        var collection       = client.GetCollection(collectionName);
        var existingKvObject = await collection.GetAsync <Product>(productKey);

        var product = existingKvObject.Value;

        product.Category = ProductCategory.Widget;

        var kvMetaData = await collection.UpdateAsync(productKey, product);


        Assert.Equal(collectionName, kvMetaData.CollectionName);
        Assert.Equal(productKey, kvMetaData.Key);
        Assert.True(kvMetaData.VersionReference.Length > 0);

        var updatedKvObject = await collection.GetAsync <JObject>(kvMetaData.Key);

        Assert.Equal(ProductCategory.Widget.ToString(), updatedKvObject.Value["category"].Value <string>());
    }
Beispiel #5
0
    public async void SupportsCustomSerializationForProperties()
    {
        var client     = new Client(application, CustomSerializer.Create());
        var collection = client.GetCollection(testFixture.UserCollection.CollectionName);

        GraphNode fromNode = new GraphNode {
            CollectionName = testFixture.UserCollection.CollectionName, Key = testFixture.UserKey
        };
        GraphNode toNode = new GraphNode {
            CollectionName = testFixture.Collection.CollectionName, Key = testFixture.BreadKey
        };

        var properties = new
        {
            category = ProductCategory.Widget
        };

        try
        {
            var kvMetaData = await client.LinkAsync(fromNode, "purchased", toNode, properties);

            Assert.Equal(fromNode.CollectionName, kvMetaData.CollectionName);
            Assert.Equal(fromNode.Key, kvMetaData.Key);
            Assert.True(kvMetaData.VersionReference.Length > 0);
            var location = String.Format("/v0/{0}/{1}/relation/purchased/{2}/{3}",
                                         fromNode.CollectionName,
                                         fromNode.Key,
                                         toNode.CollectionName,
                                         toNode.Key);
            Assert.Equal(location, kvMetaData.Location);

            var kvObject = await collection.GetLinkAsync <JObject>(kvMetaData.Key, "purchased", toNode);

            Assert.Equal(ProductCategory.Widget.ToString(), kvObject.Value <string>("category"));
        }
        finally
        {
            await testFixture.Client.UnlinkAsync(fromNode, "purchased", toNode);
        }
    }
Beispiel #6
0
    public async void SupportsCustomSerialization()
    {
        var client     = new Client(application, CustomSerializer.Create());
        var collection = client.GetCollection(collectionName);

        var productMetaData = await collection.GetAsync <Product>(productKey);

        string dateTime  = DateTime.UtcNow.ToString("s");
        var    mergeItem = new
        {
            origin = Origin.Moon
        };

        var kvMetaData = await collection.MergeAsync(productMetaData.Key, mergeItem);

        Assert.Equal(collectionName, kvMetaData.CollectionName);
        Assert.Contains(kvMetaData.Key, kvMetaData.Location);
        Assert.True(kvMetaData.VersionReference.Length > 0);
        Assert.Contains(kvMetaData.VersionReference, kvMetaData.Location);

        var kvObject = await collection.GetAsync <JObject>(productKey);

        Assert.Equal(Origin.Moon.ToString(), kvObject.Value["origin"].Value <string>());
    }
    public async void SupportsCustomSerialzation()
    {
        var client     = new Client(application, CustomSerializer.Create());
        var collection = client.GetCollection(collectionName);

        string dateTime = DateTime.UtcNow.ToString("s");
        List <PatchOperation> patchOperations = new List <PatchOperation>();

        patchOperations.Add(new PatchOperation <Origin>
        {
            Operation = "add", Path = "/origin", Value = Origin.Moon
        });

        var kvMetaData = await collection.PatchAsync(productKey, patchOperations);

        Assert.Equal(collectionName, kvMetaData.CollectionName);
        Assert.Contains(kvMetaData.Key, kvMetaData.Location);
        Assert.True(kvMetaData.VersionReference.Length > 0);
        Assert.Contains(kvMetaData.VersionReference, kvMetaData.Location);

        var kvObject = await collection.GetAsync <JObject>(productKey);

        Assert.Equal(Origin.Moon.ToString(), kvObject.Value.Value <string>("origin"));
    }