Unit Test XF Entities

StatusIDPriorityType
Closed39440MajorQuestion
ProfileReply
samakula AmosClient

Given this sample

using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;

[DomainComponent, DefaultClassOptions, ImageName("BO_Employee")] public interface IEmployee {
[RuleRequiredField(EmployeeValidationRules.EmployeeNameIsRequired, DefaultContexts.Save)] string Name { get; set; }
[RuleValueComparison(EmployeeValidationRules.EmployeeIsAdult, DefaultContexts.Save,
ValueComparisonType.GreaterThanOrEqual, 18)] int Age { get; set;}
}
public class EmployeeValidationRules {
public const string EmployeeNameIsRequired = "EmployeeNameIsRequired";
public const string EmployeeIsAdult = "EmployeeIsAdult";
}

and

using NUnit.Framework;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Xpo;
using DevExpress.Persistent.Validation;

[TestFixture] public class EmployeeValidationTests {
private IObjectSpace objectSpace;
[SetUp] public virtual void SetUp() {
objectSpace = new XPObjectSpaceProvider(new MemoryDataStoreProvider()).CreateObjectSpace();
XafTypesInfo.Instance.RegisterEntity("Employee", typeof(IEmployee));
XafTypesInfo.Instance.GenerateEntities();
}
[Test] public void EmployeeIsValid() {
IEmployee employee = objectSpace.CreateObject();
RuleSet ruleSet = new RuleSet();
RuleSetValidationResult result;

result = ruleSet.ValidateTarget(objectSpace, employee, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Invalid,
result.GetResultItem(EmployeeValidationRules.EmployeeNameIsRequired).State);

employee.Name = "Mary Tellitson";
result = ruleSet.ValidateTarget(objectSpace, employee, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Valid,
result.GetResultItem(EmployeeValidationRules.EmployeeNameIsRequired).State);

employee.Age = 17;
result = ruleSet.ValidateTarget(objectSpace, employee, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Invalid,
result.GetResultItem(EmployeeValidationRules.EmployeeIsAdult).State);

employee.Age = 18;
result = ruleSet.ValidateTarget(objectSpace, employee, DefaultContexts.Save);
Assert.AreEqual(ValidationState.Valid,
result.GetResultItem(EmployeeValidationRules.EmployeeIsAdult).State);
}
}

How doe you modify the test setup method to support XF Entities before calling generate entities?
Alternatively You can give a different approach to testing XF entites validation and logic

Replies

UserDescriptionPosted On
MariyaVoytovichAgent

Hello!

Xafari Client Services is dedicated for helping Xafari customers only.
If you have purchased Xafari subscription please identify yourself.
You can buy Xafari subscription at the page http://galaktikasoft.com/xafari/buy
If you have questions about purchasing please contact us via info@galaktikasoft.com.

We are always happy to help our clients.

Сan you send us a small example in which you test functionality?

Feel free to contact us if you have any questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

× This ticket is closed.

Write US