public void MostPopularPhotoShown()
        {
            var cafe = new Cafe
                {
                    Photos = new[]
                        {
                            new Photo
                            {
                                SubmittedBy = "Tom",
                                NumberOfVotes = 2
                            },
                            new Photo
                            {
                                SubmittedBy = "Dick",
                                NumberOfVotes = 5
                            },
                            new Photo
                            {
                                SubmittedBy = "Harry",
                                NumberOfVotes = 3
                            }
                        }
                };

            var result = new CafeSummaryViewModel(cafe, new MockNavigationService());

            Assert.IsNotNull(result.Photo);
            Assert.AreEqual("Dick", result.Photo.SubmittedBy);
        }
 public static void NavigateToCoffeeDetails(this INavigationService navigationService, Cafe cafe)
 {
     navigationService.Navigate(
         "CafeDetails",
         new Dictionary<string, object>
         {
             { "Id", cafe.Id }
         });
 }
        public void NavigateToCafeDetails()
        {
            var navigationService = new MockNavigationService();
            var cafe = new Cafe { Id = "1" };
            var item = new CafeSummaryViewModel(cafe, navigationService);

            item.Navigate.Execute(null);

            Assert.AreEqual("CafeDetails", navigationService.Current.Location);
            Assert.AreEqual("1", navigationService.Current.Parameters["Id"]);
        }
        public void CannotSubmitIfUnchangedSinceLastSubmit()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "5" };
                context.DataService.Cafes.Add(cafe);

                context.IdentityService.SetCurrentIdentity("UserA");
                context.ViewModel.AssociatedCafe = cafe;
                context.ViewModel.Comment = "Great!";

                context.ViewModel.Submit.Execute(null);
                context.ViewModel.Comment = "Great!";

                Assert.IsFalse(context.ViewModel.Submit.CanExecute(null));
            }
        }
        public void PhotosPopulatedWhenNavigatedTo()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe
                    {
                        Id = "1",
                        Photos = new[]
                        {
                            new Photo
                            {
                                SubmittedBy = "Tom",
                                NumberOfVotes = 2
                            },
                            new Photo
                            {
                                SubmittedBy = "Dick",
                                NumberOfVotes = 5
                            },
                            new Photo
                            {
                                SubmittedBy = "Harry",
                                NumberOfVotes = 3
                            }
                        }
                    };
                context.Cafes.Add(cafe);

                context.NavigateTo(cafe.Id);

                var expected = cafe.Photos
                    .OrderByDescending(photo => photo.NumberOfVotes)
                    .ToArray();
                CollectionAssert.AreEqual(
                    expected.Select(p => p.SubmittedBy).ToArray(),
                    context.ViewModel.Photos.Select(p => p.SubmittedBy).ToArray());
            }
        }
        public void PropertiesPopulatedFromModel()
        {
            var cafe = new Cafe
                {
                    Name = "Coffee Shop",
                    Address = "1 Main Street",
                    PostCode = "A1",
                    Longitude = 45,
                    Latitude = -12,
                    CoffeeRating = 3.5,
                    AtmosphereRating = 4.5,
                    NumberOfVotes = 12
                };

            var result = new CafeSummaryViewModel(cafe, new MockNavigationService());

            Assert.AreEqual("Coffee Shop", result.Name, "Name");
            Assert.AreEqual("1 Main Street", result.Address, "Address");
            Assert.AreEqual(45, result.Longitude, "Longitude");
            Assert.AreEqual(-12, result.Latitude, "Latitude");
            Assert.AreEqual(4, result.Rating, "Rating");
            Assert.AreEqual(12, result.NumberOfVotes, "NumberOfVotes");
        }
        public void SubmittedIdentityReviewDoesNotUpdatesReviewCollectionIfNoComment()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);

                context.NavigateTo(cafe.Id);
                Assert.AreEqual(0, context.ViewModel.Reviews.Count);

                context.IdentityService.SetCurrentIdentity("UserA");
                context.ViewModel.CurrentIdentityReview.CoffeeRating = 3;
                context.ViewModel.CurrentIdentityReview.Submit.Execute(null);

                Assert.IsFalse(context.ViewModel.Reviews.Any());
            }
        }
        public void SubmittedIdentityReviewUpdatesVoteSummary()
        {
            using (var context = new Context())
            {
                context.IdentityService.SetCurrentIdentity("Me");

                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review
                            {
                                Id = Guid.NewGuid().ToString(),
                                CoffeeRating = 2,
                                AtmosphereRating = 4,
                                SubmittedBy = "SomebodyElse"
                            }
                    };

                context.NavigateTo(cafe.Id);

                context.ViewModel.CurrentIdentityReview.CoffeeRating = 4;
                context.ViewModel.CurrentIdentityReview.AtmosphereRating = 2;
                context.ViewModel.CurrentIdentityReview.Submit.Execute(null);
                Assert.AreEqual(2, context.ViewModel.NumberOfVotes);
                Assert.AreEqual(3, context.ViewModel.CoffeeRating);
                Assert.AreEqual(3, context.ViewModel.AtmosphereRating);
            }
        }
        public void SubmittedIdentityReviewUpdatesReviewCollectionIfCommentSupplied()
        {
            using (var context = new Context())
            {
                context.IdentityService.SetCurrentIdentity("Me"); ;

                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);

                context.ViewModel.CurrentIdentityReview.Comment = "My review";
                context.ViewModel.CurrentIdentityReview.Submit.Execute(null);

                Assert.AreEqual(1, context.ViewModel.Reviews.Count);
                var review = context.ViewModel.Reviews.First();
                Assert.AreEqual("My review", review.Comment);
                Assert.AreEqual("Me", review.SubmittedBy);

                context.ViewModel.CurrentIdentityReview.Comment = "My updated review!";
                context.ViewModel.CurrentIdentityReview.Submit.Execute(null);

                Assert.AreEqual(1, context.ViewModel.Reviews.Count);
                review = context.ViewModel.Reviews.First();
                Assert.AreEqual("My updated review!", review.Comment);
                Assert.AreEqual("Me", review.SubmittedBy);
            }
        }
        public void IdentityReviewResetIfNoReviewByCurrentIdentity()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review
                        {
                            Comment = "Somebody else's opinion",
                            CoffeeRating = 1,
                            AtmosphereRating = 3,
                            SubmittedBy = "SomebodyElse"
                        }
                    };

                context.IdentityService.SetCurrentIdentity("SomebodyElse"); ;
                context.NavigateTo(cafe.Id);

                context.IdentityService.SetCurrentIdentity("Me"); ;
                context.NavigateTo(cafe.Id);

                Assert.IsNull(context.ViewModel.CurrentIdentityReview.Comment);
                Assert.IsNull(context.ViewModel.CurrentIdentityReview.CoffeeRating);
                Assert.IsNull(context.ViewModel.CurrentIdentityReview.AtmosphereRating);
            }
        }
        public void ReviewsSortedNewestToOldest()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review
                        {
                            Comment = "Yesterday",
                            SubmittedDate = DateTime.Today.AddDays(-1)
                        },
                        new Review
                        {
                            Comment = "Ancient!",
                            SubmittedDate = DateTime.Today.AddYears(-5)
                        },
                        new Review
                        {
                            Comment = "Today",
                            SubmittedDate = DateTime.Today
                        }
                    };

                context.NavigateTo(cafe.Id);

                Assert.AreEqual("Today", context.ViewModel.Reviews[0].Comment);
                Assert.AreEqual("Yesterday", context.ViewModel.Reviews[1].Comment);
                Assert.AreEqual("Ancient!", context.ViewModel.Reviews[2].Comment);
            }
        }
 private void PopulatePhoto(Cafe model)
 {
     this.photo = model.Photos
                         .OrderByDescending(p => p.NumberOfVotes)
                         .FirstOrDefault();
 }
        public void IdentityReviewPopulatedWithLatestReviewByCurrentIdentity()
        {
            using (var context = new Context())
            {
                context.IdentityService.SetCurrentIdentity("Me");

                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review
                        {
                            Comment = "My latest review!",
                            CoffeeRating = 2,
                            AtmosphereRating = 4,
                            SubmittedBy = "Me",
                            SubmittedDate = DateTime.Today.AddMonths(-1)
                        },
                        new Review
                        {
                            Comment = "My ancient review",
                            CoffeeRating = 1,
                            AtmosphereRating = 1,
                            SubmittedBy = "Me",
                            SubmittedDate = DateTime.Today.AddYears(-3)
                        }
                    };

                context.NavigateTo(cafe.Id);

                Assert.AreEqual("My latest review!", context.ViewModel.CurrentIdentityReview.Comment);
                Assert.AreEqual(2, context.ViewModel.CurrentIdentityReview.CoffeeRating);
                Assert.AreEqual(4, context.ViewModel.CurrentIdentityReview.AtmosphereRating);
            }
        }
        public void ShareCafe()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe
                    {
                        Name = "Coffee Shop",
                        Address = "1 Main Street",
                        PostCode = "X1 XXX"
                    };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);

                context.ViewModel.Share.Execute(null);

                Assert.AreEqual(1, context.ShareSource.SharedPackages.Count);
                Assert.AreEqual("Coffee Shop", context.ShareSource.SharedPackages.Last().Title);
                Assert.AreEqual("1 Main Street, X1 XXX", context.ShareSource.SharedPackages.Last().Text);
            }
        }
        public void SubmittingSkippedIfAuthenticationFailed()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "5" };
                context.DataService.Cafes.Add(cafe);

                context.IdentityService.ClearCurrentIdentity();
                context.IdentityService.AuthenticationRequested +=
                    (sender, args) => args.Fail();

                context.ViewModel.AssociatedCafe = cafe;
                context.ViewModel.Comment = "Good stuff";
                context.ViewModel.Submit.Execute(null);

                Assert.IsFalse(context.DataService.Reviews.ContainsKey(cafe));
            }
        }
        public void SubmittingSkipsSaveIfNothingToSubmitAfterTrimming()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "5" };
                context.DataService.Cafes.Add(cafe);

                context.IdentityService.SetCurrentIdentity("UserA");
                context.ViewModel.AssociatedCafe = cafe;
                context.ViewModel.Comment = "   ";
                context.ViewModel.CoffeeRating = null;
                context.ViewModel.AtmosphereRating = null;
                context.ViewModel.Submit.Execute(null);

                Assert.IsFalse(context.DataService.Reviews.ContainsKey(cafe));
            }
        }
        public void ShowDirections()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe
                            {
                                Id = "1",
                                Name = "Coffee Shop",
                                Longitude = 45.15,
                                Latitude = 15.45
                            };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);

                context.ViewModel.ShowDirections.Execute(null);

                Assert.IsNotNull(context.MapLauncher.LastLaunch);
                Assert.AreEqual("Coffee Shop", context.MapLauncher.LastLaunch.Name);
                Assert.AreEqual(45.15, context.MapLauncher.LastLaunch.Longitude);
                Assert.AreEqual(15.45, context.MapLauncher.LastLaunch.Latitude);
            }
        }
        public void SubmittingTrimsComment()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "5" };
                context.DataService.Cafes.Add(cafe);

                context.IdentityService.SetCurrentIdentity("UserA");
                context.ViewModel.AssociatedCafe = cafe;
                context.ViewModel.Comment = " Love  it!  ";
                context.ViewModel.Submit.Execute(null);

                var review = context.DataService.Reviews[cafe].Single();
                Assert.AreEqual("Love  it!", review.Comment, "Comment");
            }
        }
 private void Populate(Cafe model)
 {
     this.Name = model.Name;
     this.Address = model.Address;
     this.Longitude = model.Longitude;
     this.Latitude = model.Latitude;
     this.Rating = (model.CoffeeRating + model.AtmosphereRating) / 2;
     this.NumberOfVotes = model.NumberOfVotes;
 }
 public CafeSummaryViewModel(Cafe model, INavigationService navigationService)
 {
     this.Navigate = new NavigateToCafeDetailsCommand(model, navigationService);
     this.Populate(model);
     this.PopulatePhoto(model);
 }
        public void CannotSubmitReviewBeforeNavigating()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);

                context.IdentityService.SetCurrentIdentity("UserA");
                context.ViewModel.CurrentIdentityReview.Comment = "Something";
                context.ViewModel.CurrentIdentityReview.CoffeeRating = 3;
                context.ViewModel.CurrentIdentityReview.AtmosphereRating = 4.5;

                Assert.IsFalse(context.ViewModel.CurrentIdentityReview.Submit.CanExecute(null));
            }
        }
        public void SubmittingSetsSubmissionProperties()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "5" };
                context.DataService.Cafes.Add(cafe);

                context.IdentityService.SetCurrentIdentity("Jim");
                context.ViewModel.AssociatedCafe = cafe;
                context.ViewModel.Comment = "Tasted better";
                context.ViewModel.Submit.Execute(null);

                Assert.AreEqual("Jim", context.ViewModel.SubmittedBy);
                Assert.IsNotNull(context.ViewModel.SubmittedDate);
            }
        }
        public async Task IsAuthenticationRequired()
        {
            using (var context = new Context())
            {
                context.IdentityService.ClearCurrentIdentity();

                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);
                Assert.IsTrue(context.ViewModel.IsAuthenticationRequired);

                context.IdentityService.AuthenticationRequested +=
                    (sender, args) => args.Success("Me");
                await context.IdentityService.AuthenticateAsync();
                Assert.IsFalse(context.ViewModel.IsAuthenticationRequired);
            }

            using (var context = new Context())
            {
                context.IdentityService.SetCurrentIdentity("Me");

                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);
                Assert.IsFalse(context.ViewModel.IsAuthenticationRequired);
            }
        }
