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); var updated = Province.Load(province.ID); Assert.IsNotNull(updated); Compare(updated, loaded); // Delete loaded = Province.Load(province.ID); loaded.Delete(); Assert.IsTrue(loaded.IsValid); Assert.IsTrue(loaded.IsDeleted); loaded.AcceptChanges(); loaded = Province.Load(province.ID); Assert.IsNull(loaded); }