public void PartialUpdateRestaurant_NonExistingID_Fail()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = 200,
                Name         = "New Name"
            };
            var expectedResponse = new UpdateRestaurantResponseModel {
                WasSucessfull = false
            };

            var updateRestTran = new PartialUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            //assert
            Assert.AreEqual(expectedResponse.WasSucessfull, actualResponse.WasSucessfull, "Invalid execution status");
        }
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Restaurants.Clear();
                var restaurants = await DataStore.GetItemsAsync(true);

                foreach (var restaurant in restaurants)
                {
                    Restaurants.Add(restaurant);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #3
0
        public void CompleteUpdateRestaurant_ValidIDUpdateCuisine_Succeed()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var expectedID          = 2;
            var expectedName        = "Restaurant Two";
            var expectedCuisine     = Cuisines[2].Id;
            var expectedCreatedById = 102;
            var expectedUpdatedById = 103;
            var restToUpdate        = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = expectedID,
                Name         = expectedName,
                CuisineId    = expectedCuisine
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            var expectedResponse = new UpdateRestaurantResponseModel {
                WasSucessfull = true
            };

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            //assert
            Assert.AreEqual(expectedResponse.WasSucessfull, actualResponse.WasSucessfull, "Invalid execution status");

            ValidateRestUpdate(expectedID, expectedName, expectedCuisine, expectedCreatedById, expectedUpdatedById, restToUpdate);
        }
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            #region load data from XML
            StreamResourceInfo sr = Application.GetResourceStream(new Uri(@"SampleData\restaurants.xml", UriKind.Relative));
            using (TextReader reader = new StreamReader(sr.Stream))
            {
                XmlSerializer serializer  = new XmlSerializer(typeof(ObservableCollection <Restaurant>));
                var           restaurants = (ObservableCollection <Restaurant>)serializer.Deserialize(reader);


                var rt = new Rot13Table();
                foreach (var r in restaurants)
                {
                    Restaurants.Add(r);
                    //r.Text = rt.Transform(r.Text);
                    //r1.Add(r);
                }


                //var serializer1 = new XmlSerializer(typeof(List<Restaurant>));
                //var writer = new System.IO.StringWriter();
                //serializer1.Serialize(writer, r1);
                //var a = writer.ToString();
            }
            #endregion



            this.IsDataLoaded = true;
        }
 public void LoadRestaurants()
 {
     Restaurants.Add(new Restaurant(1, "Ilden", "Roskilde", 50));
     Restaurants.Add(new Restaurant(2, "Jensen's Bøfhus", "Holbæk", 60));
     Restaurants.Add(new Restaurant(3, "Karma Sushi", "København", 70));
     Restaurants.Add(new Restaurant(4, "Siang Jiang", "Slagelse", 50));
 }
        public void RemoveRestaurant_NonExistingID_Fail()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 101, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });

            var restaruntToRemove = new RemoveRestaurantRequestModel {
                UserId = 103, RestaurantId = 25
            };
            var removeRestTran = new RemoveRestaurantTransaction(Repo, Log, restaruntToRemove);

            var expectedResponse = new RemoveRestaurantResponseModel {
                WasSucessfull = false
            };

            //act
            removeRestTran.Execute();
            var actualResponse = removeRestTran.Response;

            //assert
            Assert.AreEqual(expectedResponse.WasSucessfull, actualResponse.WasSucessfull, "Invalid execution status");
            Assert.IsFalse(RestaurantExists(restaruntToRemove), "Restaurant not found");
        }
 public void LoadRestaurants()
 {
     Restaurants.Add(new Restaurant(1, "Flammen", "Roskilde", 50));
     Restaurants.Add(new Restaurant(2, "Ilden", "Roskilde", 70));
     Restaurants.Add(new Restaurant(3, "Moehr", "Roskilde", 60));
     Restaurants.Add(new Restaurant(4, "Bone's", "Roskilde", 50));
     Restaurants.Add(new Restaurant(5, "La Rustica", "Roskilde", 60));
 }
