Exemplo n.º 1
0
        public void TestItineraryStopName_Unique()
        {
            var existingStop = new ItineraryStop
            {
                Name            = "  HELLO  ",
                ItineraryId     = 1,
                ItineraryStopId = 2
            };

            context.ItineraryStops.Add(existingStop);

            var testItineraryStop = new ItineraryStop
            {
                Name        = "  hello ",
                ItineraryId = existingStop.ItineraryId
            };
            var items = new Dictionary <object, object> {
                { EcaContext.VALIDATABLE_CONTEXT_KEY, context }
            };
            var vc      = new ValidationContext(testItineraryStop, null, items);
            var results = new List <ValidationResult>();
            var actual  = Validator.TryValidateObject(testItineraryStop, vc, results);

            Assert.IsFalse(actual);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("Name", results.First().MemberNames.First());

            var expectedErrorMessage = String.Format("The itinerary stop with the name [{0}] already exists.",
                                                     testItineraryStop.Name);

            Assert.AreEqual(expectedErrorMessage, results.First().ErrorMessage);
        }
Exemplo n.º 2
0
        public void TestCreateGetItineraryStopsByItineraryIdQuery_ItineraryDoesNotExist()
        {
            var project = new Project
            {
                ProjectId = 1,
            };
            var cityLocationType = new LocationType
            {
                LocationTypeId   = LocationType.City.Id,
                LocationTypeName = LocationType.City.Value
            };
            var location = new Location
            {
                LocationId     = 1,
                LocationName   = "city",
                LocationType   = cityLocationType,
                LocationTypeId = cityLocationType.LocationTypeId
            };
            var person1 = new Person
            {
                PersonId = 1,
                FullName = "person 1"
            };
            var participant1 = new Participant
            {
                ParticipantId = 1,
                PersonId      = person1.PersonId,
                Person        = person1
            };
            var itinerary = new Itinerary
            {
                ItineraryId = 1,
                Name        = "itinerary name",
                StartDate   = DateTimeOffset.UtcNow.AddDays(-100.0),
                EndDate     = DateTimeOffset.UtcNow.AddDays(100.0),
                ProjectId   = project.ProjectId,
                Project     = project
            };
            var stop = new ItineraryStop
            {
                DateArrive    = DateTimeOffset.UtcNow.AddDays(-10.0),
                DateLeave     = DateTimeOffset.UtcNow.AddDays(10.0),
                Destination   = location,
                DestinationId = location.LocationId,
                Itinerary     = itinerary,
                ItineraryId   = itinerary.ItineraryId,
                Name          = "stop"
            };

            stop.History.RevisedOn = DateTimeOffset.UtcNow;
            stop.Participants.Add(participant1);

            context.ItineraryStops.Add(stop);
            context.Locations.Add(location);
            context.LocationTypes.Add(cityLocationType);
            var results = ItineraryStopQueries.CreateGetItineraryStopsByItineraryIdQuery(context, itinerary.ItineraryId + 1).ToList();

            Assert.AreEqual(0, results.Count);
        }
        public void TestDoValidateUpdate_EndDateAfterMaxItineraryStopDate()
        {
            var id                                 = 1;
            var updator                            = new User(1);
            var startDate                          = DateTimeOffset.Now.AddDays(-1.0);
            var endDate                            = DateTimeOffset.Now.AddDays(1.0);
            var projectId                          = 1;
            var name                               = "name";
            var arrivalLocationId                  = 2;
            var departureLocationId                = 3;
            UpdatedEcaItinerary  model             = null;
            Project              project           = null;
            Location             arrivalLocation   = null;
            Location             departureLocation = null;
            Itinerary            itinerary         = null;
            List <ItineraryStop> stops             = new List <ItineraryStop>();

            var itineraryStop = new ItineraryStop
            {
                DateArrive = DateTimeOffset.Now,
                DateLeave  = DateTimeOffset.Now
            };

            stops.Add(itineraryStop);

            Func <UpdatedEcaItineraryValidationEntity> createEntity = () =>
            {
                itinerary = new Itinerary
                {
                    ItineraryId = id
                };
                project = new Project
                {
                    ProjectId = projectId
                };
                arrivalLocation = new Location
                {
                    LocationId = arrivalLocationId
                };
                departureLocation = new Location
                {
                    LocationId = departureLocationId
                };
                model = new UpdatedEcaItinerary(id, updator, startDate, endDate, name, projectId, arrivalLocationId, departureLocationId);
                return(new UpdatedEcaItineraryValidationEntity(model, itinerary, arrivalLocation, departureLocation, stops));
            };

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

            endDate = DateTimeOffset.Now.AddDays(-1.0);

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

            Assert.AreEqual(1, validationErrors.Count);
            Assert.AreEqual(ItineraryServiceValidator.END_DATE_BEFORE_ITINERARY_STOP_MAX_DATE, validationErrors.First().ErrorMessage);
            Assert.AreEqual(PropertyHelper.GetPropertyName <AddedEcaItinerary>(x => x.EndDate), validationErrors.First().Property);
        }
