Beispiel #1
0
        public void Verify_Get_ByKey_Should_ReturnTheCorrectObject()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();
            var businessWorkflow        = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, new StoryArcMapper());
            // Act
            var person = businessWorkflow.Get("KING-STEPHEN");

            // Assert
            Assert.IsType <StoryArcModel>(person);
        }
Beispiel #2
0
        public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();

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

            // Assert
            Assert.Equal(true, result);
        }
Beispiel #3
0
        public void Verify_Deactivate_ByKey_ANonExistingEntity_Should_ThrowAnInvalidOperationException()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();

            mockStoryArcsRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var mockStoryArcsMapper = new Mock <IStoryArcMapper>();

            mockStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <IStoryArcModel>(), It.IsAny <IStoryArc>())).Returns(() => true);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, mockStoryArcsMapper.Object);

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

            mockStoryArcsRepository.Setup(m => m.Search(It.IsAny <IStoryArcSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <IStoryArc> >().Object);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, new StoryArcMapper());
            var model            = StoryArcsMockingSetup.DoMockingSetupForStoryArcModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockStoryArcsRepository.Verify(m => m.Add(It.IsAny <IStoryArc>()), Times.Once);
        }
Beispiel #5
0
        public void Verify_Search_AsListing_Should_ReturnAListOfStoryArcsWithDataMatchingSearchParametersWithListingMapping()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();
            var searchModel             = new Mock <IStoryArcSearchModel>();
            var mockStoryArcsMapper     = new Mock <IStoryArcMapper>();

            mockStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <IStoryArcModel>(), It.IsAny <IStoryArc>())).Returns(() => true);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, mockStoryArcsMapper.Object);

            // Act
            businessWorkflow.Search(searchModel.Object, true);
            // Assert
            mockStoryArcsRepository.Verify(m => m.Search(It.IsAny <IStoryArcSearchModel>(), It.IsAny <bool>()), Times.Once);
        }
Beispiel #6
0
        public void Verify_Update_Should_SetUpdatedDate()
        {
            // Arrange
            var mockStoryArc            = StoryArcsMockingSetup.DoMockingSetupForStoryArc(1);
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();

            mockStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockStoryArc.Object);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, new StoryArcMapper());
            var expectedName     = "Stephen King (2)";
            var model            = StoryArcsMockingSetup.DoMockingSetupForStoryArcModel(1, expectedName);

            // Act
            businessWorkflow.Update(model.Object);
            // Assert
            mockStoryArc.Verify(m => m.UpdatedDate, Times.Once);
        }
Beispiel #7
0
        public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();
            var mockStoryArcsMapper     = new Mock <IStoryArcMapper>();

            mockStoryArcsMapper.Setup(m => m.AreEqual(It.IsAny <IStoryArcModel>(), It.IsAny <IStoryArc>())).Returns(() => true);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, mockStoryArcsMapper.Object);

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

            // Assert
            mockStoryArcsRepository.Verify(m => m.Remove(It.IsAny <IStoryArc>()), Times.Once);
            Assert.Equal(true, result);
        }
Beispiel #8
0
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = StoryArcsMockingSetup.DoMockingSetupForStoryArc(1);
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();

            mockStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var            businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, new StoryArcMapper());
            var            model            = StoryArcsMockingSetup.DoMockingSetupForStoryArcModel(1);
            IStoryArcModel 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);
        }
Beispiel #9
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockStoryArcsRepository = StoryArcsMockingSetup.DoMockingSetupForRepository();
            var mockStoryArc            = StoryArcsMockingSetup.DoMockingSetupForStoryArc(1);

            mockStoryArcsRepository.Setup(m => m.Search(It.IsAny <IStoryArcSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <IStoryArc> {
                mockStoryArc.Object
            });
            mockStoryArcsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockStoryArc.Object);
            var businessWorkflow = new StoryArcsBusinessWorkflow(mockStoryArcsRepository.Object, new StoryArcMapper());
            var model            = StoryArcsMockingSetup.DoMockingSetupForStoryArcModel();

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