Пример #24
0
 private CafeSummaryViewModel CreateCafeSummary(Cafe cafe)
 {
     return new CafeSummaryViewModel(cafe, this.navigationService);
 }
        public void NavigateToMap()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe
                {
                    Id = "1",
                    Name = "Coffee Shop",
                    Longitude = 45.15,
                    Latitude = 15.45
                };
                context.Cafes.Add(cafe);
                context.NavigateTo(cafe.Id);

                context.ViewModel.NavigateToMap.Execute(null);

                Assert.AreEqual("Map", context.NavigationService.Current.Location);
                Assert.AreEqual("1", context.NavigationService.Current.Parameters["Id"]);
            }
        }
Пример #26
0
        private void Populate(Cafe cafe)
        {
            this.CurrentIdentityReview.AssociatedCafe = cafe; 

            this.Name = cafe.Name;
            this.RaisePropertyChanged(() => this.Name);

            this.Address = string.Format("{0}, {1}", cafe.Address, cafe.PostCode);
            this.RaisePropertyChanged(() => this.Address);

            this.Longitude = cafe.Longitude;
            this.RaisePropertyChanged(() => this.Longitude);

            this.Latitude = cafe.Latitude;
            this.RaisePropertyChanged(() => this.Latitude);

            this.CoffeeRating = cafe.CoffeeRating;
            this.AtmosphereRating = cafe.AtmosphereRating;
            this.NumberOfVotes = cafe.NumberOfVotes;

            foreach (var photo in cafe.Photos.OrderByDescending(p => p.NumberOfVotes))
            {
                this.Photos.Add(new PhotoViewModel(photo));
            }

            this.shareSource.IsEnabled = true;
            this.Share.Cafe = cafe;
        }
        public void ShareNotExecutableBeforeOrAfterNavigating()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Name = "A" };
                context.Cafes.Add(cafe);

                Assert.IsFalse(context.ViewModel.Share.CanExecute(null));

                context.NavigateTo(cafe.Id);
                Assert.IsTrue(context.ViewModel.Share.CanExecute(null));

                context.ViewModel.OnNavigatedFrom();
                Assert.IsFalse(context.ViewModel.Share.CanExecute(null));
            }
        }
 public NavigateToCafeDetailsCommand(Cafe cafe, INavigationService navigationService)
 {
     this.cafe = cafe;
     this.navigationService = navigationService;
 }
        public void ReviewsPopulatedWhenNavigatedTo()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review { Comment = "Good!" },
                        new Review { Comment = "Bad!" },
                        new Review { Comment = "Ugly!" }
                    };

                context.NavigateTo(cafe.Id);

                CollectionAssert.AreEquivalent(
                    context.Reviews[cafe].Select(r => r.Comment).ToArray(),
                    context.ViewModel.Reviews.Select(r => r.Comment).ToArray());
            }
        }
        public void ReviewsWithoutCommentsSkippedWhenPopulating()
        {
            using (var context = new Context())
            {
                var cafe = new Cafe { Id = "1" };
                context.Cafes.Add(cafe);
                context.Reviews[cafe] = new List<Review>
                    {
                        new Review { Comment = null, CoffeeRating = 5 },
                        new Review { Comment = null, AtmosphereRating = 3 }
                    };

                context.NavigateTo(cafe.Id);

                Assert.IsFalse(context.ViewModel.Reviews.Any());
            }
        }