Exemplo n.º 4
0
        public ItineraryModel GetSingleItinerary(int ItinId)
        {
            ItineraryModel output = null;

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(@"SELECT * FROM Itinerary WHERE ItinId = @ItinId; ", conn);
                    cmd.Parameters.AddWithValue("@ItinId", ItinId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        output = new ItineraryModel();

                        output.ItinId    = Convert.ToInt32(reader["ItinId"]);
                        output.ItinName  = Convert.ToString(reader["ItinName"]);
                        output.UserId    = Guid.Parse(Convert.ToString(reader["UserId"]));
                        output.StartDate = Convert.ToDateTime(reader["StartDate"]);
                    }
                    reader.Close();

                    SqlCommand cmd2 = new SqlCommand(@"SELECT * FROM Itinerary_Stops WHERE Itinerary_Stops.ItinId = @ItinId ORDER BY [Order];", conn);
                    cmd2.Parameters.AddWithValue("@ItinId", ItinId);

                    reader       = cmd2.ExecuteReader();
                    output.Stops = new List <ItineraryStop>();
                    while (reader.Read())
                    {
                        ItineraryStop stop = new ItineraryStop();
                        stop.PlaceID   = Convert.ToString(reader["PlaceId"]);
                        stop.Name      = Convert.ToString(reader["Name"]);
                        stop.Image     = Convert.ToString(reader["Image"]);
                        stop.Address   = Convert.ToString(reader["Address"]);
                        stop.Order     = Convert.ToInt32(reader["Order"]);
                        stop.Latitude  = Convert.ToDouble(reader["Latitude"]);
                        stop.Longitude = Convert.ToDouble(reader["Longitude"]);
                        stop.Category  = Convert.ToString(reader["Category"]);
                        output.Stops.Add(stop);
                    }
                }
                return(output);
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occurred reading the database: " + ex.Message);
                return(null);
            }
        }
        private void DoSetParticipants(
            Itinerary itinerary,
            ItineraryStop itineraryStop,
            IEnumerable <Participant> itineraryParticipants,
            ItineraryStopParticipants itineraryStopParticipants)
        {
            var notAllowedParticipantsById = itineraryStopParticipants.ParticipantIds.Except(itineraryParticipants.Select(x => x.ParticipantId).Distinct());

            var validationEntity = new ItineraryStopParticipantsValidationEntity(notAllowedParticipantsById);

            itineraryStopParticipantsValidator.ValidateUpdate(validationEntity);

            Contract.Assert(itineraryStopParticipants.Audit.GetType() == typeof(Update), "The audit type must be an update.  The itinerary create date should not change.");
            itineraryStopParticipants.Audit.SetHistory(itineraryStop);
            itineraryStopParticipants.Audit.SetHistory(itinerary);
            SetParticipants(itineraryStopParticipants.ParticipantIds.ToList(), itineraryStop, x => x.Participants);
        }
