예제 #1
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            var exerciseHistories = fittifyContext.ExerciseHistories.Where(eH => eH.Exercise.Name == "SpinningBikeSeed").ToList();

            if (fittifyContext.CardioSets.Count() == 0)
            {
                foreach (var eH in exerciseHistories)
                {
                    fittifyContext.CardioSets.Add(new CardioSet()
                    {
                        DateTimeStart     = eH.ExecutedOnDateTime + TimeSpan.FromMinutes(0),
                        DateTimeEnd       = eH.ExecutedOnDateTime + TimeSpan.FromMinutes(5),
                        ExerciseHistoryId = eH.Id,
                        OwnerGuid         = StaticFields.TestOwnerGuid
                    });

                    fittifyContext.CardioSets.Add(new CardioSet()
                    {
                        DateTimeStart     = eH.ExecutedOnDateTime + TimeSpan.FromMinutes(60),
                        DateTimeEnd       = eH.ExecutedOnDateTime + TimeSpan.FromMinutes(80),
                        ExerciseHistoryId = eH.Id,
                        OwnerGuid         = StaticFields.TestOwnerGuid
                    });
                }
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        public async Task DeleteEntityById()
        {
            var(connection, options) = await CreateUniqueMockDbConnectionForThisTest();

            try
            {
                int categoryId;
                using (var context = new FittifyContext(options))
                {
                    var category = new Category();
                    context.Categories.Add(category);
                    context.SaveChanges();
                    categoryId = category.Id;

                    var categoryRepository   = new CategoryRepository(context);
                    var entityDeletionResult = await categoryRepository.Delete(categoryId);

                    Assert.AreEqual(entityDeletionResult.DidEntityExist, true);
                    Assert.AreEqual(entityDeletionResult.IsDeleted, true);
                }

                using (var context = new FittifyContext(options))
                {
                    var category = context.Categories.FirstOrDefault(f => f.Id == categoryId);

                    Assert.AreEqual(null, category);
                }
            }
            finally
            {
                connection.Close();
            }
        }
예제 #3
0
        CreateUniqueMockDbConnectionForThisTest(List <WorkoutHistory> listWorkoutHistories)
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;



                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    if (listWorkoutHistories != null)
                    {
                        context.AddRange(listWorkoutHistories);
                        context.SaveChanges();
                    }
                }
            });

            return(connection, options);
        }
