public void Verify_Create_Should_AddANewEntityObjectToTheDatabase() { // Arrange var mockTeamCharacterFriendsRepository = TeamCharacterFriendsMockingSetup.DoMockingSetupForRepository(); mockTeamCharacterFriendsRepository.Setup(m => m.Search(It.IsAny<ITeamCharacterFriendSearchModel>(), It.IsAny<bool>())) .Returns(() => new Mock<List<ITeamCharacterFriend>>().Object); var businessWorkflow = new TeamCharacterFriendsBusinessWorkflow(mockTeamCharacterFriendsRepository.Object, new TeamCharacterFriendMapper()); var model = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriendModel(); // Act try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ } // Assert mockTeamCharacterFriendsRepository.Verify(m => m.Add(It.IsAny<ITeamCharacterFriend>()), Times.Once); }
public void Verify_Create_Should_AddANewEntityObjectToTheDatabase() { // Arrange var mockTeamCharacterFriendsRepository = TeamCharacterFriendsMockingSetup.DoMockingSetupForRepository(); mockTeamCharacterFriendsRepository.Setup(m => m.Search(It.IsAny <ITeamCharacterFriendSearchModel>(), It.IsAny <bool>())) .Returns(() => new Mock <List <ITeamCharacterFriend> >().Object); var businessWorkflow = new TeamCharacterFriendsBusinessWorkflow(mockTeamCharacterFriendsRepository.Object, new TeamCharacterFriendMapper()); var model = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriendModel(); // Act try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ } // Assert mockTeamCharacterFriendsRepository.Verify(m => m.Add(It.IsAny <ITeamCharacterFriend>()), Times.Once); }
public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var mockTeamCharacterFriendsRepository = TeamCharacterFriendsMockingSetup.DoMockingSetupForRepository(); var mockTeamCharacterFriend = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriend(1); mockTeamCharacterFriendsRepository.Setup(m => m.Search(It.IsAny<ITeamCharacterFriendSearchModel>(), It.IsAny<bool>())) .Returns(() => new List<ITeamCharacterFriend> { mockTeamCharacterFriend.Object } ); mockTeamCharacterFriendsRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockTeamCharacterFriend.Object); var businessWorkflow = new TeamCharacterFriendsBusinessWorkflow(mockTeamCharacterFriendsRepository.Object, new TeamCharacterFriendMapper()); var model = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriendModel(); // 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 mockTeamCharacterFriendsRepository.Verify(m => m.Add(It.IsAny<ITeamCharacterFriend>()), Times.Never); }
public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var mockTeamCharacterFriendsRepository = TeamCharacterFriendsMockingSetup.DoMockingSetupForRepository(); var mockTeamCharacterFriend = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriend(1); mockTeamCharacterFriendsRepository.Setup(m => m.Search(It.IsAny <ITeamCharacterFriendSearchModel>(), It.IsAny <bool>())) .Returns(() => new List <ITeamCharacterFriend> { mockTeamCharacterFriend.Object }); mockTeamCharacterFriendsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockTeamCharacterFriend.Object); var businessWorkflow = new TeamCharacterFriendsBusinessWorkflow(mockTeamCharacterFriendsRepository.Object, new TeamCharacterFriendMapper()); var model = TeamCharacterFriendsMockingSetup.DoMockingSetupForTeamCharacterFriendModel(); // 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 mockTeamCharacterFriendsRepository.Verify(m => m.Add(It.IsAny <ITeamCharacterFriend>()), Times.Never); }