public async void LunchRepository_GetUserAsync_GetsUser()
        {
            // arrangec
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            List <string>   nopes   = new List <string> {
                "https://goo.gl/pUu7he"
            };
            var addedUserSettings = context.Users.Add(new UserEntity
            {
                Id       = 1,
                GoogleId = "googleID",
                Name     = "test",
                Nopes    = JsonConvert.SerializeObject(nopes),
                Zip      = "90210"
            }).Entity;

            context.SaveChanges();

            // act
            UserDto result = await target.GetUserAsync(addedUserSettings.GoogleId);

            // assert
            Assert.NotNull(result);
            Assert.Equal(JsonConvert.SerializeObject(nopes), JsonConvert.SerializeObject(result.Nopes));
        }
        public async void LunchRepository_AddUserToTeamAsync_ReturnsWithoutErrorWhenComboAlreadyExists()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity
            {
                Name = "bob's team"
            }).Entity;
            UserEntity user = context.Users.Add(new UserEntity
            {
                Name = "bob"
            }).Entity;

            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user.Id,
                TeamId = team.Id
            });
            context.SaveChanges();


            // act
            await target.AddUserToTeamAsync(user.Id, team.Id);

            // assert
            // no exception thrown
        }
        public async void LunchRepository_AddUserToTeamAsync_AddsUserToTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity
            {
                Name = "bob's team"
            }).Entity;
            UserEntity user = context.Users.Add(new UserEntity
            {
                Name = "bob"
            }).Entity;

            context.SaveChanges();


            // act
            await target.AddUserToTeamAsync(user.Id, team.Id);

            // assert
            var userTeam = context.UserTeams.First();

            Assert.Equal(team.Id, userTeam.TeamId);
            Assert.Equal(user.Id, userTeam.UserId);
        }
        public async void LunchRepository_GetNopesAsync_ReturnsUsersNopes()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            UserEntity      user    = context.Users.Add(new UserEntity
            {
                Name  = "bob",
                Nopes = "['thing1','thing2']",
            }).Entity;
            UserEntity user2 = context.Users.Add(new UserEntity
            {
                Name  = "lilTimmy",
                Nopes = "['thing3','thing1']",
            }).Entity;

            context.SaveChanges();

            IEnumerable <int> ids = context.Users.Select(u => u.Id);

            // act
            IEnumerable <string> result = await target.GetNopesAsync(ids);

            // assert
            Assert.Contains("thing1", result);
            Assert.Contains("thing2", result);
            Assert.Contains("thing3", result);
            Assert.Equal(3, result.Count());
        }
        public async void LunchRepository_UpdateUserAsync_UpdatesUser()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            UserEntity      user    = context.Users.Add(new UserEntity()
            {
                Name  = "Tahra Dactyl",
                Nopes = "[]",
            }).Entity;
            await context.SaveChangesAsync();

            string        name  = "Paul R. Baer";
            List <string> nopes = new List <string> {
                "Chum Bucket", "Jimmy Pesto's Pizzaria"
            };

            // act
            await target.UpdateUserAsync(user.Id, name, nopes, "90210");

            // assert
            UserEntity updatedUser = await context.Users.FirstOrDefaultAsync(u => u.Id == user.Id);

            Assert.Equal(name, updatedUser.Name);
            Assert.Equal(JsonConvert.SerializeObject(nopes), updatedUser.Nopes);
            Assert.Equal("90210", updatedUser.Zip);
        }
        public async void LunchRepository_RemoveUserFromTeamAsync_RemovesUserFromTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity
            {
                Name = "bob's team"
            }).Entity;
            UserEntity user = context.Users.Add(new UserEntity
            {
                Name = "bob"
            }).Entity;

            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user.Id,
                TeamId = team.Id
            });
            context.SaveChanges();


            // act
            await target.RemoveUserFromTeamAsync(user.Id, team.Id);

            // assert
            Assert.Equal(0, context.UserTeams.Count());
        }
