예제 #1
0
        public void NoMatch_ExpectNullReturned()
        {
            //Arrange
            var poems = new PoemBuilder().Default().BuildCollection(size: 3);

            //Act
            var spec       = new GetPoemByNameSpec("non exist poem");
            var testResult = poems.AsQueryable().FirstOrDefault(spec.Criteria);

            //Assert
            Assert.Null(testResult);
        }
예제 #2
0
        public void NoMatch_ExpectNullReturned()
        {
            //Arrange
            var poems = new PoemBuilder().Default().BuildCollection(size: 3);

            //Act
            var spec       = new GetPoemAndPublishedRevisionByIdSpec(Guid.Empty);
            var testResult = poems.AsQueryable().FirstOrDefault(spec.Criteria);

            //Assert
            Assert.Null(testResult);
        }
예제 #3
0
        public void NonCaseSensitiveMatch_ExpectPoemReturned()
        {
            //Arrange
            var poems        = new PoemBuilder().Default().BuildCollection(size: 3).ToList();
            var expectResult = poems[1];

            //Act
            var spec       = new GetPoemByNameSpec(expectResult.Name.ToUpper());
            var testResult = poems.AsQueryable().FirstOrDefault(spec.Criteria);

            //Assert
            Assert.NotNull(testResult);
            Assert.Equal(expectResult.Id, testResult.Id);
        }
예제 #4
0
        public void ExactMatch_ExpectPoemReturned()
        {
            //Arrange
            var poems        = new PoemBuilder().Default().BuildCollection(size: 3).ToList();
            var expectResult = poems[1];

            //Act
            var spec       = new GetPoemAndPublishedRevisionByIdSpec(expectResult.Id);
            var testResult = poems.AsQueryable().FirstOrDefault(spec.Criteria);

            //Assert
            Assert.NotNull(testResult);
            Assert.Equal(expectResult.Id, testResult.Id);
        }
예제 #5
0
        public void SinglePoem_ExpectListWithSamePoem()
        {
            //Arrange
            var poems        = new PoemBuilder().Default().BuildCollection(size: 1).ToList();
            var queryable    = poems.AsQueryable();
            var expectResult = poems;

            //Act
            var spec       = ListPoemsByLastModifiedDateSpec.CreateSpecification();
            var testResult = queryable.OrderByDescending(spec.OrderByDesc);

            //Assert
            Assert.Null(spec.Criteria);
            Assert.Null(spec.OrderBy);
            Assert.Equal(expectResult, testResult);
        }
예제 #6
0
        public void PoemsWithDescModifiedDate_ExpectListOrderedDesc()
        {
            //Arrange
            var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList();

            poems[0].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-1);
            poems[1].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2);
            poems[2].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-3);
            var queryable    = poems.AsQueryable();
            var expectResult = poems;

            //Act
            var spec       = ListPoemsByLastModifiedDateSpec.CreateSpecification();
            var testResult = queryable.OrderByDescending(spec.OrderByDesc);

            //Assert
            Assert.Equal(expectResult, testResult);
        }
예제 #7
0
        public void ListWithNameInAscOrder_ExpectReturnedListInAscOrder()
        {
            //Arrange
            var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList();

            poems[0].Name = "A " + poems[0].Name;
            poems[1].Name = "B " + poems[1].Name;;
            poems[2].Name = "C " + poems[2].Name;;
            var queryable    = poems.AsQueryable();
            var expectResult = poems;

            //Act
            var spec       = new ListPoemsByNameSpec();
            var testResult = queryable.OrderBy(spec.OrderBy);

            //Assert
            Assert.Equal(expectResult, testResult);
        }
예제 #8
0
        public void ListWithConceivedDateInDescOrder_ExpectReturnedListInDescOrder()
        {
            //Arrange
            var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList();

            poems[0].ConceivedDateUTC = DateTime.UtcNow.AddDays(-1);
            poems[1].ConceivedDateUTC = DateTime.UtcNow.AddDays(-2);
            poems[2].ConceivedDateUTC = DateTime.UtcNow.AddDays(-3);
            var queryable    = poems.AsQueryable();
            var expectResult = poems;

            //Act
            var spec       = new ListPoemsByConceivedDateSpec();
            var testResult = queryable.OrderByDescending(spec.OrderByDesc);

            //Assert
            Assert.Equal(expectResult, testResult);
        }