Exemplo n.º 6
0
        public void TestNameMaxLength()
        {
            var stop = new ItineraryStop
            {
                Name = new string('a', ItineraryStop.NAME_MAX_LENGTH),
            };
            var items = new Dictionary <object, object> {
                { EcaContext.VALIDATABLE_CONTEXT_KEY, context }
            };
            var vc      = new ValidationContext(stop, null, items);
            var results = new List <ValidationResult>();
            var actual  = Validator.TryValidateObject(stop, vc, results, true);

            Assert.IsTrue(actual);
            Assert.AreEqual(0, results.Count);
            stop.Name = new string('a', ItineraryStop.NAME_MAX_LENGTH + 1);

            actual = Validator.TryValidateObject(stop, vc, results, true);
            Assert.IsFalse(actual);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("Name", results.First().MemberNames.First());
        }
        private ItineraryStop DoCreate(Itinerary itinerary, AddedEcaItineraryStop addedStop)
        {
            var validationEntity = GetEcaItineraryStopValidationEntity(itinerary: itinerary, ecaitineraryStop: addedStop);

            itineraryStopValidator.ValidateCreate(validationEntity);

            var update = new Update(addedStop.Audit.User);

            update.SetHistory(itinerary);

            var itineraryStop = new ItineraryStop();

            itineraryStop.DateArrive        = addedStop.ArrivalDate;
            itineraryStop.DateLeave         = addedStop.DepartureDate;
            itineraryStop.DestinationId     = addedStop.DestinationLocationId;
            itineraryStop.ItineraryId       = addedStop.ItineraryId;
            itineraryStop.ItineraryStatusId = ItineraryStatus.InProgress.Id;
            itineraryStop.Name       = addedStop.Name;
            itineraryStop.TimezoneId = addedStop.TimezoneId;
            addedStop.Audit.SetHistory(itineraryStop);

            Context.ItineraryStops.Add(itineraryStop);
            return(itineraryStop);
        }
        private void DoUpdate(Itinerary itinerary, UpdatedEcaItineraryStop updatedStop, ItineraryStop itineraryStop)
        {
            var validationEntity = GetEcaItineraryStopValidationEntity(itinerary: itinerary, ecaitineraryStop: updatedStop);

            itineraryStopValidator.ValidateUpdate(validationEntity);

            itineraryStop.DateArrive    = updatedStop.ArrivalDate;
            itineraryStop.DateLeave     = updatedStop.DepartureDate;
            itineraryStop.DestinationId = updatedStop.DestinationLocationId;
            itineraryStop.Name          = updatedStop.Name;
            itineraryStop.TimezoneId    = updatedStop.TimezoneId;

            Contract.Assert(updatedStop.Audit.GetType() == typeof(Update), "The audit type must be an update.  The itinerary create date should not change.");
            updatedStop.Audit.SetHistory(itineraryStop);
            updatedStop.Audit.SetHistory(itinerary);
        }
Exemplo n.º 9
0
        public void TestCreateGetItinerariesQuery_CheckProperties()
        {
            var participant1 = new Participant
            {
                ParticipantId = 1,
            };
            var participant2 = new Participant
            {
                ParticipantId = 2
            };
            var participant3 = new Participant
            {
                ParticipantId = 3
            };

            var cityLocationType = new LocationType
            {
                LocationTypeId   = LocationType.City.Id,
                LocationTypeName = LocationType.City.Value
            };
            var countryLocationType = new LocationType
            {
                LocationTypeId   = LocationType.Country.Id,
                LocationTypeName = LocationType.Country.Value
            };
            var arrival = new Location
            {
                LocationId     = 1,
                LocationName   = "city 1",
                LocationType   = cityLocationType,
                LocationTypeId = cityLocationType.LocationTypeId
            };
            var departureDestination = new Location
            {
                LocationId     = 2,
                LocationName   = "country 1",
                LocationType   = countryLocationType,
                LocationTypeId = countryLocationType.LocationTypeId
            };
            var project = new Project
            {
                ProjectId = 1
            };
            var itinerary = new Itinerary
            {
                Arrival             = arrival,
                ArrivalLocationId   = arrival.LocationId,
                Departure           = departureDestination,
                DepartureLocationId = departureDestination.LocationId,
                EndDate             = DateTimeOffset.Now.AddDays(1.0),
                ItineraryId         = 1,
                Name      = "name",
                ProjectId = project.ProjectId,
                Project   = project,
                StartDate = DateTimeOffset.Now.AddDays(-10.0),
            };
            var stop = new ItineraryStop
            {
                Itinerary   = itinerary,
                ItineraryId = itinerary.ItineraryId,
            };

            stop.Participants.Add(participant1);
            stop.Participants.Add(participant2);
            stop.Participants.Add(participant3);
            itinerary.Participants.Add(participant1);
            itinerary.Participants.Add(participant2);
            itinerary.Participants.Add(participant3);
            itinerary.Stops.Add(stop);
            itinerary.History.RevisedOn = DateTimeOffset.Now.AddDays(-2.0);
            context.LocationTypes.Add(cityLocationType);
            context.LocationTypes.Add(countryLocationType);
            context.Locations.Add(arrival);
            context.Locations.Add(departureDestination);
            context.Projects.Add(project);
            context.Itineraries.Add(itinerary);
            context.ItineraryStops.Add(stop);
            context.Participants.Add(participant1);
            context.Participants.Add(participant2);
            context.Participants.Add(participant3);

            var results = ItineraryQueries.CreateGetItinerariesQuery(context);

            Assert.AreEqual(1, results.Count());

            var firstResult = results.First();

            Assert.AreEqual(arrival.LocationId, firstResult.ArrivalLocation.Id);
            Assert.AreEqual(departureDestination.LocationId, firstResult.DepartureLocation.Id);
            Assert.AreEqual(project.ProjectId, firstResult.ProjectId);
            Assert.AreEqual(itinerary.History.RevisedOn, firstResult.LastRevisedOn);
            Assert.AreEqual(itinerary.EndDate, firstResult.EndDate);
            Assert.AreEqual(itinerary.ItineraryId, firstResult.Id);
            Assert.AreEqual(itinerary.Name, firstResult.Name);
            Assert.AreEqual(itinerary.StartDate, firstResult.StartDate);
            Assert.AreEqual(3, firstResult.ParticipantsCount);
        }
