Ejemplo n.º 1
0
        public void TestConstructor_ShouldSetListModelCorrectly(int height,
                                                                double weightKg,
                                                                double bodyFatPercent,
                                                                int chest,
                                                                int shoulders,
                                                                int forearm,
                                                                int arm,
                                                                int waist,
                                                                int hips,
                                                                int thighs,
                                                                int calves,
                                                                int neck,
                                                                int wrist,
                                                                int ankle,
                                                                string userId)
        {
            // Arrange,
            var date        = new DateTime(2, 3, 4);
            var measurement = new global::Logs.Models.Measurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                                                  calves, neck, wrist, ankle, userId, date);

            var list = new List <global::Logs.Models.Measurement> {
                measurement
            };

            var expected = list.Select(m => new DateIdViewModel(m.MeasurementsId,
                                                                m.Date.ToString("dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)))
                           .Reverse();

            // Act
            var model = new MeasurementStatsViewModel(list);

            // Assert
            CollectionAssert.AllItemsAreNotNull(model.ListModel);
        }
Ejemplo n.º 2
0
        public void TestConstructor_ShouldSetAnkleCorrectly(int height,
                                                            double weightKg,
                                                            double bodyFatPercent,
                                                            int chest,
                                                            int shoulders,
                                                            int forearm,
                                                            int arm,
                                                            int waist,
                                                            int hips,
                                                            int thighs,
                                                            int calves,
                                                            int neck,
                                                            int wrist,
                                                            int ankle,
                                                            string userId)
        {
            // Arrange,
            var date        = new DateTime(2, 3, 4);
            var measurement = new global::Logs.Models.Measurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs,
                                                                  calves, neck, wrist, ankle, userId, date);

            var list = new List <global::Logs.Models.Measurement> {
                measurement
            };

            var expected = list.Select(m => m.Ankle);

            // Act
            var model = new MeasurementStatsViewModel(list);

            // Assert
            CollectionAssert.AreEqual(expected, model.Ankle);
        }
Ejemplo n.º 3
0
        public void TestStats_NoIdProvidedAndIsAuthenticated_ShouldSetModelCanDeleteToTrue()
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var mockedMeasurementService = new Mock <IMeasurementService>();

            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            mockedAuthenticationProvider.Setup(p => p.IsAuthenticated).Returns(true);

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act
            controller.Stats(null);

            // Assert
            Assert.IsTrue(model.CanDelete);
        }
Ejemplo n.º 4
0
        public void TestStats_NoIdProvidedAndIsAuthenticated_ShouldCallAuthenticationProviderCurrentUserId()
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var mockedMeasurementService = new Mock <IMeasurementService>();

            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            mockedAuthenticationProvider.Setup(p => p.IsAuthenticated).Returns(true);

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act
            controller.Stats(null);

            // Assert
            mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Once);
        }
Ejemplo n.º 5
0
        public void TestStats_ShouldRenderDefaultViewWithCorrectModel(string userId)
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var mockedMeasurementService = new Mock <IMeasurementService>();

            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId);

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act, Assert
            controller
            .WithCallTo(c => c.Stats(null))
            .ShouldRenderDefaultPartialView()
            .WithModel <MeasurementStatsViewModel>(m => Assert.AreSame(model, m));
        }
Ejemplo n.º 6
0
        public void TestStats_ShouldCallFactoryCreateMeasurementStatsViewModel(string userId)
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var measurements = new List <Measurement> {
                new Measurement(), new Measurement()
            };

            var mockedMeasurementService = new Mock <IMeasurementService>();

            mockedMeasurementService.Setup(s => s.GetUserMeasurementsSortedByDate(It.IsAny <string>())).Returns(measurements);

            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId);

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act
            controller.Stats(null);

            // Assert
            mockedFactory.Verify(f => f.CreateMeasurementStatsViewModel(measurements), Times.Once);
        }
Ejemplo n.º 7
0
        public void TestConstructor_ShouldInitializeCorrectly()
        {
            // Arrange, Act
            var model = new MeasurementStatsViewModel();

            // Assert
            Assert.IsNotNull(model);
        }
Ejemplo n.º 8
0
        public void TestStats_WithId_ShouldNotCallAuthenticationProviderCurrentUserId(string userId)
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var mockedMeasurementService     = new Mock <IMeasurementService>();
            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act
            controller.Stats(userId);

            // Assert
            mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Never);
        }
Ejemplo n.º 9
0
        public void TestStats_IsNotAuthenticated_ShouldSetModelCanDeleteToFalse(string userId)
        {
            // Arrange
            var model = new MeasurementStatsViewModel();

            var mockedFactory = new Mock <IViewModelFactory>();

            mockedFactory.Setup(f => f.CreateMeasurementStatsViewModel(It.IsAny <IEnumerable <Measurement> >())).Returns(model);

            var mockedMeasurementService     = new Mock <IMeasurementService>();
            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            var controller = new MeasurementController(mockedAuthenticationProvider.Object,
                                                       mockedMeasurementService.Object,
                                                       mockedFactory.Object);

            // Act
            controller.Stats(userId);

            // Assert
            Assert.IsFalse(model.CanDelete);
        }