Inheritance: Entity
コード例 #1
0
        public decimal GetRDI(User user, DateTime date, NutrientEntity nutrientEntity)
        {
            var dailyCalorieNeed = userProfileBusinessLogic.GetDailyCalorieNeed(user);

            //9 kcal/gram ger kolhydrater i energi. 15 - 30 % av vårt energiintag bör bestå av fett
            return (dailyCalorieNeed * 0.3M) / 9;
        }
コード例 #2
0
        public void shouldReturnWeightPrognosisXml()
        {
            AutoMappingsBootStrapper.MapHistoryGraphToAmChartData();

            var user = new User("Min user");
            var userContextMock = new Mock<IUserContext>(MockBehavior.Strict);
            userContextMock.Setup(x => x.User).Returns(user);

            var graphBuilderMock = new Mock<IGraphBuilder>(MockBehavior.Strict);

            ILine line = new Line(1, new Dictionary<DateTime, decimal> { { DateTime.Now.AddDays(1), 35M } }, "MyTitle");
            var graph = new Graph { Labels = new[] { new Label { Value = "val1", Index = "1" } }, LinesContainer = new LinesContainer { Lines = new[] { line } } };
            var userWeightBusinessLogicMock = new Mock<IUserWeightBusinessLogic>();
            userWeightBusinessLogicMock.Setup(x => x.GetProjectionList(It.Is<User>(y => y == user))).Returns(line);
            graphBuilderMock.Setup(x => x.GetGraph(It.Is<ILine[]>(y => y[0] == line))).Returns(graph);

            var resultController = new CarbonFitness.App.Web.Controllers.ResultController(null, null, userContextMock.Object, graphBuilderMock.Object, userWeightBusinessLogicMock.Object, null);

            var result = resultController.ShowWeightPrognosisXml();
            Assert.That(result.ObjectToSerialize, Is.AssignableTo(typeof(AmChartData)));

            var amChartData = (AmChartData) result.ObjectToSerialize;
            var dataPoints = amChartData.DataPoints;
            Assert.That(dataPoints, Is.Not.Null);

            var firstPoint = dataPoints.First();
            Assert.That(firstPoint.Value, Is.EqualTo("val1"));

            Assert.That(amChartData.GraphRoot.Graphs[0].values[0].Value, Is.EqualTo("35"));
            userWeightBusinessLogicMock.Verify();
        }
コード例 #3
0
 public ActivityLevelType GetActivityLevel(User user)
 {
     var activityLevel = GetUserProfile(user).ActivityLevel;
     if(activityLevel == null) {
         return GetActivityLevelFromString("Låg");
     }
     return activityLevel;
 }
コード例 #4
0
 public decimal GetBMI(User user)
 {
     var profile = GetUserProfile(user);
     if(profile.Length == 0 ) {
         return 0;
     }
     var lenghtInMeter = profile.Length / 100;
     return profile.Weight / (lenghtInMeter * lenghtInMeter);
 }
コード例 #5
0
        public ILine GetNutrientHistory(NutrientEntity nutrientEntity, User user)
        {
            var userIngredients = Get100DaysUserIngredients(user);

            var valueSumPerDateFromUserIngredients = GetValueSumPerDateFromUserIngredients(userIngredients, x => x.GetNutrientIngredientDisplayValue(x.GetNutrient(nutrientEntity)));

            int nutrientId = nutrientRepository.GetByName(nutrientEntity.ToString()).Id;
            return new Line(nutrientId, valueSumPerDateFromUserIngredients);
        }
コード例 #6
0
 public UserIngredient AddUserIngredient(User user, string ingredientName, int measure, DateTime dateTime)
 {
     var userIngredient = new UserIngredient();
     userIngredient.User = user;
     userIngredient.Ingredient = GetExistingIngredient(ingredientName);
     userIngredient.Measure = measure;
     userIngredient.Date = dateTime.AddSeconds(1); // Otherwise it will show up on both today and yesterday
     return userIngredientRepository.SaveOrUpdate(userIngredient);
 }
コード例 #7
0
        protected override void LoadTestData()
        {
            var userRepository = new UserRepository();
            userA = userRepository.SaveOrUpdate(new User());

            userProfileRepository = new UserProfileRepository();
            userProfileRepository.SaveOrUpdate(new UserProfile() { User = userA });

            NHibernateSession.Current.Flush();
        }
コード例 #8
0
ファイル: InputTest.cs プロジェクト: yodiz/CarbonFitness
        public void SetUp()
        {
            expectedDate = DateTime.Now.AddDays(42).Date;
            expectedWeight = 80M;
            expectedUser = new User {Username = "******"};

            userWeightBusinessLogicMock = new Mock<IUserWeightBusinessLogic>();
            userContextMock = new Mock<IUserContext>();
            userContextMock.Setup(x => x.User).Returns(expectedUser);
        }
