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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }