コード例 #1
0
ファイル: NewEntryTests.cs プロジェクト: santhoshtns/Logs
        public void TestNewEntry_ShouldCallAuthenticationProviderCurrentUserId()
        {
            // Arrange
            var model = new NewEntryViewModel();

            var mockedService = new Mock <IEntryService>();
            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object);

            // Act
            controller.NewEntry(model);

            // Assert
            mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Once);
        }
コード例 #2
0
        public void TestNewEntry_ModelStateIsNotValid_ShouldNotCallAuthenticationProviderCurrentUserId()
        {
            // Arrange
            var model = new NewEntryViewModel();

            var mockedService = new Mock <IEntryService>();
            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

            var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object);

            controller.ModelState.AddModelError("", "");

            // Act
            controller.NewEntry(model);

            // Assert
            mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Never);
        }
コード例 #3
0
ファイル: NewEntryTests.cs プロジェクト: santhoshtns/Logs
        public void TestNewEntry_ShouldCallEntryServiceAddEntryToLogCorrectly(int logId, string content, string userId)
        {
            // Arrange
            var model = new NewEntryViewModel
            {
                LogId   = logId,
                Content = content
            };

            var mockedService = new Mock <IEntryService>();
            var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>();

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

            var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object);

            // Act
            controller.NewEntry(model);

            // Assert
            mockedService.Verify(s => s.AddEntryToLog(content, logId, userId), Times.Once);
        }