コード例 #1
0
        public void GetUserRating()
        {
            RatingUserValue rating = new RatingUserValue();

            rating.RatedObjectId = supplements[0].GlobalId;
            rating.Rating        = 2;
            rating.ProfileId     = profiles[0].GlobalId;
            rating.VotedDate     = DateTime.UtcNow;
            insertToDatabase(rating);
            rating = new RatingUserValue();
            rating.RatedObjectId = supplements[0].GlobalId;
            rating.Rating        = 5;
            rating.ProfileId     = profiles[1].GlobalId;
            rating.VotedDate     = DateTime.UtcNow;
            insertToDatabase(rating);

            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var list = service.GetSuplements(data.Token, new GetSupplementsParam(), new PartialRetrievingInfo());
                Assert.AreEqual(2, list.Items.Where(x => x.GlobalId == supplements[0].GlobalId).Single().UserRating);
                Assert.AreEqual(null, list.Items.Where(x => x.GlobalId == supplements[1].GlobalId).Single().UserRating);
            });
        }
コード例 #2
0
        public void SavePlan_UserRatingInResult()
        {
            var profile = (ProfileDTO)profiles[0].Tag;

            SessionData data = CreateNewSession(profile, ClientInformation);

            var plan = createWorkoutPlanObject(profile);

            plan.Rating = 2;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                plan = Service.SaveWorkoutPlan(data.Token, plan);
            });
            RatingUserValue rating = new RatingUserValue();

            rating.RatedObjectId = plan.GlobalId;
            rating.Rating        = 2;
            rating.ProfileId     = profile.GlobalId;
            rating.VotedDate     = DateTime.UtcNow;
            insertToDatabase(rating);


            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                plan = Service.SaveWorkoutPlan(data.Token, plan);
            });
            Assert.AreEqual(rating.Rating, plan.UserRating);
            Assert.AreEqual(rating.ShortComment, plan.UserShortComment);
        }
