当前位置: 首页>>代码示例>>C#>>正文


C# Province.AcceptChanges方法代码示例

本文整理汇总了C#中Province.AcceptChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Province.AcceptChanges方法的具体用法?C# Province.AcceptChanges怎么用?C# Province.AcceptChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Province的用法示例。


在下文中一共展示了Province.AcceptChanges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CRUDProvince

        public void CRUDProvince()
        {
            // Insert
            var province = new Province
            {
            };

            Assert.IsTrue(!province.IsValid
                && !string.IsNullOrEmpty(province.ValidationMessage)
                && province.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_EmptyName")));

            Assert.IsTrue(!province.IsValid
                && !string.IsNullOrEmpty(province.ValidationMessage)
                && province.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_EmptyCreatedBy")));

            Assert.IsTrue(!province.IsValid
                && !string.IsNullOrEmpty(province.ValidationMessage)
                && province.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_EmptyStateID")));

            province.Name = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
            province.CreatedBy = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";

            var state = StateEntity.GetAll().FirstOrDefault();

            if (state == null)
                Assert.Inconclusive();

            province.StateID = state.ID;

            Assert.IsTrue(!province.IsValid
                && !string.IsNullOrEmpty(province.ValidationMessage)
                && province.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_MaxNameLength")));

            Assert.IsTrue(!province.IsValid
                && !string.IsNullOrEmpty(province.ValidationMessage)
                && province.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_MaxCreatedByLength")));

            province.Name = "New temporal province";
            province.CreatedBy = "dcruz";

            Assert.IsTrue(province.IsValid);
            Assert.IsTrue(province.IsNew);

            province.AcceptChanges();

            Assert.IsTrue(province.IsValid);
            Assert.IsTrue(!province.IsChanged);

            var loaded = Province.Load(province.ID);

            Assert.IsNotNull(loaded);
            Assert.IsTrue(!loaded.IsChanged);
            Assert.IsTrue(!loaded.IsNew);

            Compare(loaded, province);

            // Update

            loaded.Name = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";

            Assert.IsTrue(!loaded.IsValid
                && !string.IsNullOrEmpty(loaded.ValidationMessage)
                && loaded.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_MaxNameLength")));

            Assert.IsTrue(!loaded.IsValid
                && !string.IsNullOrEmpty(loaded.ValidationMessage)
                && loaded.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_EmptyLastUpdatedBy")));

            var any = Province.GetProvinces(loaded.StateID).Where(m => m.ID != loaded.ID).FirstOrDefault();

            if (any == null)
                Assert.Inconclusive();

            loaded.Name = any.Name;

            Assert.IsTrue(!loaded.IsValid
                && !string.IsNullOrEmpty(loaded.ValidationMessage)
                && loaded.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_DuplicatedName", new { loaded.Name })));

            Assert.IsTrue(!loaded.IsValid
                && !string.IsNullOrEmpty(loaded.ValidationMessage)
                && loaded.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_EmptyLastUpdatedBy")));

            loaded.Name = "New temporal state 2";
            loaded.LastUpdatedBy = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";

            Assert.IsTrue(!loaded.IsValid
                && !string.IsNullOrEmpty(loaded.ValidationMessage)
                && loaded.ValidationMessage.Contains(ResourceStringLoader.GetResourceString("Province_MaxLastUpdatedByLength")));

            loaded.LastUpdatedBy = "dcruz";

            Assert.IsTrue(loaded.IsChanged);
            Assert.IsTrue(loaded.IsValid);

            loaded.AcceptChanges();

            Assert.IsTrue(!loaded.IsChanged);
            Assert.IsTrue(loaded.IsValid);

//.........这里部分代码省略.........
开发者ID:kohku,项目名称:Bebeclick,代码行数:101,代码来源:ProvinceTest.cs


注:本文中的Province.AcceptChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。