Example #8
0
        public static void AddRestaurant(string name)
        {
            var restautant = new Restaurant(name, CurrentUser);

            Restaurants.Add(restautant);
            SaveSystem.SaveRestsToFile();
            CurrentRestaurant = restautant;
            SetRestaurantRights();
        }
Example #9
0
        public void CompleteUpdateRestaurant_WithExistingReviews_Succeed()
        {
            Users.Add(new User {
                Id = 1, FirstName = "Ruchira", LastName = "Kumara", UserName = "******"
            });
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });

            var expectedCuisine     = Cuisines[0].Id;
            var expectedCreatedById = 102;
            var expectedUpdatedById = Users[0].Id;

            Restaurants[1].AddReview(new Review
            {
                CreatedBy      = 4,
                UpdatedBy      = 4,
                Comment        = "First Comment for 3",
                Rating         = 3,
                PostedDateTime = new DateTime(2016, 10, 16),
                ReviewNumber   = 2,
                ReviewUser     = Users[0]
            });
            Restaurants[1].AddReview(new Review
            {
                CreatedBy      = 3,
                UpdatedBy      = 3,
                Comment        = "Second Comment for 3",
                Rating         = 5,
                PostedDateTime = new DateTime(2016, 10, 10),
                ReviewNumber   = 3,
                ReviewUser     = Users[0]
            });

            var expectedID   = 2;
            var expectedName = "New Restaurant Name";
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = expectedUpdatedById,
                CuisineId    = expectedCuisine,
                RestaurantId = expectedID,
                Name         = expectedName
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            Assert.AreEqual(true, actualResponse.WasSucessfull, "Invalid response");
            ValidateRestUpdate(expectedID, expectedName, expectedCuisine, expectedCreatedById, expectedUpdatedById, restToUpdate);
        }
        public void AddResturant_WithExistingNameSame_ResturantExistExceptionThrown()
        {
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name one", CreatedBy = 100, UpdatedBy = 100, Cuisine = Cuisines[0], Id = 1
            });
            var reqData = new AddRestaurantRequestModel()
            {
                Name      = "Restaurant name one",
                CuisineId = Cuisines[1].Id,
                UserId    = 1
            };

            var sut = new AddRestaurantTransaction(Repo, Log, reqData);

            sut.Execute();

            ExistingResturantAssert(sut);
        }
Example #11
0
        //public override async Task OnNavigatedToAsync(object parameter, navigationmode mode, idictionary<string, object> state)
        //{
        //    // defaults
        //    price1checked = true;
        //    price2checked = true;
        //    star2checked = true;
        //    star3checked = true;
        //    selectedcuisine = "indian";
        //    distance = 1;
        //    await searchasync();
        //}

        public async Task SearchAsync()
        {
            var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource());
            await Task.Factory.StartNew(async() =>
            {
                // TODO: convert distance number to kilos
                var restaurants = await _dataService.GetReataurantsAsync();
                if (!source.Token.IsCancellationRequested)
                {
                    DispatcherWrapper.Current().Dispatch(() =>
                    {
                        Restaurants.Clear();
                        foreach (var restaurant in restaurants)
                        {
                            Restaurants.Add(restaurant);
                        }
                    });
                }
            }, source.Token);
        }
Example #12
0
 public async Task DisplayResults()
 {
     var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource());
     await Task.Factory.StartNew(() =>
     {
         _dataService.CuisineType = CuisineType;
         var restaurants          = _dataService.listOfRestaurants().Result;
         if (!source.Token.IsCancellationRequested)
         {
             DispatcherWrapper.Current().Dispatch(() =>
             {
                 Restaurants.Clear();
                 foreach (var restaurant in restaurants)
                 {
                     Restaurants.Add(restaurant);
                 }
             });
         }
     }, source.Token);
 }
Example #13
0
        public void CompleteUpdateRestaurant_NonExistingID_Fail()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = 200,
                Name         = "New Name"
            };

            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
        }
