public void TestStats_ShouldRenderDefaultViewWithCorrectModel(string userId) { // Arrange var model = new NutritionStatsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateNutritionStatsViewModel(It.IsAny <IEnumerable <Nutrition> >())).Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedNutritionService = new Mock <INutritionService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId); var controller = new NutritionController(mockedFactory.Object, mockedDateTimeProvider.Object, mockedNutritionService.Object, mockedAuthenticationProvider.Object); // Act, Assert controller .WithCallTo(c => c.Stats(null)) .ShouldRenderDefaultPartialView() .WithModel <NutritionStatsViewModel>(m => Assert.AreSame(model, m)); }
public void TestStats_NoIdProvidedAndIsAuthenticated_ShouldSetModelCanDeleteToTrue() { // Arrange var model = new NutritionStatsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateNutritionStatsViewModel(It.IsAny <IEnumerable <Nutrition> >())).Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedNutritionService = new Mock <INutritionService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); mockedAuthenticationProvider.Setup(p => p.IsAuthenticated).Returns(true); var controller = new NutritionController(mockedFactory.Object, mockedDateTimeProvider.Object, mockedNutritionService.Object, mockedAuthenticationProvider.Object); // Act controller.Stats(null); // Assert Assert.IsTrue(model.CanDelete); }
public void TestStats_ShouldCallFactoryCreateNutritionStatsViewModel(string userId) { // Arrange var model = new NutritionStatsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateNutritionStatsViewModel(It.IsAny <IEnumerable <Nutrition> >())).Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var nutritions = new List <Nutrition> { new Nutrition(), new Nutrition() }; var mockedNutritionService = new Mock <INutritionService>(); mockedNutritionService.Setup(s => s.GetUserNutritionsSortedByDate(It.IsAny <string>())).Returns(nutritions); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId); var controller = new NutritionController(mockedFactory.Object, mockedDateTimeProvider.Object, mockedNutritionService.Object, mockedAuthenticationProvider.Object); // Act controller.Stats(null); // Assert mockedFactory.Verify(f => f.CreateNutritionStatsViewModel(nutritions), Times.Once); }
public void TestConstructor_ShouldInitializeCorrectly() { // Arrange, Act var model = new NutritionStatsViewModel(); // Assert Assert.IsNotNull(model); }
public void TestConstructor_ShouldSetFatsCorrectly(int calories, int protein, int carbs, int fats, double water, int fiber, int sugar, string notes, string userId) { // Arrange, var date = new DateTime(2, 3, 4); var nutrition = new global::Logs.Models.Nutrition(calories, protein, carbs, fats, water, fiber, sugar, notes, userId, date); var list = new List <global::Logs.Models.Nutrition> { nutrition }; var expected = list.Select(m => m.Fats); // Act var model = new NutritionStatsViewModel(list); // Assert CollectionAssert.AreEqual(expected, model.Fats); }
public void TestConstructor_ShouldSetListModelCorrectly(int calories, int protein, int carbs, int fats, double water, int fiber, int sugar, string notes, string userId) { // Arrange, var date = new DateTime(2, 3, 4); var nutrition = new global::Logs.Models.Nutrition(calories, protein, carbs, fats, water, fiber, sugar, notes, userId, date); var list = new List <global::Logs.Models.Nutrition> { nutrition }; var expected = list.Select(m => new DateIdViewModel(m.NutritionId, m.Date.ToString("dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture))) .Reverse(); // Act var model = new NutritionStatsViewModel(list); // Assert CollectionAssert.AllItemsAreNotNull(model.ListModel); }
public void TestStats_WithId_ShouldNotCallAuthenticationProviderCurrentUserId(string userId) { // Arrange var model = new NutritionStatsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateNutritionStatsViewModel(It.IsAny <IEnumerable <Nutrition> >())).Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedNutritionService = new Mock <INutritionService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new NutritionController(mockedFactory.Object, mockedDateTimeProvider.Object, mockedNutritionService.Object, mockedAuthenticationProvider.Object); // Act controller.Stats(userId); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Never); }
public void TestStats_NoIdProvided_ShouldCallAuthenticationIsAuthenticated() { // Arrange var model = new NutritionStatsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateNutritionStatsViewModel(It.IsAny <IEnumerable <Nutrition> >())).Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedNutritionService = new Mock <INutritionService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new NutritionController(mockedFactory.Object, mockedDateTimeProvider.Object, mockedNutritionService.Object, mockedAuthenticationProvider.Object); // Act controller.Stats(null); // Assert mockedAuthenticationProvider.Verify(p => p.IsAuthenticated, Times.Once); }