Esempio n. 7
0
        public ActionResult Index()
        {
            var thisWeekLunches = LunchRepository.GetLunchesForThisWeek().ToList();
            var user            = UserRepository.GetUserByName(User.Identity.Name);

            if (user == null)
            {
                return(RedirectToAction("LogOff", "Account"));
            }
            var model = new EnrollmentModel()
            {
                MyLunches = new HashSet <Guid>(user.Enrollments.Select(e => e.EnrolledForLunchId)),
                Lunches   = thisWeekLunches
            };

            var userRatings = MealRepository.GetUserRatings(user.Id);
            var meals       = MealRepository.GetAll();
            var ratingModel = new RatingModel()
            {
                Meals       = meals,
                UserRatings = userRatings.ToDictionary(m => m.RatedMealId, m => m.Rating)
            };

            model.RatingModel = ratingModel;

            return(View(model));
        }
        public async void LunchRepository_GetUserByEmailAsync_GetsUser()
        {
            // arrangec
            LunchContext  context = GetContext();
            List <string> nopes   = new List <string> {
                "https://goo.gl/pUu7he"
            };
            var addedUser = context.Users.Add(new UserEntity
            {
                Id       = 1,
                GoogleId = "googleID",
                Name     = "test",
                Email    = "*****@*****.**",
                Nopes    = JsonConvert.SerializeObject(nopes),
                PhotoUrl = "https://gph.is/NYMue5",
                Zip      = "39955",
            }).Entity;

            context.SaveChanges();

            LunchRepository target = new LunchRepository(context);

            // act
            UserDto result = await target.GetUserByEmailAsync(addedUser.Email);

            // assert
            Assert.Equal(addedUser.Email, result.Email);
            Assert.Equal(addedUser.Id, result.Id);
            Assert.Equal(addedUser.Name, result.Name);
            Assert.Equal(addedUser.Nopes, JsonConvert.SerializeObject(result.Nopes));
        }
 public UserController(TrimestrialInfoRepository trimestrialRepo, UserRepository userRepo, ContactRepository contactRepo, UserStatusRepository statusRepo, LunchRepository lunchRepo, ITokenService token)
 {
     _userRepo        = userRepo;
     _contactRepo     = contactRepo;
     _statusRepo      = statusRepo;
     _lunchRepo       = lunchRepo;
     _trimestrialRepo = trimestrialRepo;
 }
 public void AddLunchAsync_DoesNotThrow()
 {
     var config  = new Mock <IConfigurationManager>();
     var repo    = new LunchRepository(config.Object);
     var request = new LunchOptions();
     //var response = await repo.AddLunchAsync(request);
     //Assert.AreEqual(request.SomeRequiredValue, response.SomeRequiredValue);
 }
        public void LunchRepository_Ctor_ReturnsRepository()
        {
            // arrange
            LunchContext context = GetContext();

            // act
            LunchRepository repo = new LunchRepository(context);

            // assert
            Assert.NotNull(repo);
        }
        public async Task GetValueAsync_ReturnsSomeValue()
        {
            var config = new Mock <IConfigurationManager>();

            config.Setup(x => x.GetSetting(It.IsAny <string>())).Returns("some value");

            var repo   = new LunchRepository(config.Object);
            var result = await repo.GetValueAsync(1);

            Assert.AreEqual(result, "some value");
        }
        public async void LunchRepository_GetUserAsync_ReturnsNullWhenUserNotFound()
        {
            // arrangec
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            // act
            UserDto result = await target.GetUserAsync("GoogleId");

            // assert
            Assert.Null(result);
        }
        public async void LunchRepository_GetTeamAsync_ReturnsNullIfTeamDoesNotExist()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            // act
            TeamDto result = await target.GetTeamAsync(8888);

            // assert
            Assert.Null(result);
        }
        public async Task GetIntValue_ReturnsSomeInt()
        {
            var config = new Mock <IConfigurationManager>();

            config.Setup(x => x.GetSetting <int>(It.IsAny <string>(), 0)).Returns(12);

            var repo   = new LunchRepository(config.Object);
            var result = await repo.GetIntValueAsync();

            Assert.IsInstanceOfType(result, typeof(int));
            Assert.AreEqual(result, 12);
        }
        public async void LunchRepository_GetUsersOfTeamAsync_ReturnsNullWhenTeamNotFound()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            // act
            IEnumerable <UserDto> result = await target.GetUsersOfTeamAsync(1);

            // assert
            Assert.Null(result);
        }
        public async void LunchRepository_GetUserAsync_GetsUserWithTeams()
        {
            // arrangec
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            List <string>   nopes   = new List <string> {
                "https://goo.gl/pUu7he"
            };
            var addedUserSettings = context.Users.Add(new UserEntity
            {
                Id       = 1,
                GoogleId = "googleID",
                Name     = "test",
                Nopes    = JsonConvert.SerializeObject(nopes),
                Zip      = "90210"
            }).Entity;

            TeamEntity team1 = context.Teams.Add(new TeamEntity
            {
                Id   = 1,
                Name = "bob's Team",
                Zip  = "38655"
            }).Entity;
            TeamEntity team2 = context.Teams.Add(new TeamEntity
            {
                Id   = 2,
                Name = "lilTimmy's Team",
                Zip  = "38655"
            }).Entity;

            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = 1,
                TeamId = team1.Id
            });
            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = 1,
                TeamId = team2.Id
            });

            context.SaveChanges();

            // act
            UserWithTeamsDto result = await target.GetUserAsync(addedUserSettings.GoogleId);

            // assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Teams.Count());
            Assert.Equal(team1.Name, result.Teams.ElementAt(0).Name);
            Assert.Equal(team2.Name, result.Teams.ElementAt(1).Name);
        }
        public async void LunchRepository_TeamNameExistsAsync_ReturnsFalseWhenTeamDoesNotExist()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            const string    Name    = "bob's team";

            // act
            bool result = await target.TeamNameExistsAsync(Name);

            // assert
            Assert.False(result);
        }
