Example #1
0
        public void AddRouteTest(string expectedEmail, string expectedName, string expectedSurname, string expectedDescription, string expectedAbout
            , double expectedDistance, string expectedPlace, int expectedId)
        {
            // set up test objects

            User expectedUser = new User()
            {
                Email = expectedEmail,
                About = expectedAbout,
                FirstName = expectedName,
                SecondName = expectedSurname
            };

            List<User> expextedSubscribers = new List<User>();
            expextedSubscribers.Add(expectedUser);

            Route expectedRoute = new Route()
            {
                Id = expectedId,
                Author = expectedUser,
                Description = expectedDescription,
                Start = new DateTime(2015, 12, 22),
                Distance = expectedDistance,
                MeetingPlace = expectedPlace,
                Subscribers = expextedSubscribers

            };

            routeRepository.Setup(r => r.Find(It.IsAny<int>())).Returns(expectedRoute);
            userRepository.Setup(r => r.Find(It.IsAny<string>())).Returns(expectedUser);
            routeRepository.Setup(r => r.Add(It.IsAny<Route>() ));
            // check the method
            routeService.Add(expectedRoute);
            routeRepository.Verify(r => r.Add(It.IsAny<Route>()), Times.AtLeastOnce());
        }
Example #2
0
        public void SavedInformationTest(string expectedEmail, string expectedName, string expectedSurname, string expectedDescription, string expectedAbout
            , double expectedDistance, string expectedPlace, int expectedId)
        {
            User expectedUser = new User
            {
                Email = expectedEmail,
                About = expectedAbout,
                FirstName = expectedName,
                SecondName = expectedSurname
            };

            Route expectedRoute = new Route
            {
                Id = expectedId,
                Author = expectedUser,
                Description = expectedDescription,
                Start = new DateTime(2015, 12, 22),
                Distance = expectedDistance,
                MeetingPlace = expectedPlace,

            };

               // routeService.Add();
            routeRepository.Setup(r => r.Find(It.IsAny<int>())).Returns(expectedRoute);

            Route testroute = routeService.Find(1);

            Assert.AreEqual(expectedEmail ,      testroute.Author.Email ,     " Emails are not equal" );
            Assert.AreEqual(expectedName,        testroute.Author.FirstName,  " First Names are not equal");
            Assert.AreEqual(expectedSurname,     testroute.Author.SecondName, " Second Names are not equal");
            Assert.AreEqual(expectedDescription, testroute.Description,       " Descriptions are not equal");
            Assert.AreEqual(expectedAbout,       testroute.Author.About,      " Abouts are not equal");
            Assert.AreEqual(expectedDistance,    testroute.Distance,          " Distances are not equal");
            Assert.AreEqual(expectedPlace,       testroute.MeetingPlace,      " Places are not equal");
            Assert.AreEqual(expectedId,          testroute.Id,                " Ids are not equal");
        }
Example #3
0
 public void Add(Route route)
 {
     this.routeRepository.Add(route);
 }
Example #4
0
        public void CheckIsUserSubscribedToRouteTest(string expectedEmail, string expectedName, string expectedSurname, string expectedDescription, string expectedAbout
            , double expectedDistance, string expectedPlace, int expectedId)
        {
            // set up test objects

            User expectedUser = new User()
            {
                Email = expectedEmail,
                About = expectedAbout,
                FirstName = expectedName,
                SecondName = expectedSurname
            };

            List<User> expextedSubscribers = new List<User>();
            expextedSubscribers.Add(expectedUser);

            Route expectedRoute = new Route()
            {
                Id = expectedId,
                Author = expectedUser,
                Description = expectedDescription,
                Start = new DateTime(2015, 12, 22),
                Distance = expectedDistance,
                MeetingPlace = expectedPlace,
                Subscribers = expextedSubscribers

            };

            routeRepository.Setup(r => r.Find(It.IsAny<int>())).Returns(expectedRoute);
            userRepository.Setup(r => r.Find(It.IsAny<string>())).Returns(expectedUser);

            // check the method

            bool actualResult =   routeService.CheckIsUserSubscribedToRoute(expectedRoute.Id, expectedUser.Id);
            bool expectedResult = true;

            Assert.AreEqual(expectedResult, actualResult, "wrong subscription logic");
        }
Example #5
0
 private RouteData MapRoute(Route route)
 {
     return new RouteData
     {
         Id = route.Id,
         Title = route.Title,
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = route.Distance,
         IsBanned = route.IsBanned,
         AuthorName = route.Author != null ? string.Format("{0} {1}", route.Author.FirstName, route.Author.SecondName) : string.Empty
     };
 }
Example #6
0
 public void Update(Route route)
 {
     this.routeRepository.Update(route);
 }
Example #7
0
 public static Route MapToDomain(RouteViewModel route)
 {
     Route _route = new Route
     {
         Id = route.Id,
         Title = route.Title,
         MapData = JsonConvert.DeserializeObject<MapData>(route.MapData),
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = Double.Parse(route.Distance, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo),
         //Author = JsonConvert.DeserializeObject<User>(route.Author),
         //Subscribers = JsonConvert.DeserializeObject<List<User>>(route.Subscribers),
         IsBanned = route.IsBanned
     };
     return _route;
 }
Example #8
0
 public Route MapToDomain()
 {
     //TODO: Use Automapper for mapping
     Route _route = new Route
     {
         Id = this.Id,
         Title = this.Title,
         MapData = JsonConvert.DeserializeObject<MapData>(this.MapData),
         Description = this.Description,
         MeetingPlace = this.MeetingPlace,
         Start = this.Start,
         Distance = Double.Parse(this.Distance, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo),
         //Author = JsonConvert.DeserializeObject<User>(this.Author),
         //Subscribers = JsonConvert.DeserializeObject<List<User>>(this.Subscribers),
         IsBanned = this.IsBanned
     };
     return _route;
 }
Example #9
0
 public static RouteViewModel MapToViewModel(Route route)
 {
     //yes, it's dirty code. it's temporary
     var subscribers = new List<SubscriberViewModel>();
     foreach (var item in route.Subscribers)
     {
         subscribers.Add(new SubscriberViewModel
         {
             Id = item.Id,
             FirstName = item.FirstName,
             SecondName = item.SecondName
         });
     }
     var author = new SubscriberViewModel
         {
             Id = route.Author.Id,
             FirstName = route.Author.FirstName,
             SecondName = route.Author.SecondName
         };
     RouteViewModel _route = new RouteViewModel
     {
         Id = route.Id,
         Title = route.Title,
         MapData = JsonConvert.SerializeObject(route.MapData),
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = route.Distance.ToString(),
         Author = JsonConvert.SerializeObject(author),
         Subscribers = JsonConvert.SerializeObject(subscribers),
         IsBanned = route.IsBanned
     };
     return _route;
 }