<commit_before>﻿using Csla;
using Csla.DataPortalClient;
using Csla.Testing.Business.ReadOnlyTest;
using System;
using Csla.Testing.Business.Security;
using UnitDriven;
using Csla.Testing.Business.EditableRootListTests;

#if NUNIT
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestSetup = NUnit.Framework.SetUpAttribute;
#elif MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

namespace cslalighttest.EditableRootListTests
{
  [TestClass]
  public class EditableRootListTests : TestBase
  {
    [TestMethod]
    public void AddItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
        {
          context.Assert.IsNotNull(e.Object);
          list = e.Object;
          SingleItem item = SingleItem.GetSingleItem();
          list.Add(item);
          context.Assert.AreEqual(3, list.Count, "Count should be 3");
          context.Assert.IsTrue(list[2].IsNew, "Object should be new");
          context.Assert.Success();
        }
        );
      context.Complete();
    }

    [TestMethod]
    public void RemoveNewItem()
    {
      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");

        list.RemoveAt(2);
        context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
        context.Assert.AreEqual(false, ApplicationContext.GlobalContext.ContainsKey("ERLBDeleteSelf"), "Should not have deleted new item");
        context.Assert.IsTrue(item.IsNew, "Object should be new after delete");

        context.Assert.Success();
      }
        );
      context.Complete();


    }

    [TestMethod]
    public void RemoveOldItem()
    {
      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");
        list[0].Saved += (o1, e1) =>
          {
            context.Assert.IsNull(e1.Error);
            context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
            context.Assert.AreEqual("DataPortal_DeleteSelf",
                  ApplicationContext.GlobalContext["ERLBDeleteSelf"]);
            context.Assert.Success();
          };
        list.RemoveAt(0);
       
      }
        );
      context.Complete();
    }

    [TestMethod]
    public void InsertItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");
        list[2].Saved += (o1, e1) =>
        {
          context.Assert.IsNull(e1.Error);
          context.Assert.AreEqual(3, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual("DataPortal_Insert", ApplicationContext.GlobalContext["ERLBInsert"].ToString(), "Object should have been inserted");
          context.Assert.IsFalse(list[2].IsNew, "Object should not be new");
          context.Assert.Success();
        };

        // simulate grid edit
        item = list[2];
        System.Windows.Controls.IEditableObject obj = (System.Windows.Controls.IEditableObject)item;
        obj.BeginEdit();
        item.Name = "test";
        obj.EndEdit();
      }
        );
      context.Complete();

    }

    [TestMethod]
    public void UpdateItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        context.Assert.AreEqual(2, list.Count, "Count should be 2");
        list[0].Saved += (o1, e1) =>
        {
          context.Assert.IsNull(e1.Error);
          context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual("DataPortal_Update", ApplicationContext.GlobalContext["ERLBUpdate"].ToString(), "Object should have been updated");
          context.Assert.IsFalse(list[0].IsDirty, "Object should not be dirty");
          context.Assert.Success();
        };

        // simulate grid edit
        SingleItem item = list[0];
        System.Windows.Controls.IEditableObject obj = (System.Windows.Controls.IEditableObject)item;
        obj.BeginEdit();
        item.Name = "test";
        obj.EndEdit();
      }
        );
      context.Complete();

    }

  }
}<commit_msg>Implement list Saved event for EditableRootListBase, incorporate new event into unit tests. bugid: 54<commit_after>﻿using Csla;
using Csla.DataPortalClient;
using Csla.Testing.Business.ReadOnlyTest;
using System;
using Csla.Testing.Business.Security;
using UnitDriven;
using Csla.Testing.Business.EditableRootListTests;

#if NUNIT
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestSetup = NUnit.Framework.SetUpAttribute;
#elif MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