Esempio n. 19
0
        public void STORE_PROCEDURES_TEST(string sp_name)
        {
            LunchRepository repository = RepositoryFactory.GetLunchRepository();

            switch (sp_name)
            {
            case "SP_CREATE_LUNCH":
            {
                var launch = repository.CreateLunch(new Lunch()
                    {
                        Name        = "Ajiaco",
                        Description = "El ajiaco bogotano o santafereño consiste en una sopa de pollo que contiene diferentes tipos de papa y se puede servir sola o con crema de leche y alcaparras encurtidas, generalmente en tazones de barro cocido. El ajiaco también suele incluir mazorcas de maíz tierno. Por el importante rol cultural que juega, se le considera una tradición santafereña (por el nombre colonial de la ciudad, Santa Fe de Bogotá). El ajiaco típico bogotano tiene tres tipos de papa que le brindan cremosidad gracias a los diferentes niveles de cocción; el tipo de papa más importante es la criolla que es pequeña y de color amarillo vivo y se deshace dándole el color amarillo que lo caracteriza (los otros dos tipos de papa que incluye la receta son variedades regionales que se conocen localmente como papa pastusa y papa sabanera). El componente fundamental del ajiaco es una hierba llamada guasca que le da su sabor más característico. A diferencia de lo que sugiere su nombre, el ajiaco no es picante. El plato suele servirse acompañado de una tajada de aguacate. Se ha vuelto común servirlo acompañado de arroz blanco aunque ello es una adición que, a pesar de su popularidad, no es tradicional. Algunas preparaciones incluyen también arracacha, aunque tal práctica no concuerda del todo con la más pura tradición bogotana",
                        Ingredients = "Pollo;papa criolla;papa sabanera;papa pastusa;guascas;alcaparras;mazorca de maíz tierno",
                        Image       = "https://cdn.colombia.com/sdi/2011/07/22/ajiaco-496022.jpg;https://www.deliciosi.com/images/1500/1510/ajiaco-de-pollo.jpg;http://elrancherito.com.co/wp-content/uploads/2017/07/Ajiaco.jpg"
                    });
                Assert.IsNotNull(launch);
                break;
            }

            case "SP_GET_LUNCH":
            {
                var list = repository.GetLunch();
                break;
            }

            case "SP_GETBYID_LUNCH":
            {
                var lunch = repository.GetByIdLunch(Guid.Parse("008F08E7-D499-4412-8FFA-937926B49A75"));
                Assert.IsNull(lunch);
                break;
            }

            case "SP_UPDATE_LUNCH":
            {
                var launch = repository.UpdateLunch(Guid.Parse("B73AF0D8-D760-4912-8BDC-430F76FBDD67"), new Lunch()
                    {
                        Name        = "Ajiaco Santafereño",
                        Description = "El ajiaco bogotano o santafereño consiste en una sopa de pollo que contiene diferentes tipos de papa y se puede servir sola o con crema de leche y alcaparras encurtidas, generalmente en tazones de barro cocido. El ajiaco también suele incluir mazorcas de maíz tierno. Por el importante rol cultural que juega, se le considera una tradición santafereña (por el nombre colonial de la ciudad, Santa Fe de Bogotá). El ajiaco típico bogotano tiene tres tipos de papa que le brindan cremosidad gracias a los diferentes niveles de cocción; el tipo de papa más importante es la criolla que es pequeña y de color amarillo vivo y se deshace dándole el color amarillo que lo caracteriza (los otros dos tipos de papa que incluye la receta son variedades regionales que se conocen localmente como papa pastusa y papa sabanera). El componente fundamental del ajiaco es una hierba llamada guasca que le da su sabor más característico. A diferencia de lo que sugiere su nombre, el ajiaco no es picante. El plato suele servirse acompañado de una tajada de aguacate. Se ha vuelto común servirlo acompañado de arroz blanco aunque ello es una adición que, a pesar de su popularidad, no es tradicional. Algunas preparaciones incluyen también arracacha, aunque tal práctica no concuerda del todo con la más pura tradición bogotana",
                        Ingredients = "Pollo;papa criolla;papa sabanera;papa pastusa;guascas;alcaparras;mazorca de maíz tierno",
                        Image       = "https://cdn.colombia.com/sdi/2011/07/22/ajiaco-496022.jpg;https://www.deliciosi.com/images/1500/1510/ajiaco-de-pollo.jpg;http://elrancherito.com.co/wp-content/uploads/2017/07/Ajiaco.jpg"
                    });
                break;
            }

            case "SP_DELETE_LUNCH":
            {
                var launch = repository.DeleteLunch(Guid.Parse("008F08E7-D499-4412-8FFA-937926B49A75"));
                break;
            }
            }
        }
