public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
 {
     // Arrange
     var mockVolumeCharactersRepository = VolumeCharactersMockingSetup.DoMockingSetupForRepository();
     mockVolumeCharactersRepository.Setup(m => m.Search(It.IsAny<IVolumeCharacterSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new Mock<List<IVolumeCharacter>>().Object);
     var businessWorkflow = new VolumeCharactersBusinessWorkflow(mockVolumeCharactersRepository.Object, new VolumeCharacterMapper());
     var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel();
     // Act
     try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
     // Assert
     mockVolumeCharactersRepository.Verify(m => m.Add(It.IsAny<IVolumeCharacter>()), Times.Once);
 }
コード例 #2
0
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockVolumeCharactersRepository = VolumeCharactersMockingSetup.DoMockingSetupForRepository();

            mockVolumeCharactersRepository.Setup(m => m.Search(It.IsAny <IVolumeCharacterSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <IVolumeCharacter> >().Object);
            var businessWorkflow = new VolumeCharactersBusinessWorkflow(mockVolumeCharactersRepository.Object, new VolumeCharacterMapper());
            var model            = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockVolumeCharactersRepository.Verify(m => m.Add(It.IsAny <IVolumeCharacter>()), Times.Once);
        }
 public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
 {
     // Arrange
     var mockVolumeCharactersRepository = VolumeCharactersMockingSetup.DoMockingSetupForRepository();
     var mockVolumeCharacter = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(1);
     mockVolumeCharactersRepository.Setup(m => m.Search(It.IsAny<IVolumeCharacterSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new List<IVolumeCharacter> { mockVolumeCharacter.Object } );
     mockVolumeCharactersRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockVolumeCharacter.Object);
     var businessWorkflow = new VolumeCharactersBusinessWorkflow(mockVolumeCharactersRepository.Object, new VolumeCharacterMapper());
     var model = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel();
     // 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
     mockVolumeCharactersRepository.Verify(m => m.Add(It.IsAny<IVolumeCharacter>()), Times.Never);
 }
コード例 #4
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockVolumeCharactersRepository = VolumeCharactersMockingSetup.DoMockingSetupForRepository();
            var mockVolumeCharacter            = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacter(1);

            mockVolumeCharactersRepository.Setup(m => m.Search(It.IsAny <IVolumeCharacterSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <IVolumeCharacter> {
                mockVolumeCharacter.Object
            });
            mockVolumeCharactersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockVolumeCharacter.Object);
            var businessWorkflow = new VolumeCharactersBusinessWorkflow(mockVolumeCharactersRepository.Object, new VolumeCharacterMapper());
            var model            = VolumeCharactersMockingSetup.DoMockingSetupForVolumeCharacterModel();

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