예제 #4
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            var listCategories = new List <Category>()
            {
                new Category()
                {
                    Name = "ChestSeed"
                },
                new Category()
                {
                    Name = "BackSeed"
                },
                new Category()
                {
                    Name = "LegsSeed"
                },
            };

            foreach (var category in listCategories)
            {
                if (fittifyContext.Categories.FirstOrDefault(f => f.Name == category.Name) == null)
                {
                    fittifyContext.Add(category);
                }
            }

            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #5
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            if (fittifyContext.Workouts.FirstOrDefault(f => f.Name == "MondayChestSeed") == null)
            {
                fittifyContext.Add(new Workout()
                {
                    Name = "MondayChestSeed",
                    ////CategoryId = fittifyContext.Categories.FirstOrDefault(f => f.Name == "ChestSeed").Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            if (fittifyContext.Workouts.FirstOrDefault(f => f.Name == "WednesdayBackSeed") == null)
            {
                fittifyContext.Add(new Workout()
                {
                    Name = "WednesdayBackSeed",
                    ////CategoryId = fittifyContext.Categories.FirstOrDefault(f => f.Name == "BackSeed").Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            if (fittifyContext.Workouts.FirstOrDefault(f => f.Name == "FridayLegSeed") == null)
            {
                fittifyContext.Add(new Workout()
                {
                    Name = "FridayLegSeed",
                    ////CategoryId = fittifyContext.Categories.FirstOrDefault(f => f.Name == "LegsSeed").Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #6
0
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listExercises = new List <Exercise>()
                {
                    new Exercise()
                    {
                        Name = "aFirstExercise"
                    },
                    new Exercise()
                    {
                        Name = "aSecondExercise"
                    },
                    new Exercise()
                    {
                        Name = "aThirdExercise"
                    },
                    new Exercise()
                    {
                        Name = "cFourthExercise"
                    },
                    new Exercise()
                    {
                        Name = "cFifthExercise"
                    },
                    new Exercise()
                    {
                        Name = "cSixthExercise"
                    },
                    new Exercise()
                    {
                        Name = "bSeventhExercise", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "bEighthExercise", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "bNinthExercise", OwnerGuid = _ownerGuid
                    }
                };

                // CreateAsync the schema in the database
                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    context.AddRange(listExercises);
                    context.SaveChanges();
                }
            });

            return(connection, options);
        }
예제 #7
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            var exerciseHistories = fittifyContext.ExerciseHistories.ToArray();
            var count             = exerciseHistories.Count();

            if (fittifyContext.WeightLiftingSets.Count() == 0)
            {
                for (int i = 1; i <= count; i++)
                {
                    if (exerciseHistories[i - 1].Exercise.Name == "SpinningBikeSeed") // spinningBile is seeded from CardioSet
                    {
                        continue;
                    }
                    else if (i % 4 == 0) // fourth exercise are situps
                    {
                        for (int j = 1; j <= 4; j++)
                        {
                            fittifyContext.WeightLiftingSets.Add(new WeightLiftingSet()
                            {
                                WeightFull         = 10,
                                RepetitionsFull    = 20,
                                WeightReduced      = 5,
                                RepetitionsReduced = 20,
                                WeightBurn         = 0,
                                ExerciseHistoryId  = exerciseHistories[i - 1].Id,
                                OwnerGuid          = StaticFields.TestOwnerGuid
                            });
                        }
                    }
                    else if (i % 3 == 0)
                    {
                        for (int j = 1; j <= 3; j++)
                        {
                            fittifyContext.WeightLiftingSets.Add(new WeightLiftingSet()
                            {
                                WeightFull         = 30,
                                RepetitionsFull    = 12,
                                WeightReduced      = 20,
                                RepetitionsReduced = 8,
                                WeightBurn         = 10,
                                ExerciseHistoryId  = exerciseHistories[i - 1].Id,
                                OwnerGuid          = StaticFields.TestOwnerGuid
                            });
                        }
                    }
                    else if (i % 2 == 0)
                    {
                        for (int j = 1; j <= 2; j++)
                        {
                            fittifyContext.WeightLiftingSets.Add(new WeightLiftingSet()
                            {
                                WeightFull         = 30,
                                RepetitionsFull    = 12,
                                WeightReduced      = 20,
                                RepetitionsReduced = 8,
                                WeightBurn         = 10,
                                ExerciseHistoryId  = exerciseHistories[i - 1].Id,
                                OwnerGuid          = StaticFields.TestOwnerGuid
                            });
                        }
                    }
                    else
                    {
                        fittifyContext.WeightLiftingSets.Add(new WeightLiftingSet()
                        {
                            WeightFull         = 30,
                            RepetitionsFull    = 12,
                            WeightReduced      = 20,
                            RepetitionsReduced = 8,
                            WeightBurn         = 10,
                            ExerciseHistoryId  = exerciseHistories[i - 1].Id,
                            OwnerGuid          = StaticFields.TestOwnerGuid
                        });
                    }
                }
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #8
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            var listMapExerciseWorkouts = fittifyContext.MapExerciseWorkout.ToList();

            if (listMapExerciseWorkouts.Count() == 0)
            {
                var listWorkouts = fittifyContext.Workouts.ToList();
                foreach (var workout in listWorkouts)
                {
                    if (workout.Name == "MondayChestSeed")
                    {
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "InclinedBenchPressSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "DumbBellFlySeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "NegativeBenchPressSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SitupsSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SpinningBikeSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                    }

                    if (workout.Name == "WednesdayBackSeed")
                    {
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "DeadLiftSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SeatedPullDownSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "RowSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SitupsSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SpinningBikeSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                    }

                    if (workout.Name == "FridayLegSeed")
                    {
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SquatSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "LegCurlSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "CalfRaiseSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SitupsSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                        fittifyContext.Add(new MapExerciseWorkout()
                        {
                            WorkoutId  = workout.Id,
                            ExerciseId = fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SpinningBikeSeed").Id,
                            OwnerGuid  = StaticFields.TestOwnerGuid
                        });
                    }
                }
            }

            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #9
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            DateTime SessionStart;
            DateTime SessionEnd;
            string   workout;

            SessionStart = new DateTime(2017, 05, 01, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 01, 14, 32, 01);
            workout      = "MondayChestSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     = fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid     = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 03, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 03, 14, 32, 01);
            workout      = "WednesdayBackSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     =
                        fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 05, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 05, 14, 32, 01);
            workout      = "FridayLegSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     = fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid     = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 08, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 08, 14, 32, 01);
            workout      = "MondayChestSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     =
                        fittifyContext.Workouts.FirstOrDefault(w => w.Name == "MondayChestSeed").Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 10, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 10, 14, 32, 01);
            workout      = "WednesdayBackSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     =
                        fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 12, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 12, 14, 32, 01);
            workout      = "FridayLegSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     = fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid     = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 15, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 15, 14, 32, 01);
            workout      = "MondayChestSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     =
                        fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 17, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 17, 14, 32, 01);
            workout      = "WednesdayBackSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     =
                        fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            SessionStart = new DateTime(2017, 05, 19, 12, 01, 05);
            SessionEnd   = new DateTime(2017, 05, 19, 14, 32, 01);
            workout      = "FridayLegSeed";
            if (fittifyContext.WorkoutHistories.FirstOrDefault(f =>
                                                               f.DateTimeStart == SessionStart && f.Workout.Name == workout) == null)
            {
                fittifyContext.Add(new WorkoutHistory()
                {
                    DateTimeStart = SessionStart,
                    DateTimeEnd   = SessionEnd,
                    WorkoutId     = fittifyContext.Workouts.FirstOrDefault(w => w.Name == workout).Id,
                    OwnerGuid     = StaticFields.TestOwnerGuid
                });
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #10
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            DateTime executedOnDateTime;
            int?     previousExerciseId;
            string   previousExerciseName;

            previousExerciseId = null;
            executedOnDateTime = new DateTime(2017, 05, 01, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                //var WorkoutHistory = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                //    w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd);
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == "InclinedBenchPressSeed").Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == "DumbBellFlySeed").Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == "NegativeBenchPressSeed").Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == "SitupsSeed").Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == "SpinningBikeSeed").Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 03, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "DeadLiftSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SeatedPullDownSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "RowSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 05, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "SquatSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "LegCurlSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "CalfRaiseSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            fittifyContext.SaveChanges();

            executedOnDateTime = new DateTime(2017, 05, 08, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "InclinedBenchPressSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "DumbBellFlySeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "NegativeBenchPressSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 10, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "DeadLiftSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SeatedPullDownSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "RowSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 12, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "SquatSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "LegCurlSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "CalfRaiseSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            fittifyContext.SaveChanges();

            executedOnDateTime = new DateTime(2017, 05, 15, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "InclinedBenchPressSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "DumbBellFlySeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "NegativeBenchPressSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 17, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "DeadLiftSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SeatedPullDownSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "RowSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }

            executedOnDateTime = new DateTime(2017, 05, 19, 13, 04, 12);
            if (fittifyContext.ExerciseHistories.FirstOrDefault(f => f.ExecutedOnDateTime == executedOnDateTime) == null)
            {
                previousExerciseName = "SquatSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "LegCurlSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "CalfRaiseSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SitupsSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });

                previousExerciseName = "SpinningBikeSeed";
                previousExerciseId   = fittifyContext.ExerciseHistories.ToArray().Reverse().FirstOrDefault(f => f.Exercise.Name == previousExerciseName).Id;
                fittifyContext.ExerciseHistories.Add(new ExerciseHistory()
                {
                    ExerciseId         = fittifyContext.Exercises.FirstOrDefault(e => e.Name == previousExerciseName).Id,
                    ExecutedOnDateTime = executedOnDateTime,
                    WorkoutHistoryId   = fittifyContext.WorkoutHistories.FirstOrDefault(w =>
                                                                                        w.DateTimeStart < executedOnDateTime && executedOnDateTime < w.DateTimeEnd).Id,
                    PreviousExerciseHistoryId = previousExerciseId,
                    OwnerGuid = StaticFields.TestOwnerGuid
                });
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #11
0
        public static bool Seed(FittifyContext fittifyContext)
        {
            // Chest
            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "InclinedBenchPressSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "InclinedBenchPressSeed", ExerciseType = ExerciseTypeEnum.WeightLifting, OwnerGuid = Guid.Parse("d860efca-22d9-47fd-8249-791ba61b07c7")
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "DumbBellFlySeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "DumbBellFlySeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "NegativeBenchPressSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "NegativeBenchPressSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            // Back
            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "DeadLiftSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "DeadLiftSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SeatedPullDownSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "SeatedPullDownSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "RowSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "RowSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            // LegsSeed
            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SquatSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "SquatSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "LegCurlSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "LegCurlSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "CalfRaiseSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "CalfRaiseSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            // Other
            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SitupsSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "SitupsSeed", ExerciseType = ExerciseTypeEnum.WeightLifting
                });
            }

            if (fittifyContext.Exercises.FirstOrDefault(f => f.Name == "SpinningBikeSeed") == null)
            {
                fittifyContext.Add(new Exercise()
                {
                    Name = "SpinningBikeSeed", ExerciseType = ExerciseTypeEnum.Cardio
                });
            }


            if (fittifyContext.SaveChanges() >= 0)
            {
                return(true);
            }

            return(false);
        }
