Beispiel #1
0
        public void Verify_Get_ByID_Should_ReturnTheCorrectObjectType()
        {
            // Arrange
            var mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();
            var businessWorkflow           = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            // Act
            var person = businessWorkflow.Get(1);

            // Assert
            Assert.IsType <ObjectMovieModel>(person);
        }
Beispiel #2
0
        public void Verify_Remove_ANonExistingEntity_Should_ReturnTrue()
        {
            // Arrange
            var mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();

            mockObjectMoviesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            // 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 mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();

            mockObjectMoviesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null);
            var mockObjectMoviesMapper = new Mock <IObjectMovieMapper>();

            mockObjectMoviesMapper.Setup(m => m.AreEqual(It.IsAny <IObjectMovieModel>(), It.IsAny <IObjectMovie>())).Returns(() => true);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, mockObjectMoviesMapper.Object);

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

            mockObjectMoviesRepository.Setup(m => m.Search(It.IsAny <IObjectMovieSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <IObjectMovie> >().Object);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            var model            = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovieModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockObjectMoviesRepository.Verify(m => m.Add(It.IsAny <IObjectMovie>()), Times.Once);
        }
Beispiel #5
0
        public void Verify_Search_AsListing_Should_ReturnAListOfObjectMoviesWithDataMatchingSearchParametersWithListingMapping()
        {
            // Arrange
            var mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();
            var searchModel            = new Mock <IObjectMovieSearchModel>();
            var mockObjectMoviesMapper = new Mock <IObjectMovieMapper>();

            mockObjectMoviesMapper.Setup(m => m.AreEqual(It.IsAny <IObjectMovieModel>(), It.IsAny <IObjectMovie>())).Returns(() => true);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, mockObjectMoviesMapper.Object);

            // Act
            businessWorkflow.Search(searchModel.Object, true);
            // Assert
            mockObjectMoviesRepository.Verify(m => m.Search(It.IsAny <IObjectMovieSearchModel>(), It.IsAny <bool>()), Times.Once);
        }
Beispiel #6
0
        public void Verify_Update_Should_SetUpdatedDate()
        {
            // Arrange
            var mockObjectMovie            = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovie(1);
            var mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();

            mockObjectMoviesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockObjectMovie.Object);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            var expectedName     = "Stephen King (2)";
            var model            = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovieModel(1, expectedName);

            // Act
            businessWorkflow.Update(model.Object);
            // Assert
            mockObjectMovie.Verify(m => m.UpdatedDate, Times.Once);
        }
Beispiel #7
0
        public void Verify_Remove_ByKey_Should_DeactivateTheObjectAndReturnTrue()
        {
            // Arrange
            var mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();
            var mockObjectMoviesMapper     = new Mock <IObjectMovieMapper>();

            mockObjectMoviesMapper.Setup(m => m.AreEqual(It.IsAny <IObjectMovieModel>(), It.IsAny <IObjectMovie>())).Returns(() => true);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, mockObjectMoviesMapper.Object);

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

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

            mockObjectMoviesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow     = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            var model                = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovieModel(1);
            IObjectMovieModel 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 mockObjectMoviesRepository = ObjectMoviesMockingSetup.DoMockingSetupForRepository();
            var mockObjectMovie            = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovie(1);

            mockObjectMoviesRepository.Setup(m => m.Search(It.IsAny <IObjectMovieSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <IObjectMovie> {
                mockObjectMovie.Object
            });
            mockObjectMoviesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockObjectMovie.Object);
            var businessWorkflow = new ObjectMoviesBusinessWorkflow(mockObjectMoviesRepository.Object, new ObjectMovieMapper());
            var model            = ObjectMoviesMockingSetup.DoMockingSetupForObjectMovieModel();

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