예제 #1
0
        public void Verify_Get_ByKey_Should_ReturnTheCorrectOrigin()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            // Act
            var origins = repository.Get("KING-STEPHEN");

            // Assert
            Assert.Equal("/TEST/KING-STEPHEN", origins.ApiDetailUrl);
        }
예제 #2
0
        public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            var origins     = repository.Get(1);

            // Act
            repository.Deactivate(origins);
            // Assert
            Assert.Equal(false, origins.Active);
        }
예제 #3
0
        public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            var origins     = repository.Get(1);

            // Act
            repository.Remove(origins);
            // Assert
            mockSetOrigins.Verify(x => x.Remove((Origin)origins), Times.Once);
        }
예제 #4
0
        public void Verify_Update_Should_SetTheEntityStateToModified()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            var origins     = repository.Get(1);

            origins.ApiDetailUrl = "/TEST";
            // Act
            repository.Update(origins);
            // Assert
            mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once);
        }
예제 #5
0
        public void Verify_Add_Should_AddTheEntityToTheContext()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(false, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            var origins     = new Origin {
                Active = true, CustomKey = "SALVATORE-RAA",
            };

            // Act
            repository.Add(origins);
            // Assert
            mockSetOrigins.Verify(x => x.Add(origins), Times.Once);
        }
예제 #6
0
        public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins, true);
            var repository  = new OriginsRepository(mockContext.Object);
            var searchModel = new Mock <IOriginSearchModel>();
            // Act
            var origins = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray();

            // Assert
            Assert.Equal(1, origins.Length);
            Assert.Equal(2, origins[0].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", origins[0].MyApiDetailUrl);
            // Stephen King was filtered out because he was Inactive
        }
예제 #7
0
        public void Verify_List_Should_ReturnAListOfOriginsWithData()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            // Act
            var origins = repository.List.ToArray();

            // Assert
            Assert.Equal(2, origins.Length);
            Assert.Equal(1, origins[0].Id);
            Assert.Equal("/TEST/KING-STEPHEN", origins[0].ApiDetailUrl);
            Assert.Equal(2, origins[1].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", origins[1].ApiDetailUrl);
        }
예제 #8
0
        public void Verify_Search_WithPaging_Should_ReturnAListOfOriginsWithDataMatchingSearchParameters()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins);
            var repository  = new OriginsRepository(mockContext.Object);
            var searchModel = new OriginSearchModel {
                Paging = new Paging {
                    Skip = 1, Take = 1
                }
            };
            // Act
            var origins = repository.Search(searchModel /*.Object*/).ToArray();

            // Assert
            Assert.Equal(1, origins.Length);
            Assert.Equal(2, origins[0].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", origins[0].ApiDetailUrl);
            // Stephen King was filtered out because he was Skipped
        }
예제 #9
0
        public void Verify_Search_WithModifiedSince_Should_ReturnAListOfOriginsWithDataMatchingSearchParameters()
        {
            // Arrange
            Mock <IDbSet <Origin> > mockSetOrigins;
            var mockContext = OriginsMockingSetup.DoMockingSetupForContext(true, out mockSetOrigins, true);
            var repository  = new OriginsRepository(mockContext.Object);
            var createDate  = new System.DateTime(2015, 05, 28, 10, 45, 00).AddDays(1).AddMinutes(-1);
            //var searchModel = new Mock<IOriginSearchModel>();
            //searchModel.Setup(m => m.ModifiedSince).Returns(() => createDate);
            var searchModel = new OriginSearchModel {
                ModifiedSince = createDate
            };
            // Act
            var origins = repository.Search(searchModel /*.Object*/).ToArray();

            // Assert
            Assert.Equal(1, origins.Length);
            Assert.Equal(2, origins[0].Id);
            Assert.Equal("/TEST/NIVEN-LARRY", origins[0].ApiDetailUrl);
            // Stephen King was filtered out because he was created before the modified since date
        }