Exemple #1
0
        public void Verify_Get_ByID_Should_ReturnTheCorrectObjectType()
        {
            // Arrange
            var mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();
            var businessWorkflow             = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            // Act
            var person = businessWorkflow.Get(1);

            // Assert
            Assert.IsType <ConceptVolumeModel>(person);
        }
Exemple #2
0
        public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue()
        {
            // Arrange
            var mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();

            mockConceptVolumesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            // 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 mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();

            mockConceptVolumesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var mockConceptVolumesMapper = new Mock <IConceptVolumeMapper>();

            mockConceptVolumesMapper.Setup(m => m.AreEqual(It.IsAny <IConceptVolumeModel>(), It.IsAny <IConceptVolume>())).Returns(() => true);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, mockConceptVolumesMapper.Object);

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

            mockConceptVolumesRepository.Setup(m => m.Search(It.IsAny <IConceptVolumeSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <IConceptVolume> >().Object);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            var model            = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockConceptVolumesRepository.Verify(m => m.Add(It.IsAny <IConceptVolume>()), Times.Once);
        }
Exemple #5
0
        public void Verify_Search_AsListing_Should_ReturnAListOfConceptVolumesWithDataMatchingSearchParametersWithListingMapping()
        {
            // Arrange
            var mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();
            var searchModel = new Mock <IConceptVolumeSearchModel>();
            var mockConceptVolumesMapper = new Mock <IConceptVolumeMapper>();

            mockConceptVolumesMapper.Setup(m => m.AreEqual(It.IsAny <IConceptVolumeModel>(), It.IsAny <IConceptVolume>())).Returns(() => true);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, mockConceptVolumesMapper.Object);

            // Act
            businessWorkflow.Search(searchModel.Object, true);
            // Assert
            mockConceptVolumesRepository.Verify(m => m.Search(It.IsAny <IConceptVolumeSearchModel>(), It.IsAny <bool>()), Times.Once);
        }
Exemple #6
0
        public void Verify_Update_Should_SetUpdatedDate()
        {
            // Arrange
            var mockConceptVolume            = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(1);
            var mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();

            mockConceptVolumesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockConceptVolume.Object);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            var expectedName     = "Stephen King (2)";
            var model            = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(1, expectedName);

            // Act
            businessWorkflow.Update(model.Object);
            // Assert
            mockConceptVolume.Verify(m => m.UpdatedDate, Times.Once);
        }
Exemple #7
0
        public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue()
        {
            // Arrange
            var mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();
            var mockConceptVolumesMapper     = new Mock <IConceptVolumeMapper>();

            mockConceptVolumesMapper.Setup(m => m.AreEqual(It.IsAny <IConceptVolumeModel>(), It.IsAny <IConceptVolume>())).Returns(() => true);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, mockConceptVolumesMapper.Object);

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

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

            mockConceptVolumesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow       = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            var model                  = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel(1);
            IConceptVolumeModel 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 mockConceptVolumesRepository = ConceptVolumesMockingSetup.DoMockingSetupForRepository();
            var mockConceptVolume            = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolume(1);

            mockConceptVolumesRepository.Setup(m => m.Search(It.IsAny <IConceptVolumeSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <IConceptVolume> {
                mockConceptVolume.Object
            });
            mockConceptVolumesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockConceptVolume.Object);
            var businessWorkflow = new ConceptVolumesBusinessWorkflow(mockConceptVolumesRepository.Object, new ConceptVolumeMapper());
            var model            = ConceptVolumesMockingSetup.DoMockingSetupForConceptVolumeModel();

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