Exemplo n.º 1
0
        public void GetRoadByImageShouldReturnRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetRoadByImage_Roads_Image_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);
            var image        = new Image();

            dbContext.Images.Add(image);
            dbContext.SaveChanges();

            var road = new Road
            {
                RoadName = "roadOne",
                Photos   = new List <Image>()
                {
                    image
                }
            };

            image.Road = road;
            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var result = roadsService.GetRoadByImage(image);

            Assert.Equal(road, result);
        }
Exemplo n.º 2
0
        public void GetCommentsByRoadIdShouldNotReturnCommentsWhenInvalidRoadIsGiven()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentsByRoadId_Comments_Roads_Db")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var road = new Road
            {
                Id       = "Road1",
                RoadName = "Lorem",
                Comments = new List <Comment>
                {
                    new Comment
                    {
                        Content = "comment1"
                    },
                    new Comment
                    {
                        Content = "comment2"
                    }
                }
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var comments = commentsService.GetCommentsByRoadId("road12");

            Assert.Null(comments);
        }
Exemplo n.º 3
0
        public void GetCommentsByRoadIdShouldReturnAllCommentsOfGivenRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentsByRoadId_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var road = new Road
            {
                Id       = "Road1",
                RoadName = "Lorem",
                Comments = new List <Comment>
                {
                    new Comment
                    {
                        Content = "comment1"
                    },
                    new Comment
                    {
                        Content = "comment2"
                    }
                }
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var comments = commentsService.GetCommentsByRoadId(road.Id);

            Assert.Equal(2, comments.Count);
        }
Exemplo n.º 4
0
        public void CreateRoadShouldCreateRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateRoad_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var imageService = new Mock <IImageService>();

            imageService.Setup(x => x.AddPhoto(It.IsAny <IFormFile>())).Returns(new Image
            {
                PublicId  = "PublicId",
                Name      = "123",
                DateAdded = DateTime.UtcNow,
                Id        = Convert.ToString(Guid.NewGuid()),
                ImageUrl  = "http://www.url.com/",
            });

            var roadsService = new RoadsService(dbContext, imageService.Object, null, null, null, null);

            var roadResult = roadsService.Create("Lorem", "Ips", "ium", 1, "Lorem Ipsium", null, "userId", GenerateFile(),
                                                 GenerateFiles(), 1, 1, 1);

            Assert.True(roadResult);
        }
Exemplo n.º 5
0
        public void EditRoadShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditRoad_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var imageService = new Mock <IImageService>();

            imageService.Setup(x => x.AddPhoto(It.IsAny <IFormFile>())).Returns(new Image
            {
                PublicId  = "PublicId",
                Name      = "123",
                DateAdded = DateTime.UtcNow,
                Id        = Convert.ToString(Guid.NewGuid()),
                ImageUrl  = "http://www.ur;.com/",
            });

            var road = new Road
            {
                RoadName = "LoremIpsium1",
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();



            var roadsService = new RoadsService(dbContext, imageService.Object, null, null, null, null);

            var editResult = roadsService.Edit(road.Id, "ipsum", "lorem", "ips", 60, "big description", null, GenerateFile(), 1, 1, 1);

            Assert.True(editResult);
        }
Exemplo n.º 6
0
        public void GetLongestRoadsShouldReturnLongestRoads()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetLongestRoads_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var roads = new List <Road> {
                new Road {
                    RoadName = "Road1", RoadLength = 60
                }, new Road {
                    RoadName = "Road2", RoadLength = 80
                }, new Road {
                    RoadName = "Road3", RoadLength = 40
                }
            };

            dbContext.Roads.AddRange(roads);
            dbContext.SaveChanges();

            var result = roadsService.GetLongestRoads();

            Assert.Equal(result, roads.OrderByDescending(x => x.RoadLength));
        }
Exemplo n.º 7
0
        public void DeleteRoadShouldNotHardDeleteRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteRoad_Road_Db")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var road = new Road()
            {
                RoadName = "Road"
            };



            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            dbContext.Roads.Remove(road);
            dbContext.SaveChanges();

            var result = roadsService.DeleteRoad(road.Id);

            Assert.False(result);
        }
