示例#1
0
 public void RoutesRepository_GetHashByTrack_NullReference_IncorrectData(string track)
 {
     // Arrange
     var repository = new RoutesRepository(_datacontext);
     //Act
     var result = repository.GetHashByTrack(track);
 }
示例#2
0
 public void RoutesRepository_GetHashByTrack_CorrectData(string track, string expectedResult)
 {
     // Arrange
     var repository = new RoutesRepository(_datacontext);
     //Act
     var result = repository.GetHashByTrack(track);
     //Assert
     Assert.AreEqual(result, expectedResult);
 }
示例#3
0
        /// <summary>
        /// Adds the new feedback and get URL to route.
        /// </summary>
        /// <param name="routesNodeWithFeedbacksData">The routes node with feedbacks data.</param>
        /// <returns>Return URL to route with new feedbacks</returns>
        public string AddNewFeedbackAndGetUrlToRoute(List<RouteNodeWithFeedbacksData> routesNodeWithFeedbacksData)
        {
            RoutesRepository routeRepository = new RoutesRepository();
            FeedbackItemRepository feedbackItemRepository = new FeedbackItemRepository();
            StringBuilder track = new StringBuilder(routesNodeWithFeedbacksData.Count * 5 + routesNodeWithFeedbacksData.Count - 1);

            bool backwardOrder = routesNodeWithFeedbacksData[0].OriginCityNodeId >
                     routesNodeWithFeedbacksData[routesNodeWithFeedbacksData
                     .Count - 1].DestinationCityNodeId;

            routesNodeWithFeedbacksData.ForEach(routeWithFeedback =>
            {
                RouteNode routeNode = routeRepository.GetRouteNode(
                routeWithFeedback.OriginCityNodeId, routeWithFeedback.DestinationCityNodeId) ??
                    new RouteNode()
                    {
                        RouteNodeId = routeRepository.CreateRouteNode(routeWithFeedback.OriginCityNodeId,
                            routeWithFeedback.DestinationCityNodeId)
                    };

                int feedbackId = feedbackItemRepository.AddNewFeedback(routeNode.RouteNodeId, routeWithFeedback.UserId,
                    routeWithFeedback.SubmitTime);

                routeWithFeedback.FeedbackValues.ForEach(feedbackValue => feedbackItemRepository.AddNewFeedbackValue(new FeedbackValueData()
                {
                    FeedbackId = feedbackId,
                    Value = feedbackValue.Value,
                    FeedbackItemId = feedbackValue.FeedbackItemId
                }));

                if (!backwardOrder)
                {
                    track.Append(routeWithFeedback.OriginCityNodeId).Append("-");
                    if (routeWithFeedback.Equals(routesNodeWithFeedbacksData.Last()))
                    {
                        track.Append(routeWithFeedback.DestinationCityNodeId);
                    }
                }
                else
                {
                    track.Insert(0, routeWithFeedback.OriginCityNodeId).Insert(0, "-");
                    if (routeWithFeedback.Equals(routesNodeWithFeedbacksData.Last()))
                    {
                        track.Insert(0, routeWithFeedback.DestinationCityNodeId);
                    }
                }
            });
            BuildRoutes(routesNodeWithFeedbacksData[0].OriginCityNodeId,
                routesNodeWithFeedbacksData[routesNodeWithFeedbacksData.Count - 1].DestinationCityNodeId);

            string hash = routeRepository.GetHashByTrack(track.ToString());
            return String.Format("{0}-{1}-To-{2}", hash,
                routesNodeWithFeedbacksData.First().OriginCityNode,
                routesNodeWithFeedbacksData.Last().DestinationCityNode)
                .Replace(" ", "-")
                .Replace(",", "");
        }