コード例 #9
0
 public IEnumerable<SelectListItem> GetViewTypes(User user)
 {
     var nutrientOptions = new List<SelectListItem>();
     addGraphlineOption("Vikt (kg)", "Weight", nutrientOptions);
     IEnumerable<Nutrient> nutrients = nutrientBusinessLogic.GetNutrients();
     foreach (Nutrient nutrient in nutrients) {
         addGraphlineOption(nutrientTranslator.GetString(nutrient.Name), nutrient.Name, nutrientOptions);
     }
     return nutrientOptions;
 }
コード例 #10
0
        public User Create(User user)
        {
            var existingUser = userRepository.Get(user.Username);
            if (existingUser != null) {
                throw new UserAlreadyExistException(user.Username);
            }

            var savedUser = userRepository.Save(user);
            userProfileRepository.Save(new UserProfile {User = savedUser});
            return savedUser;
        }
コード例 #11
0
        public void shouldGetUserFromThreadIdentity()
        {
            var userBusinessLogicMock = new Mock<IUserBusinessLogic>();
            userBusinessLogicMock.Setup(x => x.Get(It.IsAny<string>())).Returns(new User {Username = "******"});
            var user = new User("myUser");
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("myUser"), null);
            Assert.That(new UserContext(userBusinessLogicMock.Object, null).User.Username, Is.EqualTo(user.Username));

            userBusinessLogicMock.Setup(x => x.Get(It.IsAny<string>())).Returns(new User {Username = "******"});

            var newUserName = "******";
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(newUserName), null);
            Assert.That(new UserContext(userBusinessLogicMock.Object, null).User.Username, Is.EqualTo(newUserName));
        }
コード例 #12
0
        public void shouldCreateUserProfileWhenCreatingAUser()
        {
            var user = new User();
            var userProfileRepositoryMock = new Mock<IUserProfileRepository>(MockBehavior.Strict);
            userProfileRepositoryMock.Setup(x => x.Save(It.Is<UserProfile>(y=> y.User == user))).Returns(new UserProfile());

            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(x => x.Save(user)).Returns(user);

            var userBusinessLogic = new UserBusinessLogic(userRepositoryMock.Object, userProfileRepositoryMock.Object);
            userBusinessLogic.Create(user);

            userProfileRepositoryMock.VerifyAll();
        }
コード例 #13
0
        public UserWeight SaveWeight(User user, decimal weight, DateTime date)
        {
            if (weight == 0) {
                throw new InvalidWeightException("Cannot save zero weight");
            }

            var userWeight = userWeightRepository.FindByDate(user, date);

            if (userWeight == null) {
                userWeight = new UserWeight {Date = date, User = user, Weight = weight};
            }

            userWeight.Weight = weight;

            var savedUserWeight = userWeightRepository.SaveOrUpdate(userWeight);
            return savedUserWeight;
        }
コード例 #14
0
ファイル: CreateTest.cs プロジェクト: yodiz/CarbonFitness
        public void shouldPassCreatedUserIdToDetails()
        {
            var userName = "******";
            var password = "******";

            var factory = new MockFactory(MockBehavior.Strict);
            var userContextMock = new Mock<IUserContext>();
            var mock = factory.Create<IUserBusinessLogic>();
            var createdUser = new User {Username = userName};
            mock.Setup(x => x.Create(It.Is<User>(y => y.Username == userName))).Returns(createdUser);

            var controller = new CarbonFitness.App.Web.Controllers.UserController(mock.Object, userContextMock.Object);
            var viewResult = (RedirectToRouteResult) controller.Create(userName, password);

            var idRouteValue = viewResult.RouteValues["id"];
            Assert.That(idRouteValue.ToString() == createdUser.Id.ToString(), "Expected id" + createdUser.Id + ", but was:" + idRouteValue);
        }
コード例 #15
0
        public void shouldFindByDate()
        {
            var expectedDate = DateTime.Now.Date;
            var expectedWeight = 80.5M;

            var user = new User("UserWeightRepositoryFindByDateTester");
            var userWeight = new UserWeight {Date = expectedDate, User = user, Weight = expectedWeight};

            NHibernateSession.Current.Save(user);
            NHibernateSession.Current.Save(userWeight);

            var repository = new UserWeightRepository();
            var foundUserWeight = repository.FindByDate(user, expectedDate);

            Assert.That(foundUserWeight, Is.Not.Null);
            Assert.That(foundUserWeight.Date, Is.EqualTo(expectedDate));
            Assert.That(foundUserWeight.Weight, Is.EqualTo(expectedWeight));
        }
コード例 #16
0
        public INutrientAverage GetNutrientAverage(IEnumerable<NutrientEntity> nutrientEntities, User user)
        {
            var result = new NutrientAverage();
            result.NutrientValues = new Dictionary<NutrientEntity, decimal>();

            var nutrientSums = GetNutrientSumList(nutrientEntities, user);
            if(nutrientSums.Count() == 0) {
                return result;
            }

            foreach (var nutrientEntity in nutrientEntities) {
                var nutrientSum = 0M;
                foreach (var sum in nutrientSums) {
                    nutrientSum += sum.NutrientValues[nutrientEntity];
                }
                var average = nutrientSum / nutrientSums.Count();
                result.NutrientValues.Add(nutrientEntity, average);
            }
            return result;
        }