Exemplo n.º 8
0
        public void DeleteReplyByIdShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteReplyById_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);


            var reply = new Reply
            {
                Id = "replyId1",
            };

            dbContext.Replies.Add(reply);
            dbContext.SaveChanges();

            var result = commentsService.DeleteReply(reply.Id);

            //  Assert.Empty(dbContext.Replies);
            Assert.True(result);
        }
Exemplo n.º 9
0
        public void AddReplyToCommentShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddReplyToComment_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var user = new User
            {
                UserName = "******"
            };
            var comment = new Comment
            {
                Content = "comment1",
                Id      = "commentId1",
                Replies = new List <Reply>(),
                User    = user
            };

            dbContext.Users.Add(user);
            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();
            var result = commentsService.AddReplyToComment("commentId1", "reply1", user);

            Assert.True(result);
            Assert.Equal(1, comment.Replies.Count);
        }
Exemplo n.º 10
0
        void GetLatestRoadShouldReturnRoadsOrderedByDateDescending()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetLatestRoads_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var date          = DateTime.UtcNow;
            var dateTwo       = "12-12-1999 1:12:00AM";
            var parsedDateTwo = DateTime.Parse(dateTwo);

            var roads = new List <Road> {
                new Road {
                    RoadName = "Road1", PostedOn = date
                }, new Road {
                    RoadName = "Road2", PostedOn = date.AddDays(2)
                }, new Road {
                    RoadName = "Road3", PostedOn = parsedDateTwo
                }
            };

            dbContext.Roads.AddRange(roads);
            dbContext.SaveChanges();

            var result = roadsService.GetLatestRoads();

            Assert.Equal(result, roads.OrderByDescending(x => x.PostedOn));
        }
Exemplo n.º 11
0
        public void GetRoadsShouldReturnAllRoads()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetRoads_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var roads = new List <Road> {
                new Road {
                    RoadName = "Road1"
                }, new Road {
                    RoadName = "Road2"
                }, new Road {
                    RoadName = "Road3"
                }
            };

            dbContext.Roads.AddRange(roads);
            dbContext.SaveChanges();

            var returnCollection = roadsService.GetRoads();

            Assert.Equal(returnCollection.Count, roads.Count);
        }
Exemplo n.º 12
0
        public void AddCommentToRoadShouldAddCommentToTheGivenRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddCommentToRoad_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);


            var user = new User
            {
                UserName = "******",
                Roads    = new List <Road>
                {
                    new Road
                    {
                        Id       = "RoadId1",
                        RoadName = "Lorem",
                    }
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var result = commentsService.AddCommentToRoad("RoadId1", user, 4, "none");

            Assert.Single(dbContext.Comments);
            Assert.True(result);
        }
Exemplo n.º 13
0
 public void DeleteRoad(Road road)
 {
     try
     {
         Logger.LogNewMessage($"Deleting road with id {road.Id}", LogType.INFO);
         RoadsService.DeleteRoad(road.Id);
     }
     catch (Exception ex)
     {
         Logger.LogNewMessage($"Error getting road with id {road.Id}. Message  {ex.Message}", LogType.ERROR);
     }
 }
Exemplo n.º 14
0
        public void GetTopRoadsShouldReturnRoadsWithMostAverateRating()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetTopRoads_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentOne = new Comment {
                Content = "Loremipsium", Rating = 5
            };
            var commentTwo = new Comment {
                Content = "Loremipsium", Rating = 3
            };
            var commentThree = new Comment {
                Content = "Loremipsium", Rating = 4
            };

            dbContext.Comments.AddRange(commentOne, commentTwo, commentThree);
            dbContext.SaveChanges();

            var roads = new List <Road>
            {
                new Road {
                    RoadName = "Road1", Comments = new List <Comment>()
                    {
                        commentOne
                    }
                },
                new Road {
                    RoadName = "Road2", Comments = new List <Comment>()
                    {
                        commentTwo
                    }
                },
                new Road {
                    RoadName = "Road3", Comments = new List <Comment>()
                    {
                        commentThree
                    }
                }
            };

            dbContext.Roads.AddRange(roads);
            dbContext.SaveChanges();

            var result = roadsService.GetTopRoads();

            Assert.Equal(result, roads.OrderByDescending(x => x.AverageRating));
        }
