public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
 {
     // Arrange
     var mockIssuesRepository = IssuesMockingSetup.DoMockingSetupForRepository();
     mockIssuesRepository.Setup(m => m.Search(It.IsAny<IIssueSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new Mock<List<IIssue>>().Object);
     var businessWorkflow = new IssuesBusinessWorkflow(mockIssuesRepository.Object, new IssueMapper());
     var model = IssuesMockingSetup.DoMockingSetupForIssueModel();
     // Act
     try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
     // Assert
     mockIssuesRepository.Verify(m => m.Add(It.IsAny<IIssue>()), Times.Once);
 }
コード例 #2
0
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockIssuesRepository = IssuesMockingSetup.DoMockingSetupForRepository();

            mockIssuesRepository.Setup(m => m.Search(It.IsAny <IIssueSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <IIssue> >().Object);
            var businessWorkflow = new IssuesBusinessWorkflow(mockIssuesRepository.Object, new IssueMapper());
            var model            = IssuesMockingSetup.DoMockingSetupForIssueModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockIssuesRepository.Verify(m => m.Add(It.IsAny <IIssue>()), Times.Once);
        }
 public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
 {
     // Arrange
     var mockIssuesRepository = IssuesMockingSetup.DoMockingSetupForRepository();
     var mockIssue = IssuesMockingSetup.DoMockingSetupForIssue(1);
     mockIssuesRepository.Setup(m => m.Search(It.IsAny<IIssueSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new List<IIssue> { mockIssue.Object } );
     mockIssuesRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockIssue.Object);
     var businessWorkflow = new IssuesBusinessWorkflow(mockIssuesRepository.Object, new IssueMapper());
     var model = IssuesMockingSetup.DoMockingSetupForIssueModel();
     // Act
     try { businessWorkflow.Create(model.Object); }
     catch { /* ignored, the Get call at the end doesn't work because don't get a real entity with id on it */ }
     // Assert
     mockIssuesRepository.Verify(m => m.Add(It.IsAny<IIssue>()), Times.Never);
 }
コード例 #4
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockIssuesRepository = IssuesMockingSetup.DoMockingSetupForRepository();
            var mockIssue            = IssuesMockingSetup.DoMockingSetupForIssue(1);

            mockIssuesRepository.Setup(m => m.Search(It.IsAny <IIssueSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <IIssue> {
                mockIssue.Object
            });
            mockIssuesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockIssue.Object);
            var businessWorkflow = new IssuesBusinessWorkflow(mockIssuesRepository.Object, new IssueMapper());
            var model            = IssuesMockingSetup.DoMockingSetupForIssueModel();

            // Act
            try { businessWorkflow.Create(model.Object); }
            catch { /* ignored, the Get call at the end doesn't work because don't get a real entity with id on it */ }
            // Assert
            mockIssuesRepository.Verify(m => m.Add(It.IsAny <IIssue>()), Times.Never);
        }