Exemple #1
0
        public void Verify_Get_ByID_Should_ReturnTheCorrectObjectType()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            // Act
            var person = businessWorkflow.Get(1);

            // Assert
            Assert.IsType <CharacterEnemyModel>(person);
        }
Exemple #2
0
        public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();

            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            // Act
            var result = businessWorkflow.Remove("DOESNT-EXIST");

            // Assert
            Assert.Equal(true, result);
        }
Exemple #3
0
        public void Verify_Deactivate_ByKey_ANonExistingEntity_Should_ThrowAnInvalidOperationException()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();

            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var mockCharacterEnemiesMapper = new Mock <ICharacterEnemyMapper>();

            mockCharacterEnemiesMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterEnemyModel>(), It.IsAny <ICharacterEnemy>())).Returns(() => true);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, mockCharacterEnemiesMapper.Object);

            // Act/Assert
            Assert.Throws <System.InvalidOperationException>(() => businessWorkflow.Deactivate("TEST"));
        }
Exemple #4
0
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();

            mockCharacterEnemiesRepository.Setup(m => m.Search(It.IsAny <ICharacterEnemySearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <ICharacterEnemy> >().Object);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            var model            = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockCharacterEnemiesRepository.Verify(m => m.Add(It.IsAny <ICharacterEnemy>()), Times.Once);
        }
Exemple #5
0
        public void Verify_Search_AsListing_Should_ReturnAListOfCharacterEnemiesWithDataMatchingSearchParametersWithListingMapping()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();
            var searchModel = new Mock <ICharacterEnemySearchModel>();
            var mockCharacterEnemiesMapper = new Mock <ICharacterEnemyMapper>();

            mockCharacterEnemiesMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterEnemyModel>(), It.IsAny <ICharacterEnemy>())).Returns(() => true);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, mockCharacterEnemiesMapper.Object);

            // Act
            businessWorkflow.Search(searchModel.Object, true);
            // Assert
            mockCharacterEnemiesRepository.Verify(m => m.Search(It.IsAny <ICharacterEnemySearchModel>(), It.IsAny <bool>()), Times.Once);
        }
Exemple #6
0
        public void Verify_Update_Should_SetUpdatedDate()
        {
            // Arrange
            var mockCharacterEnemy             = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemy(1);
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();

            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacterEnemy.Object);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            var expectedName     = "Stephen King (2)";
            var model            = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel(1, expectedName);

            // Act
            businessWorkflow.Update(model.Object);
            // Assert
            mockCharacterEnemy.Verify(m => m.UpdatedDate, Times.Once);
        }
Exemple #7
0
        public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();
            var mockCharacterEnemiesMapper     = new Mock <ICharacterEnemyMapper>();

            mockCharacterEnemiesMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterEnemyModel>(), It.IsAny <ICharacterEnemy>())).Returns(() => true);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, mockCharacterEnemiesMapper.Object);

            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => new Mock <ICharacterEnemy>().Object);
            mockCharacterEnemiesRepository.Setup(m => m.SaveChanges()).Returns(() => true);
            // Act
            var result = businessWorkflow.Remove("KING-STEPHEN");

            // Assert
            mockCharacterEnemiesRepository.Verify(m => m.Remove(It.IsAny <ICharacterEnemy>()), Times.Once);
            Assert.Equal(true, result);
        }
Exemple #8
0
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemy(1);
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();

            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow        = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            var model                   = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel(1);
            ICharacterEnemyModel 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);
        }
Exemple #9
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockCharacterEnemiesRepository = CharacterEnemiesMockingSetup.DoMockingSetupForRepository();
            var mockCharacterEnemy             = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemy(1);

            mockCharacterEnemiesRepository.Setup(m => m.Search(It.IsAny <ICharacterEnemySearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <ICharacterEnemy> {
                mockCharacterEnemy.Object
            });
            mockCharacterEnemiesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacterEnemy.Object);
            var businessWorkflow = new CharacterEnemiesBusinessWorkflow(mockCharacterEnemiesRepository.Object, new CharacterEnemyMapper());
            var model            = CharacterEnemiesMockingSetup.DoMockingSetupForCharacterEnemyModel();

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