Esempio n. 20
0
        public ActionResult DisenrollUser(Guid lunchId)
        {
            var user       = UserRepository.GetUserByName(User.Identity.Name);
            var enrollment = EnrollmentRepository.Get(user.Id, lunchId);
            var success    = EnrollmentRepository.TryDelete(enrollment);
            var lunch      = LunchRepository.Get(lunchId);

            UpdateLunchInfoOnClients(lunch);

            return(Json(new
            {
                userEnrolled = !success,
                numberOfEnrollments = lunch.NumberOfEnrollments,
                numberOfPortions = lunch.NumberOfPortions
            }));
        }
        public async void LunchRepository_GetNopesAsync_ReturnsEmptyListWithNoUsers()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            context.SaveChanges();

            var ids = new List <int>();

            // act
            IEnumerable <string> result = await target.GetNopesAsync(ids);

            // assert
            Assert.Equal(0, result.Count());
        }
        public async void LunchRepository_CreateTeamAsync_CreatesATeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            const string    Name    = "bob's team";
            const string    Zip     = "90210";

            // act
            int result = await target.CreateTeamAsync(Name, Zip);

            // assert
            var team = context.Teams.First();

            Assert.Equal(Name, team.Name);
            Assert.Equal(Zip, team.Zip);
            Assert.Equal(team.Id, result);
        }
        public async void LunchRepository_CreateUserAsync_ReturnsId()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            string googleId = "googleId";
            string email    = "*****@*****.**";
            string name     = "goodname";
            string photoUrl = "photo";

            // act
            var result = await target.CreateUserAsync(googleId, email, name, photoUrl);

            // assert
            UserEntity newUser = context.Users.Where(u => u.Name == name).FirstOrDefault();

            Assert.Equal(newUser.Id, result.Id);
        }
        public async void LunchRepository_GetUserAsync_ReturnsSpecifiedUser()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            UserEntity      user    = context.Users.Add(new UserEntity()
            {
                Name  = "Tahra Dactyl",
                Nopes = "[]",
            }).Entity;
            await context.SaveChangesAsync();

            // act
            UserDto result = await target.GetUserAsync(user.Id);

            // assert
            Assert.Equal(user.Name, result.Name);
            Assert.Equal(user.Nopes, JsonConvert.SerializeObject(result.Nopes));
        }
        public async void LunchRepository_TeamNameExistsAsync_ReturnsTrueWhenTeamDoesExist()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            const string    Name    = "bob's team";

            context.Teams.Add(new TeamEntity
            {
                Name = Name
            });
            context.SaveChanges();

            // act
            bool result = await target.TeamNameExistsAsync(Name);

            // assert
            Assert.True(result);
        }
        public async void LunchRepository_GetTeamAsync_ReturnsSpecifiedTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity()
            {
                Name = "Tahra Dactyls",
                Zip  = "90210",
            }).Entity;
            await context.SaveChangesAsync();

            // act
            TeamDto result = await target.GetTeamAsync(team.Id);

            // assert
            Assert.Equal(team.Name, result.Name);
            Assert.Equal(team.Zip, result.Zip);
        }
        public async void LunchRepository_CreateUserAsync_AddsEntryToTable()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            string googleId = "googleId";
            string email    = "*****@*****.**";
            string name     = "goodname";
            string photoUrl = "photo";

            // act
            await target.CreateUserAsync(googleId, email, name, photoUrl);

            // assert
            UserEntity newUser = context.Users.Where(u => u.GoogleId == googleId).FirstOrDefault();

            Assert.True(newUser.Id > 0);
            Assert.Equal(email, newUser.Email);
            Assert.Equal(name, newUser.Name);
        }
