public void shouldGetBMI() { const decimal weight = 73M; const decimal length = 183M; var userProfile = new UserProfile { Weight = weight, Length = length, User = User }; var userProfileRepositoryMock = new Mock<IUserProfileRepository>(); userProfileRepositoryMock.Setup(x => x.GetByUserId(User.Id)).Returns(userProfile); var result = new UserProfileBusinessLogic(userProfileRepositoryMock.Object, null, null, null).GetBMI(User); var lenghtInMeter = length / 100; Assert.That(result, Is.EqualTo(weight / (lenghtInMeter * lenghtInMeter))); }
public void shouldGetBMR() { const decimal weight = 83M; const int age = 24; const int height = 174; var gender = new GenderType{Name="Man"}; var activityLevel = new ActivityLevelType { Name = "Medel" }; var calorieCalculator = new Mock<ICalorieCalculator>(); var userProfile = new UserProfile { Weight = weight, Age = age, Length = height , Gender = gender, ActivityLevel = activityLevel, User = User }; var userProfileRepositoryMock = new Mock<IUserProfileRepository>(); userProfileRepositoryMock.Setup(x => x.GetByUserId(User.Id)).Returns(userProfile); calorieCalculator.Setup(x => x.GetBMR(weight, height, age, gender)).Returns(123); var result = new UserProfileBusinessLogic(userProfileRepositoryMock.Object, null, null, calorieCalculator.Object).GetBMR(User); Assert.That(result, Is.EqualTo(123)); }
public void shouldGetActivityLevel() { var expectedActivityLevel = new ActivityLevelType(); var userProfile = new UserProfile { ActivityLevel = expectedActivityLevel, User = User }; AssertProperty(expectedActivityLevel, User, userProfile, x => x.GetActivityLevel(User)); }
public void shouldGetAge() { const int expectedAge = 24; var userProfile = new UserProfile { Age = expectedAge, User = User }; AssertProperty(expectedAge, User, userProfile, x => x.GetAge(User)); }
public void shouldIfNoGenderExistDefaultMale() { GenderType expectedGender = null; var userProfileRepositoryMock = new Mock<IUserProfileRepository>(); var userProfile = new UserProfile { Gender = expectedGender, User = User }; userProfileRepositoryMock.Setup(x => x.GetByUserId(User.Id)).Returns(userProfile); var genderTypeBusinessLogic = new Mock<IGenderTypeBusinessLogic>(); genderTypeBusinessLogic.Setup(x => x.GetGenderType(It.IsAny<string>())).Returns(new GenderType {Name = "Man"}); var result = new UserProfileBusinessLogic(userProfileRepositoryMock.Object, genderTypeBusinessLogic.Object, null, null).GetGender(User); Assert.That(result.Name, Is.EqualTo("Man")); }
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(); }
public void shouldGetZeroAsBMIIfLenghtIsZero() { const decimal weight = 83M; var userProfile = new UserProfile { Weight = weight, Length = 0, User = User }; var userProfileRepositoryMock = new Mock<IUserProfileRepository>(); userProfileRepositoryMock.Setup(x => x.GetByUserId(User.Id)).Returns(userProfile); var result = new UserProfileBusinessLogic(userProfileRepositoryMock.Object, null, null, null).GetBMI(User); Assert.That(result, Is.EqualTo(0)); }
public void shouldGetWeight() { const decimal expectedWeight = 83M; var userProfile = new UserProfile { Weight = expectedWeight, User = User }; AssertProperty(expectedWeight, User, userProfile, x => x.GetWeight(User)); }
public void shouldGetLength() { const decimal expectedLength = 1.83M; var userProfile = new UserProfile { Length = expectedLength, User = User }; AssertProperty(expectedLength, User, userProfile, x => x.GetLength(User)); }
public void shouldGetGender() { var expectedGender = new GenderType(); var userProfile = new UserProfile { Gender = expectedGender, User = User }; AssertProperty(expectedGender, User, userProfile, x => x.GetGender(User)); }
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; }