Exemplo n.º 10
0
        public void TestCreateGetItineraryStopsQueryTest_CheckProperties()
        {
            var project = new Project
            {
                ProjectId = 1,
            };
            var cityLocationType = new LocationType
            {
                LocationTypeId   = LocationType.City.Id,
                LocationTypeName = LocationType.City.Value
            };
            var location = new Location
            {
                LocationId     = 1,
                LocationName   = "city",
                LocationType   = cityLocationType,
                LocationTypeId = cityLocationType.LocationTypeId
            };
            var person1 = new Person
            {
                PersonId = 1,
                FullName = "person 1"
            };
            var participant1 = new Participant
            {
                ParticipantId = 1,
                PersonId      = person1.PersonId,
                Person        = person1
            };
            var itinerary = new Itinerary
            {
                ItineraryId = 1,
                Name        = "itinerary name",
                StartDate   = DateTimeOffset.UtcNow.AddDays(-100.0),
                EndDate     = DateTimeOffset.UtcNow.AddDays(100.0),
                ProjectId   = project.ProjectId,
                Project     = project
            };
            var stop = new ItineraryStop
            {
                DateArrive    = DateTimeOffset.UtcNow.AddDays(-10.0),
                DateLeave     = DateTimeOffset.UtcNow.AddDays(10.0),
                Destination   = location,
                DestinationId = location.LocationId,
                Itinerary     = itinerary,
                ItineraryId   = itinerary.ItineraryId,
                Name          = "stop",
                TimezoneId    = "timezone"
            };

            stop.History.RevisedOn = DateTimeOffset.UtcNow;
            stop.Participants.Add(participant1);

            context.ItineraryStops.Add(stop);
            context.Locations.Add(location);
            context.LocationTypes.Add(cityLocationType);
            var results = ItineraryStopQueries.CreateGetItineraryStopsQuery(context).ToList();

            Assert.AreEqual(1, results.Count);

            var firstResult = results.First();

            Assert.AreEqual(stop.TimezoneId, firstResult.TimezoneId);
            Assert.AreEqual(stop.DateArrive, firstResult.ArrivalDate);
            Assert.AreEqual(stop.DateLeave, firstResult.DepartureDate);
            Assert.AreEqual(itinerary.ItineraryId, firstResult.ItineraryId);
            Assert.AreEqual(stop.ItineraryStopId, firstResult.ItineraryStopId);
            Assert.AreEqual(stop.History.RevisedOn, firstResult.LastRevisedOn);
            Assert.AreEqual(stop.Name, firstResult.Name);
            Assert.AreEqual(1, firstResult.ParticipantsCount);
            Assert.AreEqual(project.ProjectId, firstResult.ProjectId);

            Assert.IsNotNull(firstResult.DestinationLocation);
            var destination = firstResult.DestinationLocation;

            Assert.AreEqual(location.LocationId, destination.Id);

            //check participants
            Assert.AreEqual(1, firstResult.Participants.Count());
            var firstParticipant = firstResult.Participants.First();

            Assert.AreEqual(participant1.ParticipantId, firstParticipant.ParticipantId);
            Assert.AreEqual(person1.PersonId, firstParticipant.PersonId);
            Assert.AreEqual(person1.FullName, firstParticipant.FullName);
            Assert.AreEqual(-1, firstParticipant.ItineraryInformationId);
            Assert.IsNull(firstParticipant.TravelingFrom);
        }