Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }