public void Verify_Create_Should_AddANewEntityObjectToTheDatabase() { // Arrange var mockEpisodeTeamFirstAppearancesRepository = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForRepository(); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Search(It.IsAny<IEpisodeTeamFirstAppearanceSearchModel>(), It.IsAny<bool>())) .Returns(() => new Mock<List<IEpisodeTeamFirstAppearance>>().Object); var businessWorkflow = new EpisodeTeamFirstAppearancesBusinessWorkflow(mockEpisodeTeamFirstAppearancesRepository.Object, new EpisodeTeamFirstAppearanceMapper()); var model = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearanceModel(); // Act try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ } // Assert mockEpisodeTeamFirstAppearancesRepository.Verify(m => m.Add(It.IsAny<IEpisodeTeamFirstAppearance>()), Times.Once); }
public void Verify_Create_Should_AddANewEntityObjectToTheDatabase() { // Arrange var mockEpisodeTeamFirstAppearancesRepository = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForRepository(); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Search(It.IsAny <IEpisodeTeamFirstAppearanceSearchModel>(), It.IsAny <bool>())) .Returns(() => new Mock <List <IEpisodeTeamFirstAppearance> >().Object); var businessWorkflow = new EpisodeTeamFirstAppearancesBusinessWorkflow(mockEpisodeTeamFirstAppearancesRepository.Object, new EpisodeTeamFirstAppearanceMapper()); var model = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearanceModel(); // Act try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ } // Assert mockEpisodeTeamFirstAppearancesRepository.Verify(m => m.Add(It.IsAny <IEpisodeTeamFirstAppearance>()), Times.Once); }
public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var mockEpisodeTeamFirstAppearancesRepository = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForRepository(); var mockEpisodeTeamFirstAppearance = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearance(1); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Search(It.IsAny<IEpisodeTeamFirstAppearanceSearchModel>(), It.IsAny<bool>())) .Returns(() => new List<IEpisodeTeamFirstAppearance> { mockEpisodeTeamFirstAppearance.Object } ); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockEpisodeTeamFirstAppearance.Object); var businessWorkflow = new EpisodeTeamFirstAppearancesBusinessWorkflow(mockEpisodeTeamFirstAppearancesRepository.Object, new EpisodeTeamFirstAppearanceMapper()); var model = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearanceModel(); // 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 mockEpisodeTeamFirstAppearancesRepository.Verify(m => m.Add(It.IsAny<IEpisodeTeamFirstAppearance>()), Times.Never); }
public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var mockEpisodeTeamFirstAppearancesRepository = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForRepository(); var mockEpisodeTeamFirstAppearance = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearance(1); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Search(It.IsAny <IEpisodeTeamFirstAppearanceSearchModel>(), It.IsAny <bool>())) .Returns(() => new List <IEpisodeTeamFirstAppearance> { mockEpisodeTeamFirstAppearance.Object }); mockEpisodeTeamFirstAppearancesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockEpisodeTeamFirstAppearance.Object); var businessWorkflow = new EpisodeTeamFirstAppearancesBusinessWorkflow(mockEpisodeTeamFirstAppearancesRepository.Object, new EpisodeTeamFirstAppearanceMapper()); var model = EpisodeTeamFirstAppearancesMockingSetup.DoMockingSetupForEpisodeTeamFirstAppearanceModel(); // 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 mockEpisodeTeamFirstAppearancesRepository.Verify(m => m.Add(It.IsAny <IEpisodeTeamFirstAppearance>()), Times.Never); }