<commit_before>﻿//
//  ReplicationTest.cs
//
//  Author:
//  	<NAME>  <<EMAIL>>
//
//  Copyright (c) 2017 Couchbase, Inc All rights reserved.
//
//  Licensed 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;
using System.Collections.Generic;
using System.Text;
using Couchbase.Lite;
using Couchbase.Lite.Logging;
using Couchbase.Lite.Sync;
using FluentAssertions;
using LiteCore;
using LiteCore.Interop;
#if !WINDOWS_UWP
using Xunit;
using Xunit.Abstractions;
#else
using Fact = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif

namespace Test
{
#if WINDOWS_UWP
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
#endif
    public sealed class ReplicationTest : TestCase
    {
        private Database _otherDB;
        private Replicator _repl;
        private bool _stopped;
        private WaitAssert _waitAssert;

#if !WINDOWS_UWP
        public ReplicationTest(ITestOutputHelper output) : base(output)
#else
        public ReplicationTest()
#endif
        {
            _otherDB = OpenDB("otherdb");
        }

        [Fact]
        public void TestBadUrl()
        {
            var config = CreateConfig(false, true, new Uri("blxp://localhost/db"));
            RunReplication(config, 15, C4ErrorDomain.LiteCoreDomain);
        }

        [Fact]
        public void TestEmptyPush()
        {
            var config = CreateConfig(true, false);
            RunReplication(config, 0, 0);
        }

        [Fact]
        public void TestLocalPush()
        {
            Db.InBatch(() =>
            {
                for (int i = 0; i < 100; i++) {
                    var doc = new Document();
                    Db.Save(doc);
                }
            });

            var config = CreateConfig(true, false);
            RunReplication(config, 0, 0);
        }

        // The below tests are disabled because they require orchestration and should be moved
        // to the functional test suite
        //[Fact] 
        public void TestAuthenticationFailure()<commit_msg>Added test for LiteCore issue 156<commit_after>﻿//
//  ReplicationTest.cs
//
//  Author:
//  	<NAME>  <<EMAIL>>
//
//  Copyright (c) 2017 Couchbase, Inc All rights reserved.
//
//  Licensed 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;
using System.Collections.Generic;
using System.Text;
using Couchbase.Lite;
using Couchbase.Lite.Logging;
using Couchbase.Lite.Sync;
using FluentAssertions;
using LiteCore;
using LiteCore.Interop;
#if !WINDOWS_UWP
using Xunit;
using Xunit.Abstractions;
#else
using Fact = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif

namespace Test
{
#if WINDOWS_UWP
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
#endif
    public sealed class ReplicationTest : TestCase
    {
        private Database _otherDB;
        private Replicator _repl;
        private bool _stopped;
        private WaitAssert _waitAssert;

#if !WINDOWS_UWP
        public ReplicationTest(ITestOutputHelper output) : base(output)
#else
        public ReplicationTest()
#endif
        {
            _otherDB = OpenDB("otherdb");
        }

        [Fact]
        public void TestBadUrl()
        {
            var config = CreateConfig(false, true, new Uri("blxp://localhost/db"));
            RunReplication(config, 15, C4ErrorDomain.LiteCoreDomain);
        }

        [Fact]
        public void TestEmptyPush()
        {
            var config = CreateConfig(true, false);
            RunReplication(config, 0, 0);
        }

        [Fact]
        public void TestLocalPush()
        {
            Db.InBatch(() =>
            {
                for (int i = 0; i < 100; i++) {
                    var doc = new Document();
                    Db.Save(doc);
                }
            });

            var config = CreateConfig(true, false);
            RunReplication(config, 0, 0);
        }

        [Fact]
        public void TestPullDoc()
        {
            // For https://github.com/couchbase/couchbase-lite-core/issues/156
            var doc1 = new Document("doc1");
            doc1.Set("name", "Tiger");
            Db.Save(doc1);
            Db.Count.Should().Be(1, "because only one document was saved so far");

            var doc2 = new Document("doc2");
            doc2.Set("name", "Cat");
            _otherDB.Save(doc2);

            var config = CreateConfig(false, true);
            RunReplication(config, 0, 0);

            Db.Count.Should().Be(2, "because the replicator should have pulled doc2 from the other DB");
            doc2.GetString("name").Should().Be("Cat");
        }

        // The below tests are disabled because they require orchestration and should be moved
        // to the functional test suite
        //[Fact] 
        public void TestAuthenticationFailure()
{'fraction_non_alphanumeric': 0.10049905351918775, 'fraction_numerical': 0.009981070383754948, 'mean_word_length': 2.2057363485934913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, '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': '3827740', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1607, 'n_words': 503}