コード例 #17
0
        public void shouldGetHistoryListInDateOrder()
        {
            const string username = "******";
            var user = new User(username);
            NHibernateSession.Current.Save(user);

            for (var i = 0; i < 10; i++) {
                NHibernateSession.Current.Save(new UserWeight { Date = ValueGenerator.getRandomDate(), Weight = i, User = user });
            }

            var result = new UserWeightRepository().GetHistoryList(user);

            Assert.That(result.Count(), Is.EqualTo(10));

            var tempDate = DateTime.MinValue;
            foreach (var userWeight in result) {
                Assert.That(userWeight.Date, Is.GreaterThanOrEqualTo(tempDate));
                tempDate = userWeight.Date;
            }
        }
コード例 #18
0
        public void shouldGetHistoryList()
        {
            const string username = "******";
            var user = new User(username);

            var session = NHibernateSession.Current;

            session.Save(user);

            for (var i = 0; i < 5; i++) {
                session.Save(new UserWeight { Date = DateTime.Now.AddDays(i), Weight = i, User = user });
                session.Flush();
            }

            var repository = new UserWeightRepository();

            var result = repository.GetHistoryList(user);

            Assert.That(result.ElementAt(0).Weight, Is.EqualTo(0));
            Assert.That(result.Count(), Is.EqualTo(5));
            Assert.That(result.Where(x => x.User.Username == username).Count(), Is.EqualTo(5));
        }
コード例 #19
0
        protected override void LoadTestData()
        {
            var ingredientRepository = new IngredientRepository();
            ingredient = ingredientRepository.SaveOrUpdate(new Ingredient {Name = "Pannbiff"});

            user = new UserRepository().Save(new User { Username = "******" });
            user2 = new UserRepository().Save(new User { Username = "******" });
            var user3 = new UserRepository().Save(new User { Username = "******" });
            NHibernateSession.Current.Flush();

            var userIngredientRepository = new UserIngredientRepository();

            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 10, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 100, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 200, User = user, Date = now.AddDays(-1)});

            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 10, User = user2, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 100, User = user3, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 200, User = user2, Date = now.AddDays(-1) });

            NHibernateSession.Current.Flush();
        }
コード例 #20
0
        private void AssertProperty(object expectedResult, User user, UserProfile resultProfile, Func<UserProfileBusinessLogic, object> propertyToFetch)
        {
            var userProfileRepositoryMock = new Mock<IUserProfileRepository>();
            userProfileRepositoryMock.Setup(x => x.GetByUserId(user.Id)).Returns(resultProfile);

            var result = propertyToFetch(new UserProfileBusinessLogic(userProfileRepositoryMock.Object, null, null, null));

            Assert.That(result, Is.EqualTo(expectedResult));
            userProfileRepositoryMock.VerifyAll();
        }
コード例 #21
0
 private UserProfile GetUserProfile(User user)
 {
     if (userProfile == null) {
         userProfile = UserProfileRepository.GetByUserId(user.Id);
         if (userProfile == null) {
             userProfile = new UserProfile {User = user, IdealWeight = 0};
         }
     }
     return userProfile;
 }
コード例 #22
0
 public decimal GetIdealWeight(User user)
 {
     return GetUserProfile(user).IdealWeight;
 }
コード例 #23
0
 public GenderType GetGender(User user)
 {
     var gender = GetUserProfile(user).Gender;
     if(gender == null) {
         return GetGenderTypeFromString("Man"); //Default
     }
     return gender;
 }
コード例 #24
0
 public decimal GetDailyCalorieNeed(User user)
 {
     return CalorieCalculator.GetDailyCalorieNeed(GetWeight(user), GetLength(user), GetAge(user), GetGender(user), GetActivityLevel(user));
 }
コード例 #25
0
 public decimal GetBMR(User user)
 {
     return CalorieCalculator.GetBMR(GetWeight(user), GetLength(user), GetAge(user), GetGender(user));
 }
コード例 #26
0
 public decimal GetLength(User user)
 {
     return GetUserProfile(user).Length;
 }
コード例 #27
0
 public decimal GetWeight(User user)
 {
     return GetUserProfile(user).Weight;
 }
コード例 #28
0
 public IEnumerable<SelectListItem> GetViewTypes(User user)
 {
     return PopulateViewTypes(GenderTypeBusinessLogic.GetGenderTypes().ToArray(), UserProfileBusinessLogic.GetGender(user));
 }
コード例 #29
0
 public int GetAge(User user)
 {
     return GetUserProfile(user).Age;
 }
コード例 #30
0
 public void SaveProfile(User user, decimal idealWeight, decimal length, decimal weight, int age, string genderName, string activityLevelName)
 {
     var userProfile = GetUserProfile(user);
     userProfile.IdealWeight = idealWeight;
     userProfile.Length = length;
     userProfile.Weight = weight;
     userProfile.Age = age;
     userProfile.Gender = GetGenderTypeFromString(genderName);
     userProfile.ActivityLevel = GetActivityLevelFromString(activityLevelName);
     UserProfileRepository.SaveOrUpdate(userProfile);
 }