コード例 #3
0
ファイル: VoteService.cs プロジェクト: robocik/BodyArchitect
        //public WorkoutPlanDTO VoteWorkoutPlan( WorkoutPlanDTO planDto)
        //{
        //    Log.WriteWarning("VoteWorkoutPlan: Username={0},planId={1}", SecurityInfo.SessionData.Profile.UserName, planDto.GlobalId);

        //    var session = Session;
        //    using (var tx = session.BeginTransaction())
        //    {
        //        var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id);
        //        var planFromDb = (from p in session.Query<BodyArchitect.Model.TrainingPlan>()
        //                          where p.GlobalId == planDto.GlobalId
        //                          select p).SingleOrDefault();
        //        saveRating(SecurityInfo, planDto, dbProfile, planFromDb);

        //        tx.Commit();

        //        try
        //        {
        //            //send message only when someone else vote
        //            if (planFromDb.Profile != dbProfile)
        //            {
        //                if (planFromDb.Profile.Settings.NotificationWorkoutPlanVoted)
        //                {
        //                    string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, planDto.UserRating);
        //                    MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification);
        //                    messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.WorkoutPlanVoted);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            ExceptionHandler.Default.Process(ex);
        //        }

        //        session.Refresh(planFromDb);
        //        Mapper.Map<BodyArchitect.Model.TrainingPlan, WorkoutPlanDTO>(planFromDb, planDto);
        //        return planDto;
        //    }

        //}

        //public ExerciseDTO VoteExercise( ExerciseDTO exercise)
        //{
        //    Log.WriteWarning("VoteExercise: Username={0},planId={1}", SecurityInfo.SessionData.Profile.UserName, exercise.GlobalId);

        //    var session = Session;
        //    using (var tx = session.BeginTransaction())
        //    {
        //        var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id);
        //        var planFromDb = (from p in session.Query<BodyArchitect.Model.Exercise>()
        //                          where p.GlobalId == exercise.GlobalId
        //                          select p).SingleOrDefault();
        //        saveRating(SecurityInfo, exercise, dbProfile, planFromDb);

        //        tx.Commit();

        //        try
        //        {
        //            //send message only when someone else vote
        //            if (planFromDb.Profile != null && planFromDb.Profile != dbProfile)
        //            {
        //                if (planFromDb.Profile.Settings.NotificationExerciseVoted)
        //                {
        //                    string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, exercise.UserRating);
        //                    MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification);
        //                    messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.ExerciseVoted);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            ExceptionHandler.Default.Process(ex);
        //        }

        //        session.Refresh(planFromDb);
        //        Mapper.Map<BodyArchitect.Model.Exercise, ExerciseDTO>(planFromDb, exercise);
        //        return exercise;
        //    }

        //}

        float saveRating(SecurityInfo SecurityInfo, VoteParams ratingable, Profile profile, BodyArchitect.Model.IRatingable globalObject)
        {
            var session = Session;

            if (ratingable.UserRating != null)// && (ratingObject == null || ratingObject != null && ratingObject.Rating != ratingable.UserRating.Value))
            {
                var ratingObject = (from rating in session.Query <RatingUserValue>()
                                    where rating.ProfileId == profile.GlobalId && rating.RatedObjectId == globalObject.GlobalId
                                    select rating).SingleOrDefault();

                if (ratingObject == null)
                {
                    ratingObject               = new RatingUserValue();
                    ratingObject.ProfileId     = profile.GlobalId;
                    ratingObject.RatedObjectId = globalObject.GlobalId;
                }
                ratingObject.LoginData    = SecurityInfo.LoginData;
                ratingObject.Rating       = ratingable.UserRating.Value;
                ratingObject.ShortComment = ratingable.UserShortComment;
                ratingObject.VotedDate    = Configuration.TimerService.UtcNow;
                session.SaveOrUpdate(ratingObject);
                ProfileStatisticsUpdater.UpdateVotings(session, profile);
                //session.SaveOrUpdate(globalObject);
                //var res = (from t in session.Query<RatingUserValue>() where t.RatedObjectId == globalObject.GlobalId select t).Average(t => t.Rating);
                var res = session.QueryOver <RatingUserValue>().Where(t => t.RatedObjectId == globalObject.GlobalId).
                          SelectList(t => t.SelectAvg(r => r.Rating)).SingleOrDefault <double>();
                globalObject.Rating = (float)res;
                session.SaveOrUpdate(globalObject);

                return((float)res);
            }
            return(globalObject.Rating);
        }
        public void GetUserRating()
        {
            RatingUserValue rating = new RatingUserValue();

            rating.RatedObjectId = definitions[0].GlobalId;
            rating.Rating        = 2;
            rating.ProfileId     = profiles[0].GlobalId;
            rating.VotedDate     = DateTime.UtcNow;
            insertToDatabase(rating);
            rating = new RatingUserValue();
            rating.RatedObjectId = definitions[0].GlobalId;
            rating.Rating        = 5;
            rating.ProfileId     = profiles[1].GlobalId;
            rating.VotedDate     = DateTime.UtcNow;
            insertToDatabase(rating);

            var                   param    = new GetSupplementsCycleDefinitionsParam();
            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;

            PagedResult <SupplementCycleDefinitionDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo);
            });
            Assert.AreEqual(2, result.Items.Where(x => x.GlobalId == definitions[0].GlobalId).Single().UserRating);
            Assert.AreEqual(null, result.Items.Where(x => x.GlobalId == definitions[1].GlobalId).Single().UserRating);
        }
コード例 #5
0
        public void ConvertExercises_WithRatings()
        {
            var profile1 = CreateProfile("profile1");
            var profile2 = CreateProfile("profile2");

            Model.Old.Exercise exercise = new Exercise(Guid.NewGuid());
            exercise.Name     = "Exercise name";
            exercise.Shortcut = "EX";
            insertToOldDatabase(exercise);

            RatingUserValue rating = new RatingUserValue();

            rating.ProfileId     = profile1.Id;
            rating.Rating        = 3;
            rating.RatedObjectId = exercise.GlobalId;
            rating.ShortComment  = "Comment";
            rating.VotedDate     = DateTime.Now.Date;
            insertToOldDatabase(rating);

            rating               = new RatingUserValue();
            rating.ProfileId     = profile2.Id;
            rating.Rating        = 5;
            rating.RatedObjectId = exercise.GlobalId;
            rating.ShortComment  = "Comment111";
            rating.VotedDate     = DateTime.Now.Date;
            insertToOldDatabase(rating);

            Convert();


            var newExercise = SessionNew.Get <Model.Exercise>(exercise.GlobalId);

            Assert.AreEqual(4, newExercise.Rating);
            var ratings = SessionNew.QueryOver <Model.RatingUserValue>().List();

            Assert.AreEqual(2, ratings.Count);
            var rating1 = ratings.Where(x => x.Rating == 3).Single();

            Assert.AreEqual("Comment", rating1.ShortComment);
            Assert.AreEqual(DateTime.Now.Date, rating1.VotedDate);
            Assert.AreEqual(newExercise.GlobalId, rating1.RatedObjectId);
            var newProfile1 = SessionNew.QueryOver <Model.Profile>().Where(x => x.UserName == "profile1").SingleOrDefault();

            Assert.AreEqual(newProfile1.GlobalId, rating1.ProfileId);


            var rating2 = ratings.Where(x => x.Rating == 5).Single();

            Assert.AreEqual("Comment111", rating2.ShortComment);
            Assert.AreEqual(DateTime.Now.Date, rating2.VotedDate);
            Assert.AreEqual(newExercise.GlobalId, rating2.RatedObjectId);
            var newProfile2 = SessionNew.QueryOver <Model.Profile>().Where(x => x.UserName == "profile2").SingleOrDefault();

            Assert.AreEqual(newProfile2.GlobalId, rating2.ProfileId);
        }
コード例 #6
0
        public void TestGetExercises_SortOrder_Rating()
        {
            RatingUserValue rating = new RatingUserValue();

            rating.RatedObjectId = exercises["t05"].GlobalId;
            rating.ProfileId     = profiles[0].Id;
            rating.Rating        = 5;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t02"].GlobalId;
            rating.ProfileId     = profiles[1].Id;
            rating.Rating        = 5;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t04"].GlobalId;
            rating.ProfileId     = profiles[1].Id;
            rating.Rating        = 3;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t01"].GlobalId;
            rating.ProfileId     = profiles[0].Id;
            rating.Rating        = 1;
            insertToDatabase(rating);

            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.SortOrder = WorkoutPlanSearchOrder.HighestRating;

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });
            Assert.AreEqual("t05", result.Items[0].Shortcut);
            Assert.AreEqual("t02", result.Items[1].Shortcut);
            Assert.AreEqual("t04", result.Items[2].Shortcut);
            Assert.AreEqual("t01", result.Items[3].Shortcut);
        }