예제 #12
0
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listWorkouts = new List <Workout>()
                {
                    new Workout()
                    {
                        Name = "WorkoutA", OwnerGuid = _ownerGuid
                    },
                    new Workout()
                    {
                        Name = "WorkoutB", OwnerGuid = _ownerGuid
                    },
                    new Workout()
                    {
                        Name = "WorkoutC", OwnerGuid = null
                    },
                    new Workout()
                    {
                        Name = "WorkoutD", OwnerGuid = null
                    }
                };

                var listExercises = new List <Exercise>()
                {
                    new Exercise()
                    {
                        Name = "ExerciseA", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "ExerciseB", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "ExerciseC", OwnerGuid = null
                    },
                    new Exercise()
                    {
                        Name = "ExerciseD", OwnerGuid = null
                    },
                };

                var listMapExerciseWorkouts = new List <MapExerciseWorkout>();

                foreach (var workout in listWorkouts)
                {
                    foreach (var exercise in listExercises)
                    {
                        if (workout.OwnerGuid != null &&
                            exercise.OwnerGuid != null &&
                            workout.OwnerGuid == exercise.OwnerGuid)
                        {
                            listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                            {
                                OwnerGuid = _ownerGuid,
                                Workout   = workout,
                                Exercise  = exercise
                            });
                        }
                        else if (workout.OwnerGuid == null &&
                                 exercise.OwnerGuid == null &&
                                 workout.OwnerGuid == exercise.OwnerGuid)
                        {
                            listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                            {
                                OwnerGuid = null,
                                Workout   = workout,
                                Exercise  = exercise
                            });
                        }
                        // we don't want Guid && null or null && Guid
                    }
                }

                using (var context = new FittifyContext(options))
                {
                    // Adding Workouts, Exercise, MapWorkoutExercises
                    context.Database.EnsureCreated();
                    context.AddRange(listMapExerciseWorkouts);
                    context.SaveChanges();

                    // Creating a workoutHistory with ExerciseHistories
                    var firstWorkoutHistory = new WorkoutHistory()
                    {
                        OwnerGuid         = _ownerGuid,
                        Workout           = context.Workouts.FirstOrDefault(f => f.OwnerGuid == _ownerGuid),
                        ExerciseHistories = new List <ExerciseHistory>()
                        {
                            new ExerciseHistory(),
                            new ExerciseHistory()
                        }
                    };

                    context.Add(firstWorkoutHistory);
                    context.SaveChanges();

                    // Creating a workoutHistory of a different workout, but with the same exerciseHistories
                    var secondWorkoutHistory = new WorkoutHistory()
                    {
                        OwnerGuid         = _ownerGuid,
                        Workout           = context.Workouts.FirstOrDefault(f => f.OwnerGuid == null),
                        ExerciseHistories = new List <ExerciseHistory>()
                        {
                            new ExerciseHistory()
                            {
                                PreviousExerciseHistory = context.ExerciseHistories.FirstOrDefault()
                            },
                            new ExerciseHistory()
                            {
                                PreviousExerciseHistory = context.ExerciseHistories.Skip(1).FirstOrDefault()
                            }
                        }
                    };

                    context.Add(secondWorkoutHistory);
                    context.SaveChanges();

                    ////var thirdWorkoutHistory = new WorkoutHistory()
                    ////{
                    ////    OwnerGuid = _ownerGuid,
                    ////    Workout = context.Workouts.FirstOrDefault(f => f.OwnerGuid == _ownerGuid),
                    ////    ExerciseHistories = new List<ExerciseHistory>()
                    ////    {
                    ////        new ExerciseHistory()
                    ////        {
                    ////            PreviousExerciseHistory = context.ExerciseHistories.Skip(2).FirstOrDefault()
                    ////        },
                    ////        new ExerciseHistory()
                    ////        {
                    ////            PreviousExerciseHistory = context.ExerciseHistories.Skip(3).FirstOrDefault()
                    ////        }
                    ////    }
                    ////};

                    ////context.Add(thirdWorkoutHistory);
                    ////context.SaveChanges();

                    // Connecting Workout with the three WorkoutHistories
                    var workoutHistory     = context.WorkoutHistories.FirstOrDefault(f => f.ExerciseHistories != null && f.OwnerGuid != null);
                    workoutHistory.Workout = context.Workouts.FirstOrDefault();
                    context.SaveChanges();
                }
            });

            return(connection, options);
        }