Example #14
0
        public void CompleteUpdateRestaurant_ValidIDWithBlankUpdatePaddedName_Succeed()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var expectedID   = 2;
            var expectedName = "New Restaurant Name";
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = expectedID,
                Name         = "  " + expectedName + "   "
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
        }
Example #15
0
        public AddReviewTests()
        {
            Cuisines.Add(new Cuisine {
                Id = 1, Name = "Indian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 2, Name = "Armenian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 3, Name = "Italian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 4, Name = "Cajun", CreatedBy = 2, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 5, Name = "Mexican", CreatedBy = 2, UpdatedBy = 1
            });

            Restaurants.Add(new Restaurant {
                Name = "Restaurant name one", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[0], Id = 1
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Two", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[0], Id = 2
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Three", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[1], Id = 3
            });

            Users.Add(new User {
                Id = 1
            });
            Users.Add(new User {
                Id = 2
            });
            Users.Add(new User {
                Id = 3
            });
        }
Example #16
0
        public ViewReviesTests()
        {
            Cuisines.Add(new Cuisine {
                Id = 1, Name = "Indian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 2, Name = "Armenian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 3, Name = "Italian", CreatedBy = 1, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 4, Name = "Cajun", CreatedBy = 2, UpdatedBy = 1
            });
            Cuisines.Add(new Cuisine {
                Id = 5, Name = "Mexican", CreatedBy = 2, UpdatedBy = 1
            });

            Restaurants.Add(new Restaurant {
                Name = "Restaurant name one", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[0], Id = 1
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Two", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[0], Id = 2
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Three", CreatedBy = 1, UpdatedBy = 1, Cuisine = Cuisines[1], Id = 3
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Four", CreatedBy = 2, UpdatedBy = 2, Cuisine = Cuisines[1], Id = 4
            });
            Restaurants.Add(new Restaurant {
                Name = "Restaurant name Five", CreatedBy = 2, UpdatedBy = 1, Cuisine = Cuisines[3], Id = 5
            });


            Users.Add(new User {
                Id = 1
            });
            Users.Add(new User {
                Id = 2
            });
            Users.Add(new User {
                Id = 3
            });
            Users.Add(new User {
                Id = 4
            });
            Users.Add(new User {
                Id = 5
            });
            Users.Add(new User {
                Id = 6
            });
            Users.Add(new User {
                Id = 7
            });
            Users.Add(new User {
                Id = 8
            });
            Users.Add(new User {
                Id = 9
            });
            Users.Add(new User {
                Id = 10
            });
            Users.Add(new User {
                Id = 11
            });

            //restaurant 2 setup
            Reviews.Add(new Review
            {
                CreatedBy  = 3,
                ReviewUser = Users[2],
                UpdatedBy  = 3,
                //ReviewRestaurant = Restaurants[1],
                Comment        = "Comment for 2",
                Rating         = 3,
                PostedDateTime = new DateTime(2016, 10, 16),
                ReviewNumber   = 1,
            });
            Restaurants[1].AddReview(Reviews[0]);//rest ID 2

            //restaurant 3 setup
            Reviews.Add(new Review
            {
                CreatedBy      = 4,
                UpdatedBy      = 4,
                Comment        = "First Comment for 3",
                Rating         = 3,
                PostedDateTime = new DateTime(2016, 10, 16),
                ReviewNumber   = 2,
                ReviewUser     = Users[3]
            });
            Reviews.Add(new Review
            {
                CreatedBy      = 3,
                UpdatedBy      = 3,
                Comment        = "Second Comment for 3",
                Rating         = 5,
                PostedDateTime = new DateTime(2016, 10, 10),
                ReviewNumber   = 3,
                ReviewUser     = Users[2]
            });
            Restaurants[2].AddReview(Reviews[1]);
            Restaurants[2].AddReview(Reviews[2]);

            //restaurant 4 setup
            for (var i = 0; i < 10; i++)
            {
                var newReview = new Review
                {
                    CreatedBy      = Users[i].Id,
                    UpdatedBy      = Users[i].Id,
                    Comment        = $"Comment {i} for Restaurant 4",
                    Rating         = (i % 5) + 1,
                    PostedDateTime = new DateTime(2016, 09, i + 1),
                    ReviewNumber   = 4 + i,
                    ReviewUser     = Users[i]
                };
                // 0+1 to 4+1

                Reviews.Add(newReview);

                Restaurants[3].AddReview(Reviews[3 + i]);
            }
        }