コード例 #7
0
        public void ConvertPlan_Ratings()
        {
            string plan = @"<TrainingPlan>
  <Purpose>Mass</Purpose>
  <Language>pl</Language>
  <Author>jony0008</Author>
  <Comment><![CDATA[]]></Comment>
  <CreationDate>06/05/2011 21:05:23</CreationDate>
  <Difficult>Beginner</Difficult>
  <GlobalId>00c7057a-0694-4b2c-96f7-2c8d0e1cf445</GlobalId>
  <Name>mój plan FBW</Name>
  <RestSeconds>90</RestSeconds>
  <TrainingType>FBW</TrainingType>
  <Url></Url>
  <Days>
    <Day>
      <GlobalId>4cd10e23-170f-4374-b1ae-06e9774752ce</GlobalId>
      <Name>Dzień 1</Name>
      <Entries>
        <Entry>
          <ExerciseId>3e06a130-b811-4e45-9285-f087403615bf</ExerciseId>
          <GlobalId>aaae4427-e354-4323-bb0a-08053cacde18</GlobalId>
          <RestSeconds>90</RestSeconds>
          <Sets>
            <Set>
              <RepetitionNumberMax>12</RepetitionNumberMax>
              <RepetitionNumberMin>12</RepetitionNumberMin>
              <RepetitionsType>Normalna</RepetitionsType>
              <GlobalId>a6e905c6-a8cc-4840-a8d8-6a25dcafadcb</GlobalId>
              <DropSet>None</DropSet>
            </Set>
          </Sets>
        </Entry>
      </Entries>
      <SuperSets />
    </Day>
  </Days>
</TrainingPlan>";

            Model.Old.Profile oldProfile1 = CreateProfile("profile1");
            Model.Old.Profile oldProfile2 = CreateProfile("profile2");
            var oldExercise = CreateExercise("test", new Guid("3e06a130-b811-4e45-9285-f087403615bf"));

            Model.Old.TrainingPlan oldPlan = new TrainingPlan();
            oldPlan.GlobalId     = new Guid("00c7057a-0694-4b2c-96f7-2c8d0e1cf445");
            oldPlan.Profile      = oldProfile1;
            oldPlan.PlanContent  = plan;
            oldPlan.PublishDate  = DateTime.Now.Date;
            oldPlan.Purpose      = WorkoutPlanPurpose.Strength;
            oldPlan.Language     = "pl";
            oldPlan.Status       = PublishStatus.Published;
            oldPlan.Name         = "yyyyy";
            oldPlan.Author       = "Roemk";
            oldPlan.CreationDate = DateTime.UtcNow.Date.AddHours(1);
            oldPlan.Difficult    = TrainingPlanDifficult.Advanced;
            oldPlan.TrainingType = TrainingType.HST;
            insertToOldDatabase(oldPlan);

            RatingUserValue rating = new RatingUserValue();

            rating.ProfileId     = oldProfile1.Id;
            rating.Rating        = 3;
            rating.RatedObjectId = oldPlan.GlobalId;
            rating.ShortComment  = "Comment";
            rating.VotedDate     = DateTime.Now.Date;
            insertToOldDatabase(rating);

            rating               = new RatingUserValue();
            rating.ProfileId     = oldProfile2.Id;
            rating.Rating        = 5;
            rating.RatedObjectId = oldPlan.GlobalId;
            rating.ShortComment  = "Comment111";
            rating.VotedDate     = DateTime.Now.Date;
            insertToOldDatabase(rating);

            //another plan
            rating               = new RatingUserValue();
            rating.ProfileId     = oldProfile2.Id;
            rating.Rating        = 1;
            rating.RatedObjectId = Guid.NewGuid();
            rating.ShortComment  = "Comment111";
            rating.VotedDate     = DateTime.Now.Date;
            insertToOldDatabase(rating);

            Convert();

            var newPlan = SessionNew.QueryOver <Model.TrainingPlan>().SingleOrDefault();

            Assert.AreEqual(4, newPlan.Rating);
            var ratings = SessionNew.QueryOver <Model.RatingUserValue>().Where(x => x.RatedObjectId == newPlan.GlobalId).List();

            Assert.AreEqual(2, ratings.Count);
            var rating1 = ratings.Where(x => x.Rating == 3).Single();

            Assert.AreEqual("Comment", rating1.ShortComment);
            Assert.AreEqual(DateTime.Now.Date, rating1.VotedDate);
            Assert.AreEqual(newPlan.GlobalId, rating1.RatedObjectId);
            var newProfile1 = SessionNew.QueryOver <Model.Profile>().Where(x => x.UserName == "profile1").SingleOrDefault();

            Assert.AreEqual(newProfile1.GlobalId, rating1.ProfileId);


            var rating2 = ratings.Where(x => x.Rating == 5).Single();

            Assert.AreEqual("Comment111", rating2.ShortComment);
            Assert.AreEqual(DateTime.Now.Date, rating2.VotedDate);
            Assert.AreEqual(newPlan.GlobalId, rating2.RatedObjectId);
            var newProfile2 = SessionNew.QueryOver <Model.Profile>().Where(x => x.UserName == "profile2").SingleOrDefault();

            Assert.AreEqual(newProfile2.GlobalId, rating2.ProfileId);
        }
