public void Verify_Get_ByKey_Should_ReturnTheCorrectObject() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); // Act var person = businessWorkflow.Get("KING-STEPHEN"); // Assert Assert.IsType <CharacterModel>(person); }
public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); mockCharactersRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); // Act var result = businessWorkflow.Remove("DOESNT-EXIST"); // Assert Assert.Equal(true, result); }
public void Verify_Deactivate_ByKey_ANonExistingEntity_Should_ThrowAnInvalidOperationException() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); mockCharactersRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null); var mockCharactersMapper = new Mock <ICharacterMapper>(); mockCharactersMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterModel>(), It.IsAny <ICharacter>())).Returns(() => true); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, mockCharactersMapper.Object); // Act/Assert Assert.Throws <System.InvalidOperationException>(() => businessWorkflow.Deactivate("TEST")); }
public void Verify_Create_Should_AddANewEntityObjectToTheDatabase() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); mockCharactersRepository.Setup(m => m.Search(It.IsAny <ICharacterSearchModel>(), It.IsAny <bool>())) .Returns(() => new Mock <List <ICharacter> >().Object); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(); // Act try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ } // Assert mockCharactersRepository.Verify(m => m.Add(It.IsAny <ICharacter>()), Times.Once); }
public void Verify_Search_AsListing_Should_ReturnAListOfCharactersWithDataMatchingSearchParametersWithListingMapping() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); var searchModel = new Mock <ICharacterSearchModel>(); var mockCharactersMapper = new Mock <ICharacterMapper>(); mockCharactersMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterModel>(), It.IsAny <ICharacter>())).Returns(() => true); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, mockCharactersMapper.Object); // Act businessWorkflow.Search(searchModel.Object, true); // Assert mockCharactersRepository.Verify(m => m.Search(It.IsAny <ICharacterSearchModel>(), It.IsAny <bool>()), Times.Once); }
public void Verify_Update_Should_SetUpdatedDate() { // Arrange var mockCharacter = CharactersMockingSetup.DoMockingSetupForCharacter(1); var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); mockCharactersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacter.Object); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); var expectedName = "Stephen King (2)"; var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(1, expectedName); // Act businessWorkflow.Update(model.Object); // Assert mockCharacter.Verify(m => m.UpdatedDate, Times.Once); }
public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); var mockCharactersMapper = new Mock <ICharacterMapper>(); mockCharactersMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterModel>(), It.IsAny <ICharacter>())).Returns(() => true); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, mockCharactersMapper.Object); mockCharactersRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => new Mock <ICharacter>().Object); mockCharactersRepository.Setup(m => m.SaveChanges()).Returns(() => true); // Act var result = businessWorkflow.Remove("KING-STEPHEN"); // Assert mockCharactersRepository.Verify(m => m.Remove(It.IsAny <ICharacter>()), Times.Once); Assert.Equal(true, result); }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = CharactersMockingSetup.DoMockingSetupForCharacter(1); var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); mockCharactersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(1); ICharacterModel result = null; // Act try { result = businessWorkflow.Update(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 Assert.NotNull(result); Assert.Equal("/TEST/KING-STEPHEN", result.ApiDetailUrl); Assert.Null(result.UpdatedDate); }
public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var mockCharactersRepository = CharactersMockingSetup.DoMockingSetupForRepository(); var mockCharacter = CharactersMockingSetup.DoMockingSetupForCharacter(1); mockCharactersRepository.Setup(m => m.Search(It.IsAny <ICharacterSearchModel>(), It.IsAny <bool>())) .Returns(() => new List <ICharacter> { mockCharacter.Object }); mockCharactersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacter.Object); var businessWorkflow = new CharactersBusinessWorkflow(mockCharactersRepository.Object, new CharacterMapper()); var model = CharactersMockingSetup.DoMockingSetupForCharacterModel(); // 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 mockCharactersRepository.Verify(m => m.Add(It.IsAny <ICharacter>()), Times.Never); }