Example #17
0
 public void Add(Restaurant restaurant)
 {
     Restaurants.Add(restaurant);
 }
Example #18
0
 public Restaurant AddRestaurant(Restaurant restaurant)
 {
     restaurant.Id = Restaurants.Max(r => r.Id) + 1;
     Restaurants.Add(restaurant);
     return(restaurant);
 }
        //made it a task to not hinder loading which is long enough as it is
        public async Task Initialize()
        {
            var test = Database.GetPendingMigrations();

            if (Database.GetPendingMigrations().Any())
            {
                await Database.MigrateAsync();
            }

            //init roles
            if (Roles.ToList().Count < 3)
            {
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("Admin")
                {
                    Id = "Admin", NormalizedName = "ADMIN"
                });
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("Manager")
                {
                    Id = "Manager", NormalizedName = "MANAGER"
                });
                Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole("User")
                {
                    Id = "User", NormalizedName = "USER"
                });
            }
            //init user roles
            if (UserRoles.ToList().Count < 3)
            {
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var adminUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == adminUser.Id))
                    {
                        var adminRole = Roles.First(r => r.Name == "Admin");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = adminUser.Id, RoleId = adminRole.Id
                        });
                    }
                }
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var managerUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == managerUser.Id))
                    {
                        var managerRole = Roles.First(r => r.Name == "Manager");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = managerUser.Id, RoleId = managerRole.Id
                        });
                    }
                }
                if (Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var userUser = Users.First(u => u.Email == "*****@*****.**");
                    if (!UserRoles.Any(ur => ur.UserId == userUser.Id))
                    {
                        var userRole = Roles.First(r => r.Name == "User");
                        UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <string> {
                            UserId = userUser.Id, RoleId = userRole.Id
                        });
                    }
                }
            }
            //init some restaurants
            if (Restaurants.ToList().Count < 3)
            {
                Restaurants.Add(new Restaurant("Pizzeria Italiano", "Szlak 34 Kraków"));
                Restaurants.Add(new Restaurant("Hong bao", "Chinatown 120 Chicago"));
                Restaurants.Add(new Restaurant("Wiejskie smaczki", "Wiejska 3 Warszawa"));
            }
            //init some managers
            if (RestaurantManagers.ToList().Count < 3)
            {
                RestaurantManagers.Add(new RestaurantManager(0, "Maciek", "Kowalski", 45));
                RestaurantManagers.Add(new RestaurantManager(0, "Przemek", "Nowak", 35));
                RestaurantManagers.Add(new RestaurantManager(0, "Zdzisław", "Jankowksi", 55));
            }
            //init some cuisine types
            if (CuisineTypes.ToList().Count < 3)
            {
                CuisineTypes.Add(new CuisineType(0, "Chinesse", "China"));
                CuisineTypes.Add(new CuisineType(0, "Fusion", null));
                CuisineTypes.Add(new CuisineType(0, "Italian", "Italy"));
            }
            //init some dishes
            if (Dishes.ToList().Count < 3)
            {
                Dishes.Add(new Dish(0, "Lasagne", MealType.Meat));
                Dishes.Add(new Dish(0, "Fish and chips", MealType.Fish));
                Dishes.Add(new Dish(0, "Fried vegetables", MealType.Vegan));
            }
            //init some discount type
            if (DiscountTypes.ToList().Count < 1)
            {
                DiscountTypes.Add(new DiscountType(0, "Early birds", 8, 16)
                {
                    Amount = 0.2m
                });
            }
            //can we init users from here?
            SaveChanges();
        }
 public void AddRestaurant(Restaurant res)
 {
     Restaurants.Add(res);
 }