<commit_before>﻿// This file is Part of CalDavSynchronizer (http://outlookcaldavsynchronizer.sourceforge.net/)
// Copyright (c) 2015 <NAME>
// Copyright (c) 2015 <NAME>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
// 
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Linq;
using System.Threading.Tasks;
using CalDavSynchronizer.Implementation;
using CalDavSynchronizer.Implementation.ComWrappers;
using CalDavSynchronizer.Implementation.DistributionLists;
using CalDavSynchronizer.IntegrationTests.Infrastructure;
using CalDavSynchronizer.IntegrationTests.TestBase;
using DDay.iCal;
using GenSync.Logging;
using NUnit.Framework;
using Thought.vCards;

namespace CalDavSynchronizer.IntegrationTests
{

  class ContactSynchronizerFixture : ContactSynchronizerFixtureBase
  {
    [Test]
    [Apartment(System.Threading.ApartmentState.STA)]
    public async Task Synchronize_AnyCase_SyncsSogoDistLists()
    {
      var options = GetOptions("IntegrationTests/Contacts/Sogo");
 

      await InitializeFor (options);
      await ClearEventRepositoriesAndCache ();

      await Server.CreateEntity(
        c =>
        {
          c.EmailAddresses.Add(new vCardEmailAddress("<EMAIL>"));
          c.GivenName = "Nihil";
          c.FamilyName = "Baxter";
        });

      var masonId = await Server.CreateEntity (
       c =>
       {
         c.EmailAddresses.Add (new vCardEmailAddress ("<EMAIL>"));
         c.GivenName = "Agent";
         c.FamilyName = "Mason";
       });

      var steinbergId = await Server.CreateEntity (
       c =>
       {
         c.EmailAddresses.Add (new vCardEmailAddress ("<EMAIL>"));
         c.GivenName = "Agent";
         c.FamilyName = "Steinberg";
       });


      await ServerSogoDistListsOrNull.CreateEntity(
        l =>
        {
          l.Name = "Agents";
          l.Members.Add(new KnownDistributionListMember("<EMAIL>", "Mason", masonId.GetServerFileName()));
          l.Members.Add(new KnownDistributionListMember ("<EMAIL>", "Steinberg", steinbergId.GetServerFileName()));
        });
      
      await Synchronizer.Synchronize(NullSynchronizationLogger.Instance);

      var outlookNames = (await Outlook.GetAllEntities()).Select(c => c.Entity.Inner.LastName).ToArray();

      CollectionAssert.AreEquivalent(
        new[] {"Baxter", "Mason", "Steinberg"},
        outlookNames);

      using (var outlookDistList = (await OutlookDistListsOrNull.GetAllEntities()).SingleOrDefault()?.Entity)
      {
        Assert.That(outlookDistList, Is.Not.Null);

        Assert.That(outlookDistList.Inner.DLName, Is.EqualTo("Agents"));

        var outlookMembers = Enumerable
          .Range(1, outlookDistList.Inner.MemberCount)
          .Select(i => outlookDistList.Inner.GetMember(i))
          .ToSafeEnumerable()
          .Select(d => d.Address)
          .ToArray();

        CollectionAssert.AreEquivalent(
          new[] {"<EMAIL>", "<EMAIL>"},
          outlookMembers);

        outlookDistList.Inner.DLName = "All";
        var recipient = Application.Session.CreateRecipient("Baxter");
        Assert.That(recipient.Resolve(), Is.True);
        outlookDistList.Inner.AddMember(recipient);
        outlookDistList.Inner.Save();
      }

      await Synchronizer.Synchronize (NullSynchronizationLogger.Instance);

      var serverDistList = (await ServerSogoDistListsOrNull.GetAllEntities ()).SingleOrDefault ()?.Entity;
      Assert.That (serverDistList, Is.Not.Null);

      Assert.That (serverDistList.Name, Is.EqualTo ("All"));

      CollectionAssert.AreEquivalent (
       new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>" },
       serverDistList.Members.Select(m => m.EmailAddress));

    }


  }


}<commit_msg>Add IntegrationTest<commit_after>﻿// This file is Part of CalDavSynchronizer (http://outlookcaldavsynchronizer.sourceforge.net/)
// Copyright (c) 2015 <NAME>
// Copyright (c) 2015 <NAME>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
// 
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Linq;
using System.Threading.Tasks;
using CalDavSynchronizer.Implementation;
using CalDavSynchronizer.Implementation.ComWrappers;
using CalDavSynchronizer.Implementation.DistributionLists;
using CalDavSynchronizer.IntegrationTests.Infrastructure;
using CalDavSynchronizer.IntegrationTests.TestBase;
using DDay.iCal;
using GenSync.Logging;
using NUnit.Framework;
using Thought.vCards;

namespace CalDavSynchronizer.IntegrationTests
{