namespace cslalighttest.EditableRootListTests
{
  [TestClass]
  public class EditableRootListTests : TestBase
  {
    [TestMethod]
    public void AddItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
        {
          context.Assert.IsNotNull(e.Object);
          list = e.Object;
          SingleItem item = SingleItem.GetSingleItem();
          list.Add(item);
          context.Assert.AreEqual(3, list.Count, "Count should be 3");
          context.Assert.IsTrue(list[2].IsNew, "Object should be new");
          context.Assert.Success();
        }
        );
      context.Complete();
    }

    [TestMethod]
    public void RemoveNewItem()
    {
      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");

        list.RemoveAt(2);
        context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
        context.Assert.AreEqual(false, ApplicationContext.GlobalContext.ContainsKey("ERLBDeleteSelf"), "Should not have deleted new item");
        context.Assert.IsTrue(item.IsNew, "Object should be new after delete");

        context.Assert.Success();
      }
        );
      context.Complete();


    }

    [TestMethod]
    public void RemoveNewItemViaListSaved()
    {
      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");
        list.Saved += (o1, e1) =>
        {
          context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual(false, ApplicationContext.GlobalContext.ContainsKey("ERLBDeleteSelf"), "Should not have deleted new item");
          context.Assert.IsTrue(item.IsNew, "Object should be new after delete");

          context.Assert.Success();
        };
        list.RemoveAt(2);

      }
      );
      context.Complete();


    }

    [TestMethod]
    public void RemoveOldItem()
    {
      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");
        list[0].Saved += (o1, e1) =>
          {
            context.Assert.IsNull(e1.Error);
            context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
            context.Assert.AreEqual("DataPortal_DeleteSelf",
                  ApplicationContext.GlobalContext["ERLBDeleteSelf"]);
            context.Assert.Success();
          };
        list.RemoveAt(0);

      }
        );
      context.Complete();
    }

    [TestMethod]
    public void InsertItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        SingleItem item = SingleItem.GetSingleItem();
        list.Add(item);
        context.Assert.AreEqual(3, list.Count, "Count should be 3");
        context.Assert.IsTrue(list[2].IsNew, "Object should be new");
        list[2].Saved += (o1, e1) =>
        {
          context.Assert.IsNull(e1.Error);
          context.Assert.AreEqual(3, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual("DataPortal_Insert", ApplicationContext.GlobalContext["ERLBInsert"].ToString(), "Object should have been inserted");
          context.Assert.IsFalse(list[2].IsNew, "Object should not be new");
          context.Assert.Success();
        };

        // simulate grid edit
        item = list[2];
        System.Windows.Controls.IEditableObject obj = (System.Windows.Controls.IEditableObject)item;
        obj.BeginEdit();
        item.Name = "test";
        obj.EndEdit();
      }
        );
      context.Complete();

    }

    [TestMethod]
    public void UpdateItem()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        context.Assert.AreEqual(2, list.Count, "Count should be 2");
        list[0].Saved += (o1, e1) =>
        {
          context.Assert.IsNull(e1.Error);
          context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual("DataPortal_Update", ApplicationContext.GlobalContext["ERLBUpdate"].ToString(), "Object should have been updated");
          context.Assert.IsFalse(list[0].IsDirty, "Object should not be dirty");
          context.Assert.Success();
        };

        // simulate grid edit
        SingleItem item = list[0];
        System.Windows.Controls.IEditableObject obj = (System.Windows.Controls.IEditableObject)item;
        obj.BeginEdit();
        item.Name = "test";
        obj.EndEdit();
      }
        );
      context.Complete();

    }

    [TestMethod]
    public void UpdateItemViaListSavedEvent()
    {

      UnitTestContext context = GetContext();
      DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
      WcfProxy.DefaultUrl = cslalighttest.Properties.Resources.RemotePortalUrl;
      ApplicationContext.GlobalContext.Clear();

      RootSingleItemsList list;
      RootSingleItemsList.GetRootSingleItemsList(1, 2, (o, e) =>
      {
        context.Assert.IsNotNull(e.Object);
        list = e.Object;
        context.Assert.AreEqual(2, list.Count, "Count should be 2");
        list.Saved += (o1, e1) =>
        {
          context.Assert.IsNull(e1.Error);
          context.Assert.AreEqual(2, list.Count, "Incorrect count after remove");
          context.Assert.AreEqual("DataPortal_Update", ApplicationContext.GlobalContext["ERLBUpdate"].ToString(), "Object should have been updated");
          context.Assert.IsFalse(list[0].IsDirty, "Object should not be dirty");
          context.Assert.Success();
        };

        // simulate grid edit
        SingleItem item = list[0];
        System.Windows.Controls.IEditableObject obj = (System.Windows.Controls.IEditableObject)item;
        obj.BeginEdit();
        item.Name = "test";
        obj.EndEdit();
      }
        );
      context.Complete();

    }

  }
}
{'fraction_non_alphanumeric': 0.11627607519958795, 'fraction_numerical': 0.007275302601081638, 'mean_word_length': 2.8145874263261295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2658047', 'n_tokens_mistral': 4607, 'n_tokens_neox': 4514, 'n_words': 817}