예제 #1
0
 public void Test_IsValidationEnabled_with_inherited_attribute()
 {
     // confirm that FooE inherits behaviour of FooB
     Assert.AreEqual(
         DomainObjectValidator.IsValidationEnabled(typeof(FooB)),
         DomainObjectValidator.IsValidationEnabled(typeof(FooE))
         );
 }
예제 #2
0
 public void Test_IsValidationEnabled_with_overridden_attribute()
 {
     // confirm that FooF overrides what is inherited from FooC
     Assert.AreNotEqual(
         DomainObjectValidator.IsValidationEnabled(typeof(FooC)),
         DomainObjectValidator.IsValidationEnabled(typeof(FooF))
         );
 }
예제 #3
0
		public void Test_Validate_validation_disabled_via_overriding_attribute()
		{
			try
			{
				var foo = new FooF() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}
예제 #4
0
		public void Test_Validate()
		{
			try
			{
				var foo = new FooA() {Name = "Bethany"};
				var validator = new DomainObjectValidator();
				validator.Validate(foo);

				Assert.Fail("expected validation failure");
			}
			catch (EntityValidationException e)
			{
				// exactly one broken rule
				Assert.AreEqual(1, e.Reasons.Length);
			}
		}
예제 #5
0
		public void Test_Validate_validation_enabled_via_overriding_attribute()
		{
			try
			{
				var foo = new FooG() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);

				Assert.Fail("expected validation failure");
			}
			catch (EntityValidationException e)
			{
				// note:exactly 2 broken rules: this is important!!!
				// even though one of the rules was defined on a property of the base class,
				// and validation is disabled on the base class, the rule is still
				// evaluated for the subclass FooG which has validation enabled
				Assert.AreEqual(2, e.Reasons.Length);
			}
		}
예제 #6
0
 public void Test_IsValidationEnabled_with_validation_explicitly_enabled()
 {
     Assert.IsTrue(DomainObjectValidator.IsValidationEnabled(typeof(FooC)));
 }
예제 #7
0
 public void Test_IsValidationEnabled_with_validation_disabled()
 {
     Assert.IsFalse(DomainObjectValidator.IsValidationEnabled(typeof(FooB)));
 }
예제 #8
0
 public void Test_IsValidationEnabled_not_explicitly_specified()
 {
     // when no attribute is supplied on the class, the default is that validation is enabled
     Assert.IsTrue(DomainObjectValidator.IsValidationEnabled(typeof(FooA)));
 }
