public void Verify_Get_ByID_Should_ReturnTheCorrectObjectType()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, new CharacterStoryArcMapper());
            // Act
            var person = businessWorkflow.Get(1);

            // Assert
            Assert.IsType <CharacterStoryArcModel>(person);
        }
        public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();

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

            // Assert
            Assert.Equal(true, result);
        }
        public void Verify_Deactivate_ByKey_ANonExistingEntity_Should_ThrowAnInvalidOperationException()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();

            mockCharacterStoryArcsRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var mockCharacterStoryArcsMapper = new Mock <ICharacterStoryArcMapper>();

            mockCharacterStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterStoryArcModel>(), It.IsAny <ICharacterStoryArc>())).Returns(() => true);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, mockCharacterStoryArcsMapper.Object);

            // Act/Assert
            Assert.Throws <System.InvalidOperationException>(() => businessWorkflow.Deactivate("TEST"));
        }
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();

            mockCharacterStoryArcsRepository.Setup(m => m.Search(It.IsAny <ICharacterStoryArcSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <ICharacterStoryArc> >().Object);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, new CharacterStoryArcMapper());
            var model            = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArcModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockCharacterStoryArcsRepository.Verify(m => m.Add(It.IsAny <ICharacterStoryArc>()), Times.Once);
        }
        public void Verify_Search_AsListing_Should_ReturnAListOfCharacterStoryArcsWithDataMatchingSearchParametersWithListingMapping()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();
            var searchModel = new Mock <ICharacterStoryArcSearchModel>();
            var mockCharacterStoryArcsMapper = new Mock <ICharacterStoryArcMapper>();

            mockCharacterStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterStoryArcModel>(), It.IsAny <ICharacterStoryArc>())).Returns(() => true);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, mockCharacterStoryArcsMapper.Object);

            // Act
            businessWorkflow.Search(searchModel.Object, true);
            // Assert
            mockCharacterStoryArcsRepository.Verify(m => m.Search(It.IsAny <ICharacterStoryArcSearchModel>(), It.IsAny <bool>()), Times.Once);
        }
        public void Verify_Update_Should_SetUpdatedDate()
        {
            // Arrange
            var mockCharacterStoryArc            = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArc(1);
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();

            mockCharacterStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacterStoryArc.Object);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, new CharacterStoryArcMapper());
            var expectedName     = "Stephen King (2)";
            var model            = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArcModel(1, expectedName);

            // Act
            businessWorkflow.Update(model.Object);
            // Assert
            mockCharacterStoryArc.Verify(m => m.UpdatedDate, Times.Once);
        }
        public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue()
        {
            // Arrange
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();
            var mockCharacterStoryArcsMapper     = new Mock <ICharacterStoryArcMapper>();

            mockCharacterStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <ICharacterStoryArcModel>(), It.IsAny <ICharacterStoryArc>())).Returns(() => true);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, mockCharacterStoryArcsMapper.Object);

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

            // Assert
            mockCharacterStoryArcsRepository.Verify(m => m.Remove(It.IsAny <ICharacterStoryArc>()), Times.Once);
            Assert.Equal(true, result);
        }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArc(1);
            var mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();

            mockCharacterStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow           = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, new CharacterStoryArcMapper());
            var model                      = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArcModel(1);
            ICharacterStoryArcModel 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 mockCharacterStoryArcsRepository = CharacterStoryArcsMockingSetup.DoMockingSetupForRepository();
            var mockCharacterStoryArc            = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArc(1);

            mockCharacterStoryArcsRepository.Setup(m => m.Search(It.IsAny <ICharacterStoryArcSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <ICharacterStoryArc> {
                mockCharacterStoryArc.Object
            });
            mockCharacterStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockCharacterStoryArc.Object);
            var businessWorkflow = new CharacterStoryArcsBusinessWorkflow(mockCharacterStoryArcsRepository.Object, new CharacterStoryArcMapper());
            var model            = CharacterStoryArcsMockingSetup.DoMockingSetupForCharacterStoryArcModel();

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