<commit_before>// Copyright Naked Objects Group Ltd, 45 Station Road, Henley on Thames, UK, RG9 1AT
// 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.ComponentModel;
using System.Data.Entity;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NakedObjects.Services;
using NakedObjects.Xat;

namespace NakedObjects.SystemTest.Method {
    [TestClass]
    public class TestRecognisedMethods : AbstractSystemTest<MethodsDbContext> {
        #region Setup/Teardown

        [ClassCleanup]
        public static void ClassCleanup() {
            CleanupNakedObjectsFramework(new TestRecognisedMethods());
            Database.Delete(MethodsDbContext.DatabaseName);
        }

        [TestInitialize()]
        public void TestInitialize() {
            InitializeNakedObjectsFrameworkOnce();
            StartTest();
        }

        #endregion

        #region Configuration
        protected override string[] Namespaces {
            get { return new[] {typeof (Auto1).Namespace}; }
        }

        protected override Type[] Types {
            get {
                return new[] { typeof(Sex) };
            }
        }

        protected override object[] MenuServices {
            get {
                return new object[] {
                    new SimpleRepository<Auto1>(),
                    new SimpleRepository<Auto2>(),
                    new SimpleRepository<Auto3>(),
                    new SimpleRepository<Choices1>(),
                    new SimpleRepository<Choices2>(),
                    new SimpleRepository<Choices3>(),
                    new SimpleRepository<Choices4>(),
                    new SimpleRepository<Clear1>(),
                    new SimpleRepository<Clear2>(),
                    new SimpleRepository<Clear3>(),
                    new SimpleRepository<Created1>(),
                    new SimpleRepository<Created2>(),
                    new SimpleRepository<Default1>(),
                    new SimpleRepository<Default2>(),
                    new SimpleRepository<Default3>(),
                    new SimpleRepository<Default4>(),
                    new SimpleRepository<Deleted1>(),
                    new SimpleRepository<Deleted2>(),
                    new SimpleRepository<Deleting1>(),
                    new SimpleRepository<Deleting2>(),
                    new SimpleRepository<Disable1>(),
                    new SimpleRepository<Disable2>(),
                    new SimpleRepository<Disable3>(),
                    new SimpleRepository<Hide1>(),
                    new SimpleRepository<Hide2>(),
                    new SimpleRepository<Hide3>(),
                    new SimpleRepository<Modify1>(),
                    new SimpleRepository<Modify2>(),
                    new SimpleRepository<Modify3>(),
                    new SimpleRepository<Modify4>(),
                    new SimpleRepository<Persisted1>(),
                    new SimpleRepository<Persisted2>(),
                    new SimpleRepository<Persisting1>(),
                    new SimpleRepository<Persisting2>(),
                    new SimpleRepository<Saved1>(),
                    new SimpleRepository<Title1>(),
                    new SimpleRepository<Title2>(),
                    new SimpleRepository<Title3>(),
                    new SimpleRepository<Title4>(),
                    new SimpleRepository<Title5>(),
                    new SimpleRepository<Title6>(),
                    new SimpleRepository<Title7>(),
                    new SimpleRepository<Title8>(),
                    new SimpleRepository<Title9>(),
                    new SimpleRepository<Title10>(),
                    new SimpleRepository<Updated1>(),
                    new SimpleRepository<Updated2>(),
                    new SimpleRepository<Updating1>(),
                    new SimpleRepository<Updating2>(),
                    new SimpleRepository<Validate1>(),
                    new SimpleRepository<Validate2>(),
                    new SimpleRepository<Validate3>(),
                    new SimpleRepository<Validate4>(),
                    new SimpleRepository<Validate5>()
                };
            }
        }
        #endregion

        #region AutoComplete

        [TestMethod]
        public void RecognisedAutoCompleteMethodDoesNotShowUpAsAction() {
            var obj1 = NewTestObject<Auto1>();
            try {
                var act = obj1.GetAction("Auto Complete Prop2");
                Assert.Fail("Should not get to here!");
            }
            catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete Prop2'", e.Message);
            }
            try {
                var act = obj1.GetAction("Auto Complete Prop3");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete Prop3'", e.Message);
            }