예제 #9
0
        /// <summary>
        /// Import external practitioner from CSV format.
        /// </summary>
        /// <param name="rows">
        /// Each string in the list must contain 25 CSV fields, as follows:
        ///     0 - FamilyName
        ///     1 - GivenName
        ///     2 - MiddleName
        ///     3 - Prefix
        ///     4 - Suffix
        ///     5 - Degree
        ///     6 - LicenseNumber
        ///     7 - BillingNumber
        ///     8 - Street
        ///     9 - Unit
        ///     10 - City
        ///     11 - Province
        ///     12 - PostalCode
        ///     13 - Country
        ///     14 - ValidFrom
        ///     15 - ValidUntil
        ///     16 - Phone CountryCode
        ///     17 - Phone AreaCode
        ///     18 - Phone Number
        ///     19 - Phone Extension
        ///     20 - ValidFrom
        ///     21 - ValidUntil
        ///     22 - Fax CountryCode
        ///     23 - Fax AreaCode
        ///     24 - Fax Number
        ///     25 - Fax Extension
        ///     26 - ValidFrom
        ///     27 - ValidUntil
        /// </param>
        /// <param name="context"></param>
        public override void Import(List <string> rows, IUpdateContext context)
        {
            _context = context;

            var importedEPs = new List <ExternalPractitioner>();
            var validator   = new DomainObjectValidator();

            foreach (var row in rows)
            {
                var fields = ParseCsv(row, _numFields);

                var epFamilyName = fields[0];
                var epGivenName  = fields[1];
                var epMiddlename = fields[2];
                var epPrefix     = fields[3];
                var epSuffix     = fields[4];
                var epDegree     = fields[5];

                var epLicense       = fields[6];
                var epBillingNumber = fields[7];

                var addressStreet     = fields[8];
                var addressUnit       = fields[9];
                var addressCity       = fields[10];
                var addressProvince   = fields[11];
                var addressPostalCode = fields[12];
                var addressCountry    = fields[13];

                var addressValidFrom  = ParseDateTime(fields[14]);
                var addressValidUntil = ParseDateTime(fields[15]);

                var phoneCountryCode = fields[16];
                var phoneAreaCode    = fields[17];
                var phoneNumber      = fields[18];
                var phoneExtension   = fields[19];
                var phoneValidFrom   = ParseDateTime(fields[20]);
                var phoneValidUntil  = ParseDateTime(fields[21]);

                var faxCountryCode = fields[22];
                var faxAreaCode    = fields[23];
                var faxNumber      = fields[24];
                var faxExtension   = fields[25];
                var faxValidFrom   = ParseDateTime(fields[26]);
                var faxValidUntil  = ParseDateTime(fields[27]);


                ExternalPractitioner ep = GetExternalPracitioner(epLicense, importedEPs);

                if (ep != null)
                {
                    continue;
                }

                ep = new ExternalPractitioner {
                    LicenseNumber = epLicense, BillingNumber = epBillingNumber
                };
                ep.Name = new PersonName(epFamilyName, epGivenName, epMiddlename, epPrefix, epSuffix, epDegree);

                // create a single default contact point
                var contactPoint = new ExternalPractitionerContactPoint(ep)
                {
                    Name = "Default", IsDefaultContactPoint = true
                };

                try
                {
                    var epAddress = new Address(
                        addressStreet,
                        addressUnit,
                        addressCity,
                        addressProvince,
                        addressPostalCode,
                        addressCountry,
                        AddressType.B,
                        new DateTimeRange(addressValidFrom, addressValidUntil));
                    validator.Validate(epAddress);
                    contactPoint.Addresses.Add(epAddress);
                }
                catch (EntityValidationException)
                {
                    /* invalid address - ignore */
                }

                try
                {
                    var epTelephone = new TelephoneNumber(
                        phoneCountryCode,
                        phoneAreaCode,
                        phoneNumber,
                        phoneExtension,
                        TelephoneUse.WPN,
                        TelephoneEquipment.PH,
                        new DateTimeRange(phoneValidFrom, phoneValidUntil));

                    validator.Validate(epTelephone);
                    contactPoint.TelephoneNumbers.Add(epTelephone);
                }
                catch (EntityValidationException)
                {
                    /* invalid phone - ignore */
                }

                try
                {
                    var epFax = new TelephoneNumber(
                        faxCountryCode,
                        faxAreaCode,
                        faxNumber,
                        faxExtension,
                        TelephoneUse.WPN,
                        TelephoneEquipment.FX,
                        new DateTimeRange(faxValidFrom, faxValidUntil));

                    validator.Validate(epFax);
                    contactPoint.TelephoneNumbers.Add(epFax);
                }
                catch (EntityValidationException)
                {
                    /* invalid fax - ignore */
                }

                _context.Lock(ep, DirtyState.New);

                importedEPs.Add(ep);
            }
        }
		public void Test_Validate_validation_enabled_via_overriding_attribute()
		{
			try
			{
				var foo = new FooG() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);

				Assert.Fail("expected validation failure");
			}
			catch (EntityValidationException e)
			{
				// note:exactly 2 broken rules: this is important!!!
				// even though one of the rules was defined on a property of the base class,
				// and validation is disabled on the base class, the rule is still
				// evaluated for the subclass FooG which has validation enabled
				Assert.AreEqual(2, e.Reasons.Length);
			}
		}
		public void Test_Validate_validation_disabled_via_overriding_attribute()
		{
			try
			{
				var foo = new FooF() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}
		public void Test_Validate()
		{
			try
			{
				var foo = new FooA() {Name = "Bethany"};
				var validator = new DomainObjectValidator();
				validator.Validate(foo);

				Assert.Fail("expected validation failure");
			}
			catch (EntityValidationException e)
			{
				// exactly one broken rule
				Assert.AreEqual(1, e.Reasons.Length);
			}
		}