public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
 {
     // Arrange
     var mockCharacterIssuesRepository = CharacterIssuesMockingSetup.DoMockingSetupForRepository();
     mockCharacterIssuesRepository.Setup(m => m.Search(It.IsAny<ICharacterIssueSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new Mock<List<ICharacterIssue>>().Object);
     var businessWorkflow = new CharacterIssuesBusinessWorkflow(mockCharacterIssuesRepository.Object, new CharacterIssueMapper());
     var model = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssueModel();
     // Act
     try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
     // Assert
     mockCharacterIssuesRepository.Verify(m => m.Add(It.IsAny<ICharacterIssue>()), Times.Once);
 }
示例#2
0
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockCharacterIssuesRepository = CharacterIssuesMockingSetup.DoMockingSetupForRepository();

            mockCharacterIssuesRepository.Setup(m => m.Search(It.IsAny <ICharacterIssueSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <ICharacterIssue> >().Object);
            var businessWorkflow = new CharacterIssuesBusinessWorkflow(mockCharacterIssuesRepository.Object, new CharacterIssueMapper());
            var model            = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssueModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockCharacterIssuesRepository.Verify(m => m.Add(It.IsAny <ICharacterIssue>()), Times.Once);
        }
 public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
 {
     // Arrange
     var mockCharacterIssuesRepository = CharacterIssuesMockingSetup.DoMockingSetupForRepository();
     var mockCharacterIssue = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssue(1);
     mockCharacterIssuesRepository.Setup(m => m.Search(It.IsAny<ICharacterIssueSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new List<ICharacterIssue> { mockCharacterIssue.Object } );
     mockCharacterIssuesRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockCharacterIssue.Object);
     var businessWorkflow = new CharacterIssuesBusinessWorkflow(mockCharacterIssuesRepository.Object, new CharacterIssueMapper());
     var model = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssueModel();
     // 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
     mockCharacterIssuesRepository.Verify(m => m.Add(It.IsAny<ICharacterIssue>()), Times.Never);
 }
示例#4
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockCharacterIssuesRepository = CharacterIssuesMockingSetup.DoMockingSetupForRepository();
            var mockCharacterIssue            = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssue(1);

            mockCharacterIssuesRepository.Setup(m => m.Search(It.IsAny <ICharacterIssueSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <ICharacterIssue> {
                mockCharacterIssue.Object
            });
            mockCharacterIssuesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacterIssue.Object);
            var businessWorkflow = new CharacterIssuesBusinessWorkflow(mockCharacterIssuesRepository.Object, new CharacterIssueMapper());
            var model            = CharacterIssuesMockingSetup.DoMockingSetupForCharacterIssueModel();

            // 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
            mockCharacterIssuesRepository.Verify(m => m.Add(It.IsAny <ICharacterIssue>()), Times.Never);
        }