public void RemoveBracketsTest()
        {
            string test     = "{asd;flkjl}";
            string expected = "asd;flkjl";
            string actual   = CoreExtensions.RemoveBrackets(test);

            Assert.AreEqual(expected, actual);
        }
        public void StripLastWordTest5()
        {
            string test     = string.Empty;
            string expected = string.Empty;
            var    actual   = CoreExtensions.StripLastWord(test, "48072", "test");

            Assert.AreEqual(expected, actual);
        }
        public void LastWordTest2()
        {
            string test     = string.Empty;
            string expected = string.Empty;
            var    actual   = CoreExtensions.LastWord(test);

            Assert.AreEqual(expected, actual);
        }
        public void StripLastWordTest4()
        {
            string test     = "Our Lady of La Salette Church 2600 Harvard Rd Berkley, MI 48072";
            string expected = "Our Lady of La Salette Church 2600 Harvard Rd Berkley, MI test";
            var    actual   = CoreExtensions.StripLastWord(test, "48072", "test");

            Assert.AreEqual(expected, actual);
        }
Beispiel #5
0
        public void TestMemoizeMethodsAreDifferent()
        {
            var f1 = CoreExtensions.Memoize(MemoTest1);
            var f2 = CoreExtensions.Memoize(MemoTest1);

            Assert.AreNotSame(f1(), f2());
            Assert.AreEqual(2, memoTest1CallCount);
        }
        public void RunWithRetriesShouldHandleNullAction()
        {
            Func <bool> actIn = null;

            Action act = () => CoreExtensions.RunWithRetries(5, actIn);

            act.ShouldNotThrow("Because there is currently exception block that hides all exceptions.");
        }
        public void TestRunInThreadAndWaitWithNullAction()
        {
            // this will crash the whole app domain currently because there is NullReferenceException in the call
            CoreExtensions.RunInThreadAndWait(null);

            // NOTE! Decision should the RunInThreadAndWait handle the possible exception in the thread and throw own exception
            // or let it go to appdomain unhandled exception and tear down the appdomain
        }
        public void ToStandardTimeTest2()
        {
            string input    = "8:00 AM";
            var    actual   = CoreExtensions.ToStandardTime(input);
            string expected = "8:00 AM";

            Assert.AreEqual(expected, actual);
        }
        public void DecryptStringTest()
        {
            string cipherText = "ZOVtsFv5YFVpQ3wJMB6nug==";
            string expected   = "test";
            string actual;

            actual = CoreExtensions.DecryptString(cipherText);
            Assert.AreEqual(expected, actual);
        }
        public void toGoggleArrayTest()
        {
            string s = "Poor\t\tFair\t\tDon't Know\t\tGood\t\tExcellent\t\n5396\t\t12056\t\t32425\t\t30753\t\t38158\t\n";

            string actual;

            actual = CoreExtensions.toGogleArray(s);
            Assert.IsTrue(actual.IsGoogleArray());
        }
        public void IsTabDelimitedTest()
        {
            string s        = "Poor\t\tFair\t\tDon't Know\t\tGood\t\tExcellent\t\n5396\t\t12056\t\t32425\t\t30753\t\t38158\t\n";
            bool   expected = true;
            bool   actual;

            actual = CoreExtensions.IsTabDelimited(s);
            Assert.AreEqual(expected, actual);
        }
        public void EncryptStringTest()
        {
            string plainText = "test";
            string expected  = "ZOVtsFv5YFVpQ3wJMB6nug=="; // TODO: Initialize to an appropriate value
            string actual;

            actual = CoreExtensions.EncryptString(plainText);
            Assert.AreEqual(expected, actual);
        }
        public void CleanPortFromUrlTest()
        {
            string url      = "http://www.example.com:80/dir/?query=test";
            string expected = "http://www.example.com/dir/?query=test";
            string actual;

            actual = CoreExtensions.CleanPortFromUrl(url);
            Assert.AreEqual(expected, actual);
        }
        public void LeftTrimCleanUpMediaUrlTest()
        {
            string mediaUrl = "local.chsl.com/http://local.chsl.com/~/media/files/chsl/sports/boys/lacrosse/honors/2002.ashx";
            string expected = "http://local.chsl.com/~/media/files/chsl/sports/boys/lacrosse/honors/2002.ashx";
            string actual;

            actual = CoreExtensions.CleanUpMediaUrl(mediaUrl);
            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public static void LoadInstanceFromIsoStorage(string filename)
        {
            var source = CoreExtensions.LoadFromFile <MainDataSource>(filename);

            if (source != null)
            {
                Instance = source;
            }
        }
Beispiel #16
0
 private async void TeamExplorerOnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (TeamExplorer != null && e.PropertyName == CoreExtensions.GetMemberName(() => TeamExplorer.CurrentPage))
     {
         TeamExplorer.PropertyChanged -= TeamExplorerOnPropertyChanged;
         eventRegistered = false;
         await RefreshAsync();
     }
 }
 public void OldDateTimeToBoolTest()
 {
     Assert.True(CoreExtensions.ToBool(new DateTime(1901, 1, 1)));
     Assert.True(CoreExtensions.ToBool(new DateTime(2099, 1, 1)));
     Assert.False(CoreExtensions.ToBool(new DateTime(1900, 1, 1)));
     Assert.False(CoreExtensions.ToBool(new DateTime(3000, 1, 1)));
     Assert.False(CoreExtensions.ToBool(new DateTime(1899, 1, 1)));
     Assert.False(CoreExtensions.ToBool(new DateTime(3001, 1, 1)));
 }
        //[Route("{entityTypeName}/{id:int}/settings/{actionName}"), HttpPost, ValidateInput(false)]
        public ActionResult UpdateSetting(string entityTypeName, int id, string actionName)
        {
            var s = CoreExtensions.GetEntity(DbContext, entityTypeName, id) as IHasSettings;
            var a = s?.Settings().WithAccess(User, DbContext).FirstOrDefault(sa => sa.ActualType().Name == CoreExtensions.DashesToCamelcase(actionName));

            a.Setup(DbContext, User, Auth);

            foreach (var field in a.Fields)
            {
                object value;
                if (Request.Files.AllKeys.Contains(field.UniqueName))
                {
                    value = (object)Request.Files.Get(field.UniqueName);
                }
                else if (field.FieldAttribute is RecurringFieldAttribute)
                {
                    value = HttpUtility.HtmlDecode(Request.Form.GetValues(field.UniqueName)[0]);
                }
                else if (typeof(IEnumerable <object>).IsAssignableFrom(field.PropertyType))
                {
                    value = Request.Form.GetValues(field.UniqueName);
                }
                else
                {
                    value = (object)Request.Form.Get(field.UniqueName);
                }

                field.PropertyInfo.SetValue(a, new ActionMapper(DbContext).Map(a, field, field.PropertyInfo.PropertyType, value));
            }

            a.Validate();

            if (a.IsValid)
            {
                a.Run(User);
                DbContext.SaveChanges();
            }

            var actions = s.Settings().WithAccess(User, DbContext).ToList();

            foreach (var sa in actions)
            {
                sa.Setup(DbContext, User, Auth);
            }
            actions[actions.FindIndex(sa => sa.ActualType().IsAssignableFrom(a.ActualType()))] = a;

            var vm = new ViewModel {
                Entity = s, Description = s.Description(User), Actions = actions, SelectedAction = a, Submitted = true
            };

            if (a.IsValid)
            {
                return(RedirectToAction("SettingSuccess", new { entityTypeName = entityTypeName, id = id, actionName = actionName }));
            }

            return(View("Settings", vm));
        }