Exemplo n.º 15
0
 public Road GetRoadPreviousState(int id)
 {
     try
     {
         Logger.LogNewMessage($"Getting previous state for road with id {id}", LogType.INFO);
         return(RoadsService.GetRoadById(id));
     }
     catch (Exception ex)
     {
         Logger.LogNewMessage($"Error getting road with id {id}. Message  {ex.Message}", LogType.ERROR);
         return(null);
     }
 }
Exemplo n.º 16
0
 public void UpdateRoad(Road road)
 {
     try
     {
         Logger.LogNewMessage($"Updating road with name {road.Name}", LogType.INFO);
         //road.Stations = SelectedStations;
         RoadsService.UpdateRoad(road);
         Window.Close();
     }
     catch (Exception ex)
     {
         Logger.LogNewMessage($"Error updating road {road.Name}. Message  {ex.Message}", LogType.ERROR);
     }
 }
Exemplo n.º 17
0
 public Road AddNewRoad(Road road)
 {
     try
     {
         Logger.LogNewMessage($"Adding new road with name {road.Name}", LogType.INFO);
         //road.Stations = SelectedStations;
         var road_added = RoadsService.AddRoad(road);
         Window.Close();
         return(road_added);
     }catch (Exception ex)
     {
         Logger.LogNewMessage($"Error adding road {road.Name}. Message  {ex.Message}", LogType.ERROR);
         return(null);
     }
 }
Exemplo n.º 18
0
        public void GetRoadRoadByIdShouldReturnRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetRoadsById_Roads_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var road = new Road
            {
                RoadName = "Lorem"
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var result = roadsService.GetRoadById(road.Id);

            Assert.Equal(road, result);
        }
Exemplo n.º 19
0
        public void DeleteCommentAndItsRepliesShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteCommentAndItsReplies_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var user = new User
            {
                UserName = "******"
            };
            var comment = new Comment
            {
                Content = "comment1",
                Id      = "commentId1",
                Replies = new List <Reply>
                {
                    new Reply
                    {
                        Id = "replyId1",
                    }
                },
                User = user
            };

            dbContext.Users.Add(user);
            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();

            var result = commentsService.DeleteCommentAndItsReplies(comment.Id);

            Assert.True(result);
            Assert.True(comment.IsDeleted);
        }
Exemplo n.º 20
0
        public void GetCommentByIdShouldReturnComment()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetCommentId_Roads_Comments_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var road = new Road
            {
                Id       = "Road1",
                RoadName = "Lorem",
                Comments = new List <Comment>
                {
                    new Comment
                    {
                        Id      = "commentId1",
                        Content = "comment1"
                    },
                    new Comment
                    {
                        Id      = "commentId2",
                        Content = "comment2"
                    }
                }
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var comment = commentsService.GetCommentById("commentId1");

            Assert.Equal("comment1", comment.Content);
            Assert.NotNull(comment);
        }
Exemplo n.º 21
0
        public void AddImagesToRoadShouldAddImagesToTheGivenRoad()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddImageToRoad_Road_Image_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var imageService = new Mock <IImageService>();

            imageService.Setup(x => x.AddPhoto(It.IsAny <IFormFile>())).Returns(new Image
            {
                PublicId  = "PublicId",
                Name      = "123",
                DateAdded = DateTime.UtcNow,
                Id        = Convert.ToString(Guid.NewGuid()),
                ImageUrl  = "http://www.url.com/",
            });


            var roadsService = new RoadsService(dbContext, imageService.Object, null, null, null, null);


            var road = new Road
            {
                RoadName = "RoadOne"
            };

            dbContext.Roads.Add(road);
            dbContext.SaveChanges();

            var images = GenerateFiles();

            var result = roadsService.AddImagesToRoad(images, road.Id);

            Assert.True(result);
        }
Exemplo n.º 22
0
 public RoadsController(DistrictPlannerContext context)
 {
     _roadsService = new RoadsService(context);
 }
Exemplo n.º 23
0
 public GoogleRoadsTests()
 {
     fixture = new RoadsService(GOOGLE_PLACES_API_KEY);
 }