public void GetValueToReplaces_FilterListWithExact(string filters) { //Arrange var dbOptions = new DbContextOptionsBuilder <ValueToReplaceDbContext>() .UseInMemoryDatabase(databaseName: $"ValueToReplaceDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeValueToReplaceOne = new FakeValueToReplace { }.Generate(); fakeValueToReplaceOne.ValueToReplaceTextField1 = "Alpha"; fakeValueToReplaceOne.ValueToReplaceTextField2 = "Bravo"; fakeValueToReplaceOne.ValueToReplaceIntField1 = 5; var fakeValueToReplaceTwo = new FakeValueToReplace { }.Generate(); fakeValueToReplaceTwo.ValueToReplaceTextField1 = "Charlie"; fakeValueToReplaceTwo.ValueToReplaceTextField2 = "Delta"; fakeValueToReplaceTwo.ValueToReplaceIntField1 = 6; var fakeValueToReplaceThree = new FakeValueToReplace { }.Generate(); fakeValueToReplaceThree.ValueToReplaceTextField1 = "Echo"; fakeValueToReplaceThree.ValueToReplaceTextField2 = "Foxtrot"; fakeValueToReplaceThree.ValueToReplaceIntField1 = 7; //Act using (var context = new ValueToReplaceDbContext(dbOptions)) { context.ValueToReplaces.AddRange(fakeValueToReplaceOne, fakeValueToReplaceTwo, fakeValueToReplaceThree); context.SaveChanges(); var service = new ValueToReplaceRepository(context, new SieveProcessor(sieveOptions)); var valueToReplaceRepo = service.GetValueToReplaces(new ValueToReplaceParametersDto { Filters = filters }); //Assert valueToReplaceRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
public void GetValueToReplaces_SearchQueryReturnsExpectedRecordCount(string queryString, int expectedCount) { //Arrange var dbOptions = new DbContextOptionsBuilder <ValueToReplaceDbContext>() .UseInMemoryDatabase(databaseName: $"ValueToReplaceDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeValueToReplaceOne = new FakeValueToReplace { }.Generate(); fakeValueToReplaceOne.ValueToReplaceTextField1 = "Alpha"; fakeValueToReplaceOne.ValueToReplaceTextField2 = "Bravo"; var fakeValueToReplaceTwo = new FakeValueToReplace { }.Generate(); fakeValueToReplaceTwo.ValueToReplaceTextField1 = "Hartsfield"; fakeValueToReplaceTwo.ValueToReplaceTextField2 = "White"; var fakeValueToReplaceThree = new FakeValueToReplace { }.Generate(); fakeValueToReplaceThree.ValueToReplaceTextField1 = "Bravehart"; fakeValueToReplaceThree.ValueToReplaceTextField2 = "Jonfav"; //Act using (var context = new ValueToReplaceDbContext(dbOptions)) { context.ValueToReplaces.AddRange(fakeValueToReplaceOne, fakeValueToReplaceTwo, fakeValueToReplaceThree); context.SaveChanges(); var service = new ValueToReplaceRepository(context, new SieveProcessor(sieveOptions)); var valueToReplaceRepo = service.GetValueToReplaces(new ValueToReplaceParametersDto { QueryString = queryString }); //Assert valueToReplaceRepo.Should() .HaveCount(expectedCount); context.Database.EnsureDeleted(); } }
public void GetValueToReplaces_ListSortedInDescOrder() { //Arrange var dbOptions = new DbContextOptionsBuilder <ValueToReplaceDbContext>() .UseInMemoryDatabase(databaseName: $"ValueToReplaceDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeValueToReplaceOne = new FakeValueToReplace { }.Generate(); fakeValueToReplaceOne.ValueToReplaceTextField1 = "Bravo"; var fakeValueToReplaceTwo = new FakeValueToReplace { }.Generate(); fakeValueToReplaceTwo.ValueToReplaceTextField1 = "Alpha"; var fakeValueToReplaceThree = new FakeValueToReplace { }.Generate(); fakeValueToReplaceThree.ValueToReplaceTextField1 = "Charlie"; //Act using (var context = new ValueToReplaceDbContext(dbOptions)) { context.ValueToReplaces.AddRange(fakeValueToReplaceOne, fakeValueToReplaceTwo, fakeValueToReplaceThree); context.SaveChanges(); var service = new ValueToReplaceRepository(context, new SieveProcessor(sieveOptions)); var valueToReplaceRepo = service.GetValueToReplaces(new ValueToReplaceParametersDto { SortOrder = "-ValueToReplaceTextField1" }); //Assert valueToReplaceRepo.Should() .ContainInOrder(fakeValueToReplaceThree, fakeValueToReplaceOne, fakeValueToReplaceTwo); context.Database.EnsureDeleted(); } }
public void GetValueToReplaces_ReturnExpectedPageSize() { //Arrange var dbOptions = new DbContextOptionsBuilder <ValueToReplaceDbContext>() .UseInMemoryDatabase(databaseName: $"ValueToReplaceDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeValueToReplaceOne = new FakeValueToReplace { }.Generate(); var fakeValueToReplaceTwo = new FakeValueToReplace { }.Generate(); var fakeValueToReplaceThree = new FakeValueToReplace { }.Generate(); //Act using (var context = new ValueToReplaceDbContext(dbOptions)) { context.ValueToReplaces.AddRange(fakeValueToReplaceOne, fakeValueToReplaceTwo, fakeValueToReplaceThree); context.SaveChanges(); var service = new ValueToReplaceRepository(context, new SieveProcessor(sieveOptions)); var valueToReplaceRepo = service.GetValueToReplaces(new ValueToReplaceParametersDto { PageSize = 2 }); //Assert valueToReplaceRepo.Should() .NotBeEmpty() .And.HaveCount(2); valueToReplaceRepo.Should().ContainEquivalentOf(fakeValueToReplaceOne); valueToReplaceRepo.Should().ContainEquivalentOf(fakeValueToReplaceTwo); context.Database.EnsureDeleted(); } }