Beispiel #19
0
        public void TestMemoizeMethod1()
        {
            var f1   = CoreExtensions.Memoize(MemoTest1);
            var obj1 = f1();
            var obj2 = f1();

            Assert.AreSame(obj1, obj2);
            Assert.AreEqual(1, memoTest1CallCount);
        }
Beispiel #20
0
 public override AddressForeignTextName TranslateVmToEntity(VmAddressSimple vModel)
 {
     return(CreateViewModelEntityDefinition(vModel)
            .DisableAutoTranslation()
            .UseDataContextLocalizedUpdate(input => CoreExtensions.IsAssigned((Guid?)input.Id), input => output => output.AddressForeignId == input.Id, d => d.UseDataContextCreate(i => true))
            .AddNavigation(input => input.ForeignAddressText, output => output.Name)
            .AddRequestLanguage(output => output)
            .GetFinal());
 }
        public void IsHtmlValidTest2()
        {
            string s        = "hello <strong>world<strong>";
            bool   expected = false;
            bool   actual;

            actual = CoreExtensions.IsHtmlValid(s);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public void register_multiple_rules_for_a_single_property()
        {
            theRules.Property(x => x.Name).Required().MaximumLength(10);

            var nameRules = rulesFor(x => x.Name);

            CoreExtensions.Count(nameRules).ShouldBe(2);
            nameRules.Any(x => x is RequiredFieldRule).ShouldBeTrue();
            nameRules.ShouldContain(new MaximumLengthRule(10));
        }
        public void CleanupAbsoluteUrlTest()
        {
            string url      = "https://my.aod.org:443/~/media/extranet/bookkeepers/financial%20report%20forms/";
            string expected = "/~/media/extranet/bookkeepers/financial report forms/";
            string actual;

            actual = CoreExtensions.CleanupAbsoluteUrl(url);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public void toGoggleArrayTestBigTable()
        {
            string s = "\tGood\tExcellent\tTotal\nProviding regular meetings for teens \t5847\t8695\t20964\nProviding special events for teens (e.g. social events, retreats, service experiences)\t7869\t12280\t29617\nEngaging youth in parish life and liturgies\t8160\t11422\t29590\nProviding regular meetings for young adults\t6906\t9770\t29505\nHosting special events for young adults \t6954\t9298\t29520\nEngaging young adults in parish ministries and outreaches\t7069\t9432\t29478\n";

            string actual;

            actual = CoreExtensions.toGogleArray(s);
            Assert.AreNotEqual("[]", actual);
            Assert.IsTrue(actual.IsGoogleArray());
        }
        public void GetCoordinatesTest()
        {
            string test = "Our Lady of La Salette Church 2600 Harvard Rd Berkley, MI 48072";

            string[] expected = new string[] { "42.4923395", "-83.1849986" };
            var      actual   = CoreExtensions.GetCoordinates(test);

            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
        }
        public void CleanUpMediaUrlTest1()
        {
            string mediaUrl           = "https://my.aod.org:443/~/media/extranet/bookkeepers/financial%20report%20forms/2012-13%20financial%20reports%20and%20forms%20current%20year/non-parish%20school%202012-13%20financial%20report%20worksheets.ashx";
            bool   isSecureConnection = true; // TODO: Initialize to an appropriate value
            string expected           = "https://my.aod.org:443/~/media/extranet/bookkeepers/financial%20report%20forms/2012-13%20financial%20reports%20and%20forms%20current%20year/non-parish%20school%202012-13%20financial%20report%20worksheets.ashx";

            string actual;

            actual = CoreExtensions.CleanUpMediaUrl(mediaUrl, isSecureConnection);
            Assert.AreEqual(expected, actual);
        }
        public void TrimAfterTest()
        {
            string source       = "5/11/2009 12:00:00 AM ";
            string searchString = " ";
            string expected     = "5/11/2009";
            string actual;

            actual = CoreExtensions.TrimAfter(source, searchString);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
Beispiel #28
0
        public ActionResult QueryProvider(string workflowName, int id, string actionName, string fieldName, string query)
        {
            var action = CoreExtensions.GetAction(DbContext, Auth, workflowName, id, actionName, (Framework.Core.Entities.User)User);

            SetGetParams(action);
            SetPostValues(action, action.Fields);

            var fieldProvider = action.Fields.First(f => f.UniqueName == fieldName).FieldAttribute.GetProvider();

            return(View("Fields/_ListFieldQueryResults", fieldProvider.Options(action, (Framework.Core.Entities.User)User, query)));
        }
        public void ToDateTimeTest()
        {
            string   d        = "10-5-2015";
            string   h        = "15:10";
            DateTime expected = new DateTime(2015, 10, 5, 15, 10, 00);
            DateTime actual;

            actual = CoreExtensions.ToDateTime(d, h);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        //////////////////////////////////////////////////
        ///
        /// <author>Nicholas Paldino</author>
        /// <created>2013-11-17</created>
        /// <summary>Returns a hash code for the specified object.</summary>
        /// <returns>A hash code for the specified object.</returns>
        /// <param name="obj">The instance of <typeparamref name="T"/> for which a hash code is to be returned.</param>
        /// <exception cref="T:System.ArgumentNullException">The type of <paramref name="obj"/> is a reference type
        /// and <paramref name="obj"/> is null.</exception>
        ///
        //////////////////////////////////////////////////
        public int GetHashCode(IEnumerable <T> obj)
        {
            // Validate parameters.
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            // Get the hash codes for the items in the enumerable, and then compose a hash of those.
            // If the instance is null, assume 0.
            return(obj.Select(o => CoreExtensions.IsNull(o) ? 0 : o.GetHashCode()).Compute32BitFnvCompositeHashCode());
        }
Beispiel #31
0
 public void CreateHost()
 {
     host = new CoreExtensions();
 }