public void TestDoValidateCreate_AddedEcaItineraryIsNull()
        {
            var creator                         = new User(1);
            var startDate                       = DateTimeOffset.Now.AddDays(-1.0);
            var endDate                         = DateTimeOffset.Now;
            AddedEcaItinerary model             = null;
            Project           project           = null;
            Location          arrivalLocation   = null;
            Location          departureLocation = null;
            var entity = new AddedEcaItineraryValidationEntity(model, project, arrivalLocation, departureLocation);

            Assert.AreEqual(0, validator.DoValidateCreate(entity).Count());
        }
        public void TestDoValidateCreate_StartDateAfterEndDate()
        {
            var creator                         = new User(1);
            var startDate                       = DateTimeOffset.Now.AddDays(-1.0);
            var endDate                         = DateTimeOffset.Now;
            var projectId                       = 1;
            var name                            = "name";
            var arrivalLocationId               = 2;
            var departureLocationId             = 3;
            AddedEcaItinerary model             = null;
            Project           project           = null;
            Location          arrivalLocation   = null;
            Location          departureLocation = null;
            Func <AddedEcaItineraryValidationEntity> createEntity = () =>
            {
                project = new Project
                {
                    ProjectId = projectId
                };
                arrivalLocation = new Location
                {
                    LocationId = arrivalLocationId
                };
                departureLocation = new Location
                {
                    LocationId = departureLocationId
                };
                model = new AddedEcaItinerary(creator, startDate, endDate, name, projectId, arrivalLocationId, departureLocationId);
                return(new AddedEcaItineraryValidationEntity(model, project, arrivalLocation, departureLocation));
            };

            Assert.AreEqual(0, validator.DoValidateCreate(createEntity()).Count());

            startDate = DateTimeOffset.Now.AddDays(1.0);

            var entity           = createEntity();
            var validationErrors = validator.DoValidateCreate(entity).ToList();

            Assert.AreEqual(1, validationErrors.Count);
            Assert.AreEqual(ItineraryServiceValidator.START_DATE_AFTER_END_DATE_ERROR_MESSAGE, validationErrors.First().ErrorMessage);
            Assert.AreEqual(PropertyHelper.GetPropertyName <AddedEcaItinerary>(x => x.StartDate), validationErrors.First().Property);
        }
示例#3
0
        public void TestConstructor()
        {
            var startDate           = DateTimeOffset.Now.AddDays(-1.0);
            var endDate             = DateTimeOffset.Now.AddDays(1.0);
            var userId              = 2;
            var arrivalLocationId   = 3;
            var departureLocationId = 4;
            var name      = "name";
            var projectId = 10;

            var model = new AddedEcaItinerary(new User(userId), startDate, endDate, name, projectId, arrivalLocationId, departureLocationId);

            Assert.AreEqual(projectId, model.ProjectId);
            Assert.IsInstanceOfType(model.Audit, typeof(Create));
            Assert.AreEqual(userId, model.Audit.User.Id);
            Assert.AreEqual(startDate, model.StartDate);
            Assert.AreEqual(endDate, model.EndDate);
            Assert.AreEqual(name, model.Name);
            Assert.AreEqual(arrivalLocationId, model.ArrivalLocationId);
            Assert.AreEqual(departureLocationId, model.DepartureLocationId);
            Assert.AreEqual(projectId, model.ProjectId);
        }