コード例 #8
0
        public override void BuildDatabase()
        {
            using (var tx = Session.BeginTransaction())
            {
                profiles.Clear();
                profiles.Add(CreateProfile(Session, "test1"));
                profiles.Add(CreateProfile(Session, "test2"));
                profiles.Add(CreateProfile(Session, "test3"));
                profiles.Add(CreateProfile(Session, "test4"));

                profiles[0].Wymiary     = new Wymiary();
                profiles[0].Wymiary.Pas = 102;

                Session.SaveOrUpdate(profiles[0]);



                TrainingDay day = new TrainingDay(DateTime.Now);
                day.Profile = profiles[0];
                StrengthTrainingEntry strengthEntry = new StrengthTrainingEntry();
                StrengthTrainingItem  item          = new StrengthTrainingItem();
                strengthEntry.AddEntry(item);
                item.ExerciseId = Guid.NewGuid();
                Serie serie = new Serie("10x20");
                item.AddSerie(serie);
                day.AddEntry(strengthEntry);
                SizeEntry sizeEntry = new SizeEntry();
                sizeEntry.Wymiary        = new Wymiary();
                sizeEntry.Wymiary.Height = 100;
                day.AddEntry(sizeEntry);
                SuplementsEntry suplementsEntry = new SuplementsEntry();
                SuplementItem   suplementItem   = new SuplementItem();
                suplementItem.SuplementId = Guid.NewGuid();
                suplementItem.Name        = "fdgdfg";
                suplementsEntry.AddItem(suplementItem);
                day.AddEntry(suplementsEntry);
                BlogEntry blogEntry = new BlogEntry();
                day.AddEntry(blogEntry);
                A6WEntry a6WEntry = new A6WEntry();
                a6WEntry.DayNumber          = 1;
                a6WEntry.MyTraining         = new MyTraining();
                a6WEntry.MyTraining.Name    = "fdgdfg";
                a6WEntry.MyTraining.TypeId  = A6WEntry.EntryTypeId;
                a6WEntry.MyTraining.Profile = profiles[0];
                day.AddEntry(a6WEntry);
                Session.Save(day);

                BlogComment comment = new BlogComment();
                comment.BlogEntry = blogEntry;
                comment.Profile   = profiles[1];
                comment.Comment   = "fgdfgd";
                Session.Save(comment);
                comment           = new BlogComment();
                comment.BlogEntry = blogEntry;
                comment.Comment   = "fgdfgd";
                comment.Profile   = profiles[0];
                Session.Save(comment);

                Session.Update(blogEntry);

                Exercise exercise = new Exercise(Guid.NewGuid());
                exercise.Profile  = profiles[0];
                exercise.Name     = "Private";
                exercise.Shortcut = "PP";
                Session.Save(exercise);

                exercise             = new Exercise(Guid.NewGuid());
                exercise.Profile     = profiles[0];
                exercise.Name        = "Public";
                exercise.Shortcut    = "PP";
                exercise.Status      = PublishStatus.Published;
                exercise.PublishDate = DateTime.UtcNow;
                Session.Save(exercise);

                RatingUserValue exComment = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = exercise.GlobalId;
                Session.Save(exComment);

                exercise             = new Exercise(Guid.NewGuid());
                exercise.Profile     = profiles[1];
                exercise.Name        = "Public1";
                exercise.Shortcut    = "PP1";
                exercise.Status      = PublishStatus.Published;
                exercise.PublishDate = DateTime.UtcNow;
                Session.Save(exercise);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = exercise.GlobalId;
                Session.Save(exComment);

                TrainingPlan plan = new TrainingPlan();
                plan.Profile     = profiles[0];
                plan.GlobalId    = Guid.NewGuid();
                plan.Language    = "pl";
                plan.Author      = "dfgdfg";
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                plan             = new TrainingPlan();
                plan.Profile     = profiles[0];
                plan.Language    = "pl";
                plan.GlobalId    = Guid.NewGuid();
                plan.Author      = "dfgdfg";
                plan.Status      = PublishStatus.Published;
                plan.PublishDate = DateTime.UtcNow;
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(exComment);

                plan             = new TrainingPlan();
                plan.Profile     = profiles[1];
                plan.Language    = "pl";
                plan.GlobalId    = Guid.NewGuid();
                plan.Author      = "dfgdfg";
                plan.Status      = PublishStatus.Published;
                plan.PublishDate = DateTime.UtcNow;
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(plan);


                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(exComment);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(plan);

                Message msg = new Message();
                msg.Receiver = profiles[0];
                msg.Sender   = profiles[1];
                msg.Topic    = "dfgdfgdf";
                Session.Save(msg);
                msg          = new Message();
                msg.Receiver = profiles[1];
                msg.Sender   = profiles[0];
                msg.Topic    = "dfgdfgdf";
                Session.Save(msg);

                FriendInvitation invitation = new FriendInvitation();
                invitation.Invited    = profiles[0];
                invitation.Inviter    = profiles[2];
                invitation.CreateDate = DateTime.UtcNow;
                Session.Save(invitation);

                invitation            = new FriendInvitation();
                invitation.Invited    = profiles[3];
                invitation.Inviter    = profiles[0];
                invitation.CreateDate = DateTime.UtcNow;
                Session.Save(invitation);

                profiles[0].Friends.Add(profiles[1]);
                profiles[1].Friends.Add(profiles[0]);
                profiles[1].Statistics.FriendsCount = 1;

                profiles[0].FavoriteUsers.Add(profiles[1]);
                profiles[1].Statistics.FollowersCount = 1;
                profiles[0].FavoriteWorkoutPlans.Add(plan);

                profiles[2].FavoriteUsers.Add(profiles[0]);
                Session.Update(profiles[0]);
                Session.Update(profiles[1]);
                Session.Update(profiles[2]);
                tx.Commit();
            }
        }
