示例#1
0
        public void Test_TimeZone_Validation()
        {
            var timeZone = new Countries.DomainModel.TimeZone();

            timeZone.TimeZoneAcronym = null;
            timeZone.TimeZoneName    = null;
            timeZone.UTCOffset       = -15m;

            var validationResults = Get_Validation_Results(timeZone);

            Assert.IsTrue(validationResults.Count > 0);
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "EntityKey", StringComparison.OrdinalIgnoreCase))));
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "Id", StringComparison.OrdinalIgnoreCase))));
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "TimeZoneAcronym", StringComparison.OrdinalIgnoreCase))));
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "TimeZoneName", StringComparison.OrdinalIgnoreCase))));
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "UTCOffset", StringComparison.OrdinalIgnoreCase))));

            timeZone.TimeZoneAcronym = "xx";

            validationResults = Get_Validation_Results(timeZone);

            Assert.IsTrue(validationResults.Count > 0);
            Assert.IsTrue(validationResults.Any(
                              x => x.MemberNames.Any(y => string.Equals(y, "TimeZoneAcronym", StringComparison.OrdinalIgnoreCase))));
        }
示例#2
0
        public void Test_TimeZone_Create()
        {
            var timeZone = new Countries.DomainModel.TimeZone()
            {
                DetachedState   = DetachedState.Added,
                TimeZoneAcronym = timeZoneAbbreviationCreate,
                TimeZoneName    = timeZoneNameCreate,
                UTCOffset       = timeZoneUTCOffsetCreate
            };

            var validationResults = Get_Validation_Results(timeZone);

            Assert.AreEqual(expected: 0, actual: validationResults.Count);

            using (var entityManager = new CountriesEntityManager()) {
                entityManager.AddEntity <Countries.DomainModel.TimeZone>(timeZone);
                int updateCount = entityManager.SaveChanges();
                Assert.AreNotEqual(notExpected: 0, actual: updateCount);
            }

            using (var entityManager = new CountriesEntityManager()) {
                var timeZoneFromDb = entityManager.Set <Countries.DomainModel.TimeZone>()
                                     .Where(x => (x.Id == timeZone.Id))
                                     .SingleOrDefault();

                Assert.IsNotNull(timeZoneFromDb);
                Assert.AreEqual(expected: timeZone.ToCSVString(), actual: timeZoneFromDb.ToCSVString());

                // all entity properties must be virtual for this to work
                var proxy = timeZoneFromDb as IEntityWithChangeTracker;
                Assert.IsNotNull(proxy);
            }
        }
示例#3
0
        public void Test_TimeZone_Delete()
        {
            var timeZone = new Countries.DomainModel.TimeZone()
            {
                DetachedState   = DetachedState.Added,
                TimeZoneAcronym = timeZoneAbbreviationDelete,
                TimeZoneName    = timeZoneNameDelete,
                UTCOffset       = timeZoneUTCOffsetDelete
            };

            var validationResults = Get_Validation_Results(timeZone);

            Assert.AreEqual(expected: 0, actual: validationResults.Count);

            using (var entityManager = new CountriesEntityManager()) {
                entityManager.AddEntity <Countries.DomainModel.TimeZone>(timeZone);
                int updateCount = entityManager.SaveChanges();
                Assert.AreNotEqual(notExpected: 0, actual: updateCount);
            }

            using (var entityManager = new CountriesEntityManager()) {
                var timeZoneFromDb = entityManager.Set <Countries.DomainModel.TimeZone>()
                                     .Where(x => (x.Id == timeZone.Id))
                                     .SingleOrDefault();

                Assert.IsNotNull(timeZoneFromDb);
            }

            var timeZoneToDelete = new Countries.DomainModel.TimeZone()
            {
                DetachedState = DetachedState.Deleted,
                Id            = timeZone.Id,
                RowVersion    = timeZone.RowVersion
            };

            using (var entityManager = new CountriesEntityManager()) {
                entityManager.RemoveEntity <Countries.DomainModel.TimeZone>(timeZoneToDelete);
                int updateCount = entityManager.SaveChanges();
                Assert.AreNotEqual(notExpected: 0, actual: updateCount);
            }

            using (var entityManager = new CountriesEntityManager()) {
                var timeZoneFromDb = entityManager.Set <Countries.DomainModel.TimeZone>()
                                     .Where(x => (x.Id == timeZone.Id))
                                     .SingleOrDefault();

                Assert.IsNull(timeZoneFromDb);
            }
        }