예제 #13
0
        public async Task CorrectlyCreateWorkoutHistoryWithExerciseHistories()
        {
            var(connection, options) = await CreateUniqueMockDbConnectionForThisTest(null);

            try
            {
                using (var context = new FittifyContext(options))
                {
                    var listWorkouts = new List <Workout>()
                    {
                        new Workout()
                        {
                            Name = "WorkoutA", OwnerGuid = _ownerGuid
                        },
                        new Workout()
                        {
                            Name = "WorkoutB", OwnerGuid = _ownerGuid
                        },
                        new Workout()
                        {
                            Name = "WorkoutC", OwnerGuid = null
                        },
                        new Workout()
                        {
                            Name = "WorkoutD", OwnerGuid = null
                        }
                    };

                    var listExercises = new List <Exercise>()
                    {
                        new Exercise()
                        {
                            Name = "ExerciseA", OwnerGuid = _ownerGuid
                        },
                        new Exercise()
                        {
                            Name = "ExerciseB", OwnerGuid = _ownerGuid
                        },
                        new Exercise()
                        {
                            Name = "ExerciseC", OwnerGuid = null
                        },
                        new Exercise()
                        {
                            Name = "ExerciseD", OwnerGuid = null
                        },
                    };

                    var listMapExerciseWorkouts = new List <MapExerciseWorkout>();

                    foreach (var workout in listWorkouts)
                    {
                        foreach (var exercise in listExercises)
                        {
                            if (workout.OwnerGuid != null &&
                                exercise.OwnerGuid != null &&
                                workout.OwnerGuid == exercise.OwnerGuid)
                            {
                                listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                                {
                                    OwnerGuid = _ownerGuid,
                                    Workout   = workout,
                                    Exercise  = exercise
                                });
                            }
                            else if (workout.OwnerGuid == null &&
                                     exercise.OwnerGuid == null &&
                                     workout.OwnerGuid == exercise.OwnerGuid)
                            {
                                listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                                {
                                    OwnerGuid = null,
                                    Workout   = workout,
                                    Exercise  = exercise
                                });
                            }
                            // we don't want Guid && null or null && Guid
                        }
                    }

                    context.MapExerciseWorkout.AddRange(listMapExerciseWorkouts);
                    context.SaveChanges();
                }

                using (var context = new FittifyContext(options))
                {
                    //var Workouts = context.Workouts.ToList();
                    var newWorkoutHistory = new WorkoutHistory()
                    {
                        Workout = context.Workouts.ToList().FirstOrDefault(f => f.OwnerGuid != null)
                    };
                    var repo = new WorkoutHistoryRepository(context);
                    var newlyCreatedWorkoutHistory =
                        await repo.CreateIncludingExerciseHistories(newWorkoutHistory, _ownerGuid);

                    var serializedNewlyCreatedWorkoutHistoryReturnedFromRepo = JsonConvert.SerializeObject(newlyCreatedWorkoutHistory,
                                                                                                           new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    });

                    var newlyCreatedWorkoutHistoryFromContext = context
                                                                .WorkoutHistories
                                                                .Include(i => i.ExerciseHistories)
                                                                .Include(i => i.Workout)
                                                                .FirstOrDefault(f => f.OwnerGuid != null);
                    var serializedNewlyCreatedWorkoutHistoryReturnedFromContext = JsonConvert.SerializeObject(newlyCreatedWorkoutHistory,
                                                                                                              new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    });


                    Assert.AreEqual(serializedNewlyCreatedWorkoutHistoryReturnedFromRepo,
                                    serializedNewlyCreatedWorkoutHistoryReturnedFromContext);
                    Assert.AreEqual(newlyCreatedWorkoutHistory.ExerciseHistories.Count(), 2);
                    Assert.AreEqual(newlyCreatedWorkoutHistoryFromContext.ExerciseHistories.Count(), 2);

                    foreach (var exerciseHistory in newlyCreatedWorkoutHistory.ExerciseHistories)
                    {
                        Assert.AreEqual(exerciseHistory.PreviousExerciseHistory, null);
                    }
                }

                using (var context = new FittifyContext(options))
                {
                    var existingExerciseHistories =
                        context.ExerciseHistories.Where(w => w.OwnerGuid == _ownerGuid).ToList();


                    existingExerciseHistories.FirstOrDefault().WeightLiftingSets = new List <WeightLiftingSet>()
                    {
                        new WeightLiftingSet()
                        {
                            RepetitionsFull = 30
                        }
                    };

                    existingExerciseHistories.Skip(1).FirstOrDefault().CardioSets = new List <CardioSet>()
                    {
                        new CardioSet()
                        {
                            DateTimeStart = new DateTime(1989, 11, 01, 13, 10, 00),
                            DateTimeEnd   = new DateTime(1989, 11, 01, 13, 50, 00)
                        }
                    };

                    //var Workouts = context.Workouts.ToList();
                    var newWorkoutHistory = new WorkoutHistory()
                    {
                        Workout = context.Workouts.ToList().FirstOrDefault(f => f.OwnerGuid != null)
                    };
                    var repo = new WorkoutHistoryRepository(context);
                    var newlyCreatedWorkoutHistory =
                        await repo.CreateIncludingExerciseHistories(newWorkoutHistory, _ownerGuid);

                    foreach (var exerciseHistory in newlyCreatedWorkoutHistory.ExerciseHistories)
                    {
                        Assert.AreNotEqual(exerciseHistory.PreviousExerciseHistory, null);
                    }
                }
            }
            finally
            {
                connection.Close();
            }
        }
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listExerciseHistories = new List <ExerciseHistory>()
                {
                    new ExerciseHistory()
                    {
                        OwnerGuid         = _ownerGuid,
                        WeightLiftingSets = new List <WeightLiftingSet>()
                        {
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        CardioSets = new List <CardioSet>()
                        {
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        WorkoutHistory = new WorkoutHistory()
                        {
                            OwnerGuid = _ownerGuid
                        },
                        Exercise = new Exercise()
                        {
                            OwnerGuid = _ownerGuid
                        }
                    },
                    new ExerciseHistory()
                    {
                        OwnerGuid         = _ownerGuid,
                        WeightLiftingSets = new List <WeightLiftingSet>()
                        {
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        CardioSets = new List <CardioSet>()
                        {
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        WorkoutHistory = new WorkoutHistory()
                        {
                            OwnerGuid = _ownerGuid
                        },
                        Exercise = new Exercise()
                        {
                            OwnerGuid = _ownerGuid
                        }
                    },
                    new ExerciseHistory()
                    {
                        OwnerGuid         = _ownerGuid,
                        WeightLiftingSets = new List <WeightLiftingSet>()
                        {
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new WeightLiftingSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        CardioSets = new List <CardioSet>()
                        {
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            },
                            new CardioSet()
                            {
                                OwnerGuid = _ownerGuid
                            }
                        },
                        WorkoutHistory = new WorkoutHistory()
                        {
                            OwnerGuid = _ownerGuid
                        },
                        Exercise = new Exercise()
                        {
                            OwnerGuid = _ownerGuid
                        }
                    },
                    new ExerciseHistory()
                    {
                        OwnerGuid         = null,
                        WeightLiftingSets = new List <WeightLiftingSet>()
                        {
                            new WeightLiftingSet()
                            {
                                OwnerGuid = null
                            },
                            new WeightLiftingSet()
                            {
                                OwnerGuid = null
                            }
                        },
                        CardioSets = new List <CardioSet>()
                        {
                            new CardioSet()
                            {
                                OwnerGuid = null
                            },
                            new CardioSet()
                            {
                                OwnerGuid = null
                            }
                        },
                        WorkoutHistory = new WorkoutHistory()
                        {
                            OwnerGuid = null
                        },
                        Exercise = new Exercise()
                        {
                            OwnerGuid = null
                        }
                    },
                    new ExerciseHistory()
                    {
                        OwnerGuid         = null,
                        WeightLiftingSets = new List <WeightLiftingSet>()
                        {
                            new WeightLiftingSet()
                            {
                                OwnerGuid = null
                            },
                            new WeightLiftingSet()
                            {
                                OwnerGuid = null
                            }
                        },
                        CardioSets = new List <CardioSet>()
                        {
                            new CardioSet()
                            {
                                OwnerGuid = null
                            },
                            new CardioSet()
                            {
                                OwnerGuid = null
                            }
                        },
                        WorkoutHistory = new WorkoutHistory()
                        {
                            OwnerGuid = null
                        },
                        Exercise = new Exercise()
                        {
                            OwnerGuid = null
                        }
                    }
                };

                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    context.AddRange(listExerciseHistories);
                    context.SaveChanges();


                    var firstExerciseHistory  = context.ExerciseHistories.FirstOrDefault(f => f.OwnerGuid != null);
                    var secondExerciseHistory =
                        context.ExerciseHistories.Skip(1).FirstOrDefault(f => f.OwnerGuid != null);
                    var thirdExerciseHistory =
                        context.ExerciseHistories.Skip(2).FirstOrDefault(f => f.OwnerGuid != null);

                    secondExerciseHistory.PreviousExerciseHistory = firstExerciseHistory;
                    thirdExerciseHistory.PreviousExerciseHistory  = secondExerciseHistory;

                    context.SaveChanges();
                }
            });

            return(connection, options);
        }
