<commit_before>﻿// Copyright (c) 2011 - <NAME> & <NAME>
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

using System.Collections.Generic;
using CorrugatedIron.Models;
using CorrugatedIron.Models.MapReduce;
using CorrugatedIron.Tests.Extensions;
using CorrugatedIron.Tests.Live.LiveRiakConnectionTests;
using CorrugatedIron.Util;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading;

namespace CorrugatedIron.Tests.Live.GeneralIntegrationTests
{
    [TestFixture]
    public class WhenTalkingToRiak : LiveRiakConnectionTestBase
    {
        [Test]
        public void ServerInfoIsSuccessfullyExtracted()
        {
            var result = Client.GetServerInfo();
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void ServerInfoIsSuccessfullyExtractedAsynchronously()
        {
            var result = Client.Async.GetServerInfo().Result;
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void PingRequstResultsInPingResponse()
        {
            var result = Client.Ping();
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void ReadingMissingValueDoesntBreak()
        {
            var readResult = Client.Get("nobucket", "novalue");
            readResult.IsSuccess.ShouldBeFalse(readResult.ErrorMessage);
            readResult.ResultCode.ShouldEqual(ResultCode.NotFound);
        }

        [Test]
        public void GetsWithBucketAndKeyReturnObjectsThatAreMarkedAsNotChanged()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);
            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var readResult = Client.Get(TestBucket, TestKey);
            readResult.IsSuccess.ShouldBeTrue();
            readResult.Value.ShouldNotBeNull();
            readResult.Value.HasChanged.ShouldBeFalse();
        }

        [Test]
        public void GetWithInvalidBucketReturnsInvalidRequest()
        {
            var getResult = Client.Get("", "key");
            getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
            // TODO: confirm that this is an invalid behavior and either trap or submit a Riak bug
            //getResult = Client.Get(null, "key");
            //getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
        }

        [Test]
        public void GetWithInvalidKeyReturnsInvalidRequest()
        {
            var getResult = Client.Get("bucket", "");
            getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
        }

        [Test]
        public void MultiGetWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var getResults = Client.Get(new List<RiakObjectId>
            {
                new RiakObjectId(null, "key"),
                new RiakObjectId("", "key"),
                new RiakObjectId("  ", "key"),
                new RiakObjectId("foo/bar", "key"),
                new RiakObjectId(TestBucket, TestKey)
            }).ToList();

            getResults.Count(r => r.IsSuccess).ShouldEqual(1);
        }

        [Test]
        public void MultiPutWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var putResults = Client.Put(new List<RiakObject>
            {
                new RiakObject(null, "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("  ", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("foo/bar", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson)
            }).ToList();

            putResults.Count(r => r.IsSuccess).ShouldEqual(1);
        }

        [Test]
        public void MultiDeleteWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var deleteResults = Client.Delete(new List<RiakObjectId>
            {
                new RiakObjectId(null, "key"),
                new RiakObjectId("", "key"),<commit_msg>Missed a file for previous commit.<commit_after>﻿// Copyright (c) 2011 - <NAME> & <NAME>
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

using System.Collections.Generic;
using CorrugatedIron.Models;
using CorrugatedIron.Models.MapReduce;
using CorrugatedIron.Tests.Extensions;
using CorrugatedIron.Tests.Live.LiveRiakConnectionTests;
using CorrugatedIron.Util;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading;

namespace CorrugatedIron.Tests.Live.GeneralIntegrationTests
{
    [TestFixture]
    public class WhenTalkingToRiak : LiveRiakConnectionTestBase
    {
        [Test]
        public void ServerInfoIsSuccessfullyExtracted()
        {
            var result = Client.GetServerInfo();
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void ServerInfoIsSuccessfullyExtractedAsynchronously()
        {
            var result = Client.Async.GetServerInfo().Result;
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void PingRequstResultsInPingResponse()
        {
            var result = Client.Ping();
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
        }

        [Test]
        public void ReadingMissingValueDoesntBreak()
        {
            var readResult = Client.Get("nobucket", "novalue");
            readResult.IsSuccess.ShouldBeFalse(readResult.ErrorMessage);
            readResult.ResultCode.ShouldEqual(ResultCode.NotFound);
        }

        [Test]
        public void GetsWithBucketAndKeyReturnObjectsThatAreMarkedAsNotChanged()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);
            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var readResult = Client.Get(TestBucket, TestKey);
            readResult.IsSuccess.ShouldBeTrue();
            readResult.Value.ShouldNotBeNull();
            readResult.Value.HasChanged.ShouldBeFalse();
        }

        [Test]
        public void GetWithInvalidBucketReturnsInvalidRequest()
        {
            var getResult = Client.Get("", "key");
            getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
            // TODO: confirm that this is an invalid behavior and either trap or submit a Riak bug
            //getResult = Client.Get(null, "key");
            //getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
        }

        [Test]
        public void GetWithInvalidKeyReturnsInvalidRequest()
        {
            var getResult = Client.Get("bucket", "");
            getResult.ResultCode.ShouldEqual(ResultCode.InvalidRequest);
        }

        [Test]
        public void MultiGetWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var getResults = Client.Get(new List<RiakObjectId>
            {
                new RiakObjectId(null, "key"),
                new RiakObjectId("", "key"),
                new RiakObjectId("  ", "key"),
                new RiakObjectId("foo/bar", "key"),
                new RiakObjectId(TestBucket, TestKey)
            }).ToList();

            getResults.Count(r => r.IsSuccess).ShouldEqual(1);
        }

        [Test]
        public void MultiPutWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var putResults = Client.Put(new List<RiakObject>
            {
                new RiakObject((string)null, "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("  ", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject("foo/bar", "key", TestJson, RiakConstants.ContentTypes.ApplicationJson),
                new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson)
            }).ToList();

            putResults.Count(r => r.IsSuccess).ShouldEqual(1);
        }

        [Test]
        public void MultiDeleteWithValidAndInvalidBucketsBehavesCorrectly()
        {
            var doc = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var writeResult = Client.Put(doc);

            writeResult.IsSuccess.ShouldBeTrue();
            writeResult.Value.ShouldNotBeNull();

            var deleteResults = Client.Delete(new List<RiakObjectId>
            {
                new RiakObjectId(null, "key"),
                new RiakObjectId("", "key"),
{'fraction_non_alphanumeric': 0.09496517061987479, 'fraction_numerical': 0.0017635129177321223, 'mean_word_length': 2.4526636225266363, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136290', 'n_tokens_mistral': 3073, 'n_tokens_neox': 2936, 'n_words': 648}