コード例 #9
0
        public override void BuildDatabase()
        {
            using (var tx = Session.BeginTransaction())
            {
                profiles.Clear();
                comments.Clear();
                profiles.Add(CreateProfile(Session, "test1"));
                profiles.Add(CreateProfile(Session, "test2"));
                profiles.Add(CreateProfile(Session, "test3"));

                apiKey                  = new APIKey();
                apiKey.ApiKey           = Guid.NewGuid();
                apiKey.ApplicationName  = "UnitTest";
                apiKey.EMail            = "*****@*****.**";
                apiKey.RegisterDateTime = DateTime.UtcNow;
                insertToDatabase(apiKey);

                var apiKey1 = new APIKey();
                apiKey1.ApiKey           = Guid.NewGuid();
                apiKey1.ApplicationName  = "UnitTest";
                apiKey1.EMail            = "*****@*****.**";
                apiKey1.RegisterDateTime = DateTime.UtcNow;
                insertToDatabase(apiKey1);

                LoginData loginData1 = new LoginData();
                loginData1.ApiKey              = apiKey;
                loginData1.ApplicationVersion  = "1.0.0";
                loginData1.LoginDateTime       = DateTime.UtcNow;
                loginData1.ApplicationLanguage = "en";
                loginData1.PlatformVersion     = "NUnit";
                insertToDatabase(loginData1);

                var loginData2 = new LoginData();
                loginData2.ApiKey              = apiKey1;
                loginData2.ApplicationVersion  = "1.0.0";
                loginData2.LoginDateTime       = DateTime.UtcNow;
                loginData2.ApplicationLanguage = "en";
                loginData2.PlatformVersion     = "NUnit";
                insertToDatabase(loginData2);

                globalId1 = Guid.NewGuid();
                RatingUserValue comment = new RatingUserValue();
                comment.ProfileId     = profiles[0].GlobalId;
                comment.ShortComment  = "t1";
                comment.Rating        = 3;
                comment.RatedObjectId = globalId1;
                comment.LoginData     = loginData1;
                comments.Add(comment);
                Session.Save(comment);

                comment               = new RatingUserValue();
                comment.ProfileId     = profiles[1].GlobalId;
                comment.ShortComment  = "t2";
                comment.Rating        = 1;
                comment.RatedObjectId = globalId1;
                comment.LoginData     = loginData2;
                comments.Add(comment);
                Session.Save(comment);

                comment               = new RatingUserValue();
                comment.ProfileId     = profiles[2].GlobalId;
                comment.ShortComment  = "t2";
                comment.Rating        = 5;
                comment.RatedObjectId = globalId1;
                comments.Add(comment);
                Session.Save(comment);


                tx.Commit();
            }
        }