예제 #15
0
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listWorkouts = new List <Workout>()
                {
                    new Workout()
                    {
                        Name = "WorkoutA", OwnerGuid = _ownerGuid
                    },
                    new Workout()
                    {
                        Name = "WorkoutB", OwnerGuid = _ownerGuid
                    },
                    new Workout()
                    {
                        Name = "WorkoutC", OwnerGuid = null
                    },
                    new Workout()
                    {
                        Name = "WorkoutD", OwnerGuid = null
                    }
                };

                var listExercises = new List <Exercise>()
                {
                    new Exercise()
                    {
                        Name = "ExerciseA", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "ExerciseB", OwnerGuid = _ownerGuid
                    },
                    new Exercise()
                    {
                        Name = "ExerciseC", OwnerGuid = null
                    },
                    new Exercise()
                    {
                        Name = "ExerciseD", OwnerGuid = null
                    },
                };

                var listMapExerciseWorkouts = new List <MapExerciseWorkout>();

                foreach (var workout in listWorkouts)
                {
                    foreach (var exercise in listExercises)
                    {
                        if (workout.OwnerGuid != null &&
                            exercise.OwnerGuid != null &&
                            workout.OwnerGuid == exercise.OwnerGuid)
                        {
                            listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                            {
                                OwnerGuid = _ownerGuid,
                                Workout   = workout,
                                Exercise  = exercise
                            });
                        }
                        else if (workout.OwnerGuid == null &&
                                 exercise.OwnerGuid == null &&
                                 workout.OwnerGuid == exercise.OwnerGuid)
                        {
                            listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                            {
                                OwnerGuid = null,
                                Workout   = workout,
                                Exercise  = exercise
                            });
                        }
                        // we don't want Guid && null or null && Guid
                    }
                }


                // CreateAsync the schema in the database
                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    context.AddRange(listMapExerciseWorkouts);
                    context.SaveChanges();
                }
            });

            return(connection, options);
        }