  public class ContactSynchronizerFixture : ContactSynchronizerFixtureBase
  {
    [Test]
    [Apartment(System.Threading.ApartmentState.STA)]
    public async Task Synchronize_AnyCase_SyncsSogoDistLists()
    {
      var options = GetOptions("IntegrationTests/Contacts/Sogo");
 

      await InitializeFor (options);
      await ClearEventRepositoriesAndCache ();

      await Server.CreateEntity(
        c =>
        {
          c.EmailAddresses.Add(new vCardEmailAddress("<EMAIL>"));
          c.GivenName = "Nihil";
          c.FamilyName = "Baxter";
        });

      var masonId = await Server.CreateEntity (
       c =>
       {
         c.EmailAddresses.Add (new vCardEmailAddress ("<EMAIL>"));
         c.GivenName = "Agent";
         c.FamilyName = "Mason";
       });

      var steinbergId = await Server.CreateEntity (
       c =>
       {
         c.EmailAddresses.Add (new vCardEmailAddress ("<EMAIL>"));
         c.GivenName = "Agent";
         c.FamilyName = "Steinberg";
       });


      await ServerSogoDistListsOrNull.CreateEntity(
        l =>
        {
          l.Name = "Agents";
          l.Members.Add(new KnownDistributionListMember("<EMAIL>", "Mason", masonId.GetServerFileName()));
          l.Members.Add(new KnownDistributionListMember ("<EMAIL>", "Steinberg", steinbergId.GetServerFileName()));
        });
      
      await Synchronizer.Synchronize(NullSynchronizationLogger.Instance);

      var outlookNames = (await Outlook.GetAllEntities()).Select(c => c.Entity.Inner.LastName).ToArray();

      CollectionAssert.AreEquivalent(
        new[] {"Baxter", "Mason", "Steinberg"},
        outlookNames);

      using (var outlookDistList = (await OutlookDistListsOrNull.GetAllEntities()).SingleOrDefault()?.Entity)
      {
        Assert.That(outlookDistList, Is.Not.Null);

        Assert.That(outlookDistList.Inner.DLName, Is.EqualTo("Agents"));

        var outlookMembers = Enumerable
          .Range(1, outlookDistList.Inner.MemberCount)
          .Select(i => outlookDistList.Inner.GetMember(i))
          .ToSafeEnumerable()
          .Select(d => d.Address)
          .ToArray();

        CollectionAssert.AreEquivalent(
          new[] {"<EMAIL>", "<EMAIL>"},
          outlookMembers);

        outlookDistList.Inner.DLName = "All";
        var recipient = Application.Session.CreateRecipient("Baxter");
        Assert.That(recipient.Resolve(), Is.True);
        outlookDistList.Inner.AddMember(recipient);
        outlookDistList.Inner.Save();
      }

      await Synchronizer.Synchronize (NullSynchronizationLogger.Instance);

      var serverDistList = (await ServerSogoDistListsOrNull.GetAllEntities ()).SingleOrDefault ()?.Entity;
      Assert.That (serverDistList, Is.Not.Null);

      Assert.That (serverDistList.Name, Is.EqualTo ("All"));

      CollectionAssert.AreEquivalent (
       new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>" },
       serverDistList.Members.Select(m => m.EmailAddress));

    }

    [Test]
    [Apartment (System.Threading.ApartmentState.STA)]
    public async Task SynchronizeTwoWay_LocalContactChanges_IsSyncedToServerAndPreservesExtendedPropertiesAndUid ()
    {
      var options = GetOptions ("IntegrationTests/Contacts/Sogo");
      await InitializeFor (options);
      await ClearEventRepositoriesAndCache ();

      string initialUid = null;

      await Server.CreateEntity (
      c =>
      {
        c.EmailAddresses.Add (new vCardEmailAddress ("<EMAIL>"));
        c.GivenName = "Nihil";
        c.FamilyName = "Baxter";
        c.OtherProperties.Add (new vCardProperty ("X-CALDAVSYNCHRONIZER-INTEGRATIONTEST", "TheValueBlaBLubb"));
        initialUid = c.UniqueId;
      });

      await Synchronizer.Synchronize (NullSynchronizationLogger.Instance);

      using (var outlookEvent = (await Outlook.GetAllEntities ()).Single ().Entity)
      {
        outlookEvent.Inner.FirstName = "TheNewNihil";
        outlookEvent.Inner.Save ();
      }

      await Synchronizer.Synchronize (NullSynchronizationLogger.Instance);

      var serverContact = (await Server.GetAllEntities ()).Single ().Entity;

      Assert.That (serverContact.GivenName, Is.EqualTo ("TheNewNihil"));
      Assert.That (serverContact.UniqueId, Is.EqualTo (initialUid));

      Assert.That (
        serverContact.OtherProperties.SingleOrDefault (p => p.Name == "X-CALDAVSYNCHRONIZER-INTEGRATIONTEST")?.Value,
        Is.EqualTo ("TheValueBlaBLubb"));
    }
  }


}
{'fraction_non_alphanumeric': 0.11505043443523419, 'fraction_numerical': 0.001997403375611705, 'mean_word_length': 3.1363073110285007, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 48, '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': '6720177', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2876, 'n_words': 636}