Beispiel #1
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);
        }
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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 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);
        }
        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);
        }
        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);
        }