예제 #16
0
        static void Main(string[] args)
        {
            var _ownerGuid = new Guid("00000000-0000-0000-0000-000000000000");

            var listWorkouts = new List <Workout>()
            {
                new Workout()
                {
                    Name = "WorkoutA", OwnerGuid = _ownerGuid
                },
                new Workout()
                {
                    Name = "WorkoutB", OwnerGuid = _ownerGuid
                },
                new Workout()
                {
                    Name = "WorkoutC", OwnerGuid = null
                },
                new Workout()
                {
                    Name = "WorkoutD", OwnerGuid = null
                }
            };

            var listExercises = new List <Exercise>()
            {
                new Exercise()
                {
                    Name = "ExerciseA", OwnerGuid = _ownerGuid
                },
                new Exercise()
                {
                    Name = "ExerciseB", OwnerGuid = _ownerGuid
                },
                new Exercise()
                {
                    Name = "ExerciseC", OwnerGuid = null
                },
                new Exercise()
                {
                    Name = "ExerciseD", OwnerGuid = null
                },
            };

            var listMapExerciseWorkouts = new List <MapExerciseWorkout>();

            foreach (var workout in listWorkouts)
            {
                foreach (var exercise in listExercises)
                {
                    if (workout.OwnerGuid != null &&
                        exercise.OwnerGuid != null &&
                        workout.OwnerGuid == exercise.OwnerGuid)
                    {
                        listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                        {
                            OwnerGuid = _ownerGuid,
                            Workout   = workout,
                            Exercise  = exercise
                        });
                    }
                    else if (workout.OwnerGuid == null &&
                             exercise.OwnerGuid == null &&
                             workout.OwnerGuid == exercise.OwnerGuid)
                    {
                        listMapExerciseWorkouts.Add(new MapExerciseWorkout()
                        {
                            OwnerGuid = null,
                            Workout   = workout,
                            Exercise  = exercise
                        });
                    }
                    // we don't want Guid && null or null && Guid
                }
            }


            // CreateAsync the schema in the database
            using (var context = new FittifyContext(
                       "Server=.\\SQLEXPRESS2016S1;Database=MyTest;User Id=seifert-1;Password=merlin;"))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                context.AddRange(listMapExerciseWorkouts);
                context.SaveChanges();
            }

            MapExerciseWorkout queryResult;

            using (var context = new FittifyContext(
                       "Server=.\\SQLEXPRESS2016S1;Database=MyTest;User Id=seifert-1;Password=merlin;"))
            {
                // Todo: Investigage... all children of children are loaded
                queryResult = context
                              .MapExerciseWorkout.AsNoTracking()
                              .Include(i => i.Exercise).AsNoTracking()
                              .Include(i => i.Workout).AsNoTracking()
                              .FirstOrDefault();
            }

            var result = JsonConvert.SerializeObject(queryResult,
                                                     new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Formatting            = Formatting.Indented
            });
        }
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listExerciseHistories = new List <ExerciseHistory>()
                {
                    new ExerciseHistory(),
                    new ExerciseHistory()
                };

                var listWeightLiftingSets1 = new List <WeightLiftingSet>()
                {
                    new WeightLiftingSet(),
                    new WeightLiftingSet(),
                    new WeightLiftingSet()
                };

                var listWeightLiftingSets2 = new List <WeightLiftingSet>()
                {
                    new WeightLiftingSet(),
                    new WeightLiftingSet(),
                    new WeightLiftingSet()
                };

                // CreateAsync the schema in the database
                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    context.AddRange(listExerciseHistories);
                    context.SaveChanges();

                    var exerciseHistoriesFromContext = context.ExerciseHistories.ToList();

                    foreach (var wls in listWeightLiftingSets1)
                    {
                        wls.ExerciseHistory = exerciseHistoriesFromContext.FirstOrDefault();
                    }

                    foreach (var wls in listWeightLiftingSets2)
                    {
                        wls.ExerciseHistory = exerciseHistoriesFromContext.Skip(1).FirstOrDefault();
                    }

                    context.AddRange(listWeightLiftingSets1);
                    context.AddRange(listWeightLiftingSets2);

                    context.SaveChanges();
                }
            });

            return(connection, options);
        }