            try {
                obj1.GetAction("Auto Complete0 Do Something");
                Assert.Fail("Should not get to here!");
            }
            catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete0 Do Something'", e.Message);
            }
            try {
                obj1.GetAction("Auto Complete1 Do Something");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete1 Do Something'", e.Message);
            }
            try {
                obj1.GetAction("Auto Complete2 Do Something");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete2 Do Something'", e.Message);
            }
        }

        [TestMethod]
        public void UnmatchedAutoCompleteMethodShowsUpAsAction() {
            ITestObject obj3 = NewTestObject<Auto3>();
            obj3.GetAction("Auto Complete Prop1");
            obj3.GetAction("Auto Complete Prop2");
            obj3.GetAction("Auto Complete Prop3");
            obj3.GetAction("Auto Complete 0 Do Something");
            obj3.GetAction("Auto Complete 1 Do Something");
            obj3.GetAction("Auto Complete 2 Do Somting");
            obj3.GetAction("Auto Complete 3 Do Something");
        }

        private void CreateAuto2(string prop1) {
            var obj2 = NewTestObject<Auto2>();
            obj2.GetPropertyByName("Prop1").SetValue(prop1);
            obj2.Save();
        }

        [TestMethod]
        public virtual void AutoCompleteParameters() {
            CreateAuto2("Bar1");
            CreateAuto2("Bar2");
            CreateAuto2("Bar3");

            var obj1 = NewTestObject<Auto1>();
            var action = obj1.GetAction("Do Something");
            ITestNaked[] cho0 = action.Parameters[0].GetCompletions("any");
            Assert.AreEqual(1, cho0.Count());

            ITestNaked[] cho1 = action.Parameters[1].GetCompletions("any");
            Assert.AreEqual(3, cho1.Count());

            ITestNaked[] cho2 = action.Parameters[2].GetCompletions("bar");
            Assert.AreEqual(2, cho2.Count());
        }

        [TestMethod]
        public virtual void AutoCompleteReferenceProperty() {
            CreateAuto2("Foo1");
            CreateAuto2("Foo2");
            CreateAuto2("Foo3");

            var obj1 = NewTestObject<Auto1>();
            ITestProperty prop = obj1.GetPropertyByName("Prop3");
            ITestNaked[] cho = prop.GetCompletions("foo");
            Assert.AreEqual(3, cho.Count());
            Assert.AreEqual("Foo1", cho[0].Title);
        }

        [TestMethod]
        public virtual void AutoCompleteStringProperty() {
            var obj1 = NewTestObject<Auto1>();
            ITestProperty prop = obj1.GetPropertyByName("Prop2");
            ITestNaked[] cho = prop.GetCompletions("any");
            Assert.AreEqual(3, cho.Count());
            Assert.AreEqual("Fee", cho[0].Title);
        }

        [TestMethod]
        public virtual void AutoCompleteIntProperty() {
            var obj1 = NewTestObject<Auto1>();
            ITestProperty prop = obj1.GetPropertyByName("Prop1");

            try {
                prop.GetCompletions("any");
                Assert.Fail("expect exception");
            }
            catch (Exception) {
                // expected
            }
            obj1.GetAction("Auto Complete Prop1");
        }

        #endregion

        #region Choices

        [TestMethod]
        public void ChoicesMethodDoesNotShowUpAsAction() {
            var obj1 = NewTestObject<Choices1>();
            try {
                obj1.GetAction("Choices Prop1");
                Assert.Fail();
            }
            catch (Exception e) {
                Assert.IsNotNull(e);
            }

            try {
                obj1.GetAction("Choices 0 Do Something");
                Assert.Fail();
            }
            catch (Exception e) {
                Assert.IsNotNull(e);
            }<commit_msg>remove redundant test (from 7.0)<commit_after>// Copyright Naked Objects Group Ltd, 45 Station Road, Henley on Thames, UK, RG9 1AT
// 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.ComponentModel;
using System.Data.Entity;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NakedObjects.Services;
using NakedObjects.Xat;

namespace NakedObjects.SystemTest.Method {
    [TestClass]
    public class TestRecognisedMethods : AbstractSystemTest<MethodsDbContext> {
        #region Setup/Teardown

        [ClassCleanup]
        public static void ClassCleanup() {
            CleanupNakedObjectsFramework(new TestRecognisedMethods());
            Database.Delete(MethodsDbContext.DatabaseName);
        }

        [TestInitialize()]
        public void TestInitialize() {
            InitializeNakedObjectsFrameworkOnce();
            StartTest();
        }

        #endregion

        #region Configuration
        protected override string[] Namespaces {
            get { return new[] {typeof (Auto1).Namespace}; }
        }

        protected override Type[] Types {
            get {
                return new[] { typeof(Sex) };
            }
        }

        protected override object[] MenuServices {
            get {
                return new object[] {
                    new SimpleRepository<Auto1>(),
                    new SimpleRepository<Auto2>(),
                    new SimpleRepository<Auto3>(),
                    new SimpleRepository<Choices1>(),
                    new SimpleRepository<Choices2>(),
                    new SimpleRepository<Choices3>(),
                    new SimpleRepository<Choices4>(),
                    new SimpleRepository<Clear1>(),
                    new SimpleRepository<Clear2>(),
                    new SimpleRepository<Clear3>(),
                    new SimpleRepository<Created1>(),
                    new SimpleRepository<Created2>(),
                    new SimpleRepository<Default1>(),
                    new SimpleRepository<Default2>(),
                    new SimpleRepository<Default3>(),
                    new SimpleRepository<Default4>(),
                    new SimpleRepository<Deleted1>(),
                    new SimpleRepository<Deleted2>(),
                    new SimpleRepository<Deleting1>(),
                    new SimpleRepository<Deleting2>(),
                    new SimpleRepository<Disable1>(),
                    new SimpleRepository<Disable2>(),
                    new SimpleRepository<Disable3>(),
                    new SimpleRepository<Hide1>(),
                    new SimpleRepository<Hide2>(),
                    new SimpleRepository<Hide3>(),
                    new SimpleRepository<Modify1>(),
                    new SimpleRepository<Modify2>(),
                    new SimpleRepository<Modify3>(),
                    new SimpleRepository<Modify4>(),
                    new SimpleRepository<Persisted1>(),
                    new SimpleRepository<Persisted2>(),
                    new SimpleRepository<Persisting1>(),
                    new SimpleRepository<Persisting2>(),
                    new SimpleRepository<Saved1>(),
                    new SimpleRepository<Title1>(),
                    new SimpleRepository<Title2>(),
                    new SimpleRepository<Title3>(),
                    new SimpleRepository<Title4>(),
                    new SimpleRepository<Title5>(),
                    new SimpleRepository<Title6>(),
                    new SimpleRepository<Title7>(),
                    new SimpleRepository<Title8>(),
                    new SimpleRepository<Title9>(),
                    new SimpleRepository<Title10>(),
                    new SimpleRepository<Updated1>(),
                    new SimpleRepository<Updated2>(),
                    new SimpleRepository<Updating1>(),
                    new SimpleRepository<Updating2>(),
                    new SimpleRepository<Validate1>(),
                    new SimpleRepository<Validate2>(),
                    new SimpleRepository<Validate3>(),
                    new SimpleRepository<Validate4>(),
                    new SimpleRepository<Validate5>()
                };
            }
        }
        #endregion

        #region AutoComplete

        [TestMethod]
        public void RecognisedAutoCompleteMethodDoesNotShowUpAsAction() {
            var obj1 = NewTestObject<Auto1>();
            try {
                var act = obj1.GetAction("Auto Complete Prop2");
                Assert.Fail("Should not get to here!");
            }
            catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete Prop2'", e.Message);
            }
            try {
                var act = obj1.GetAction("Auto Complete Prop3");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete Prop3'", e.Message);
            }

            try {
                obj1.GetAction("Auto Complete0 Do Something");
                Assert.Fail("Should not get to here!");
            }
            catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete0 Do Something'", e.Message);
            }
            try {
                obj1.GetAction("Auto Complete1 Do Something");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete1 Do Something'", e.Message);
            }
            try {
                obj1.GetAction("Auto Complete2 Do Something");
                Assert.Fail("Should not get to here!");
            } catch (Exception e) {
                Assert.AreEqual("Assert.Fail failed. No Action named 'Auto Complete2 Do Something'", e.Message);
            }
        }

        [TestMethod]
        public void UnmatchedAutoCompleteMethodShowsUpAsAction() {
            ITestObject obj3 = NewTestObject<Auto3>();
            obj3.GetAction("Auto Complete Prop1");
            obj3.GetAction("Auto Complete Prop2");
            obj3.GetAction("Auto Complete Prop3");
            obj3.GetAction("Auto Complete 0 Do Something");
            obj3.GetAction("Auto Complete 1 Do Something");
            obj3.GetAction("Auto Complete 2 Do Somting");
            obj3.GetAction("Auto Complete 3 Do Something");
        }

        private void CreateAuto2(string prop1) {
            var obj2 = NewTestObject<Auto2>();
            obj2.GetPropertyByName("Prop1").SetValue(prop1);
            obj2.Save();
        }

        [TestMethod]
        public virtual void AutoCompleteParameters() {
            CreateAuto2("Bar1");
            CreateAuto2("Bar2");
            CreateAuto2("Bar3");

            var obj1 = NewTestObject<Auto1>();
            var action = obj1.GetAction("Do Something");
            ITestNaked[] cho0 = action.Parameters[0].GetCompletions("any");
            Assert.AreEqual(1, cho0.Count());

            ITestNaked[] cho1 = action.Parameters[1].GetCompletions("any");
            Assert.AreEqual(3, cho1.Count());

            ITestNaked[] cho2 = action.Parameters[2].GetCompletions("bar");
            Assert.AreEqual(2, cho2.Count());
        }

        [TestMethod]
        public virtual void AutoCompleteReferenceProperty() {
            CreateAuto2("Foo1");
            CreateAuto2("Foo2");
            CreateAuto2("Foo3");

            var obj1 = NewTestObject<Auto1>();
            ITestProperty prop = obj1.GetPropertyByName("Prop3");
            ITestNaked[] cho = prop.GetCompletions("foo");
            Assert.AreEqual(3, cho.Count());
            Assert.AreEqual("Foo1", cho[0].Title);
        }

        [TestMethod]
        public virtual void AutoCompleteStringProperty() {
            var obj1 = NewTestObject<Auto1>();
            ITestProperty prop = obj1.GetPropertyByName("Prop2");
            ITestNaked[] cho = prop.GetCompletions("any");
            Assert.AreEqual(3, cho.Count());
            Assert.AreEqual("Fee", cho[0].Title);
        }

        #endregion

        #region Choices

        [TestMethod]
        public void ChoicesMethodDoesNotShowUpAsAction() {
            var obj1 = NewTestObject<Choices1>();
            try {
                obj1.GetAction("Choices Prop1");
                Assert.Fail();
            }
            catch (Exception e) {
                Assert.IsNotNull(e);
            }

            try {
                obj1.GetAction("Choices 0 Do Something");
                Assert.Fail();
            }
            catch (Exception e) {
                Assert.IsNotNull(e);
            }
{'fraction_non_alphanumeric': 0.09892020015801949, 'fraction_numerical': 0.016328680537266264, 'mean_word_length': 1.7231784279977052, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 0, '>': 128, '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': '4331311', 'n_tokens_mistral': 4613, 'n_tokens_neox': 4395, 'n_words': 1095}