Esempio n. 28
0
        public ActionResult EnrollUser(Guid lunchId, Guid?variation = null)
        {
            var user       = UserRepository.GetUserByName(User.Identity.Name);
            var enrollment = new Enrollment()
            {
                EnrolledById       = user.Id,
                EnrolledForLunchId = lunchId,
                EnrollmentDate     = DateTime.Now,
                MealVariationId    = variation
            };
            var success = EnrollmentRepository.TryInsert(enrollment);
            var lunch   = LunchRepository.Get(lunchId);

            UpdateLunchInfoOnClients(lunch);

            return(Json(new
            {
                userEnrolled = success,
                numberOfEnrollments = lunch.NumberOfEnrollments,
                numberOfPortions = lunch.NumberOfPortions
            }));
        }
        public async void LunchRepository_GetUsersOfTeamAsync_ReturnsListOfUsersFromTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity
            {
                Name = "bob's team"
            }).Entity;
            UserEntity user = context.Users.Add(new UserEntity
            {
                Name = "bob"
            }).Entity;
            UserEntity user2 = context.Users.Add(new UserEntity
            {
                Name = "lilTimmy"
            }).Entity;

            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user.Id,
                TeamId = team.Id
            });
            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user2.Id,
                TeamId = team.Id
            });
            context.SaveChanges();


            // act
            List <UserDto> result = (await target.GetUsersOfTeamAsync(team.Id)).ToList();

            // assert
            Assert.Equal(2, result.Count());
            Assert.Equal("bob", result[0].Name);
            Assert.Equal("lilTimmy", result[1].Name);
        }
        public async void LunchRepository_UpdateTeamAsync_UpdatesTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            const string    Name    = "bob's team";
            const string    Zip     = "90210";
            const string    NewName = "fanny's team";
            const string    NewZip  = "00501";

            int id = await target.CreateTeamAsync(Name, Zip);

            await target.UpdateTeamAsync(id, NewName, NewZip);

            // act

            var result = context.Teams.Where(u => u.Id == id).Single();

            // assert
            Assert.Equal(NewName, result.Name);
            Assert.Equal(NewZip, result.Zip);
        }