예제 #18
0
        CreateUniqueMockDbConnectionForThisTest()
        {
            SqliteConnection connection = null;
            DbContextOptions <FittifyContext> options = null;

            await Task.Run(() =>
            {
                connection = new SqliteConnection("DataSource=:memory:");
                connection.Open();

                options = new DbContextOptionsBuilder <FittifyContext>()
                          .UseSqlite(connection)
                          .Options;

                var listExerciseHistories = new List <ExerciseHistory>()
                {
                    new ExerciseHistory()
                    {
                        OwnerGuid = _ownerGuid
                    },
                    new ExerciseHistory()
                    {
                        OwnerGuid = _ownerGuid
                    }
                };

                var listCardioSets1 = new List <CardioSet>()
                {
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid
                    },
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid
                    },
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid
                    }
                };

                var listCardioSets2 = new List <CardioSet>()
                {
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid, DateTimeStart = new DateTime(1989, 11, 01, 14, 00, 00), DateTimeEnd = new DateTime(1989, 11, 01, 16, 00, 00)
                    },
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid, DateTimeStart = new DateTime(1989, 11, 01, 14, 00, 00), DateTimeEnd = new DateTime(1989, 11, 01, 16, 00, 00)
                    },
                    new CardioSet()
                    {
                        OwnerGuid = _ownerGuid, DateTimeStart = new DateTime(1989, 11, 01, 14, 00, 00), DateTimeEnd = new DateTime(1989, 11, 01, 16, 00, 00)
                    }
                };

                // CreateAsync the schema in the database
                using (var context = new FittifyContext(options))
                {
                    context.Database.EnsureCreated();
                    context.AddRange(listExerciseHistories);
                    context.SaveChanges();

                    var exerciseHistoriesFromContext = context.ExerciseHistories.ToList();

                    foreach (var wls in listCardioSets1)
                    {
                        wls.ExerciseHistory = exerciseHistoriesFromContext.FirstOrDefault();
                    }

                    foreach (var wls in listCardioSets2)
                    {
                        wls.ExerciseHistory = exerciseHistoriesFromContext.Skip(1).FirstOrDefault();
                    }

                    context.AddRange(listCardioSets1);
                    context.AddRange(listCardioSets2);

                    context.SaveChanges();
                }
            });

            return(connection, options);
        }