public void Should_map_data() { var data = new Faker <Dummy>().Generate(2); var ps = new Params { Count = 10, Page = 1 }; var sut = new Result <Dummy>(ps, data.AsQueryable()) .Select(entry => new DummyDTO { Name = entry.Name, Length = (entry.Name ?? "").Length }); Assert.IsInstanceOf(typeof(DummyDTO), sut.Data.First()); Assert.AreEqual(data.Count(), sut.Count); Assert.AreEqual(data.Count(), sut.Total); }
public void Should_not_sort_provided_enumerable() { // Arrage var data = new Faker <Dummy>().Generate(13).OrderByDescending(d => d.Name); var ps = new Params { Count = 10, Page = 1 }; // Act var sut = new Result <Dummy>(ps, data.AsEnumerable(), data.Count()); // Assert Assert.AreEqual(sut.Data.First(), data.First()); Assert.AreEqual(sut.Total, data.Count()); }
public void ShouldBePageWithSortOrderByDescending() { var customers = new Faker <Customer>() .CustomInstantiator(f => new Customer() { Id = f.Random.Int(0, 100) }) .Generate(100).AsQueryable(); Expression <Func <Customer, object> > a = (c) => c.Id; var sort = new RSqlSort <Customer>() { Value = a, IsDescending = true }; var pageable = new RSqlPageable <Customer>(2, 10, sort); var expected = QueryableExtensions.Page(customers, pageable); var first = customers.OrderByDescending(c => c.Id).Skip(20).First(); expected.Number .Should().Be(2); expected.HasPrevious .Should().BeTrue(); expected.HasNext .Should().BeTrue(); expected.TotalElements .Should().Be(customers.Count()); expected.TotalPages .Should().Be(10); expected.Content.First() .Should().Be(first); }
public void ShouldBePageWithNoSort() { var id = 0; var customers = new Faker <Customer>() .CustomInstantiator(f => new Customer() { Id = id++ }) .Generate(100).AsQueryable(); var pageable = new RSqlPageable <Customer>(2, 10); var query = new RSqlQuery <Customer>(c => c.Id >= 0); var expected = QueryableExtensions.Page(customers, pageable, query); var first = customers.Skip(20).First(); expected.Number .Should().Be(2); expected.HasPrevious .Should().BeTrue(); expected.HasNext .Should().BeTrue(); expected.TotalElements .Should().Be(customers.Count()); expected.TotalPages .Should().Be(10); expected.Content.First() .Should().Be(first); }
public void Can_Create_5_Without_Color_And_Model() { var cars = new Faker<Car>().CreateMany(5, x => { x.Color = ""; x.Model = ""; }); Assert.IsNotNull(cars); Assert.AreEqual(5, cars.Count()); Assert.IsTrue(cars.All(x => x.Color == "" && x.Model == "")); }
public void Can_Create_10_Users() { var users = new Faker<User>().CreateMany(10); Assert.IsNotNull(users); Assert.AreEqual(10, users.Count()); Assert.IsTrue(users.First().Email.Contains("@")); Assert.IsTrue(users.Last().Email.Contains("@")); }
public void Should_not_page_if_unchecked() { // Arrange var data = new Faker <Dummy>().Generate(13); var ps = new Params { Page = 2, Count = 10 }; // Act var sut = new Result <Dummy>(ps, data.AsQueryable(), page: false); // Assert Assert.AreEqual(data.Count(), sut.Data.Count()); }
public void Should_bootstrap_from_provided_data() { var data = new Faker <Dummy>().Generate(13); var ps = new Params { Count = 10, Page = 1 }; var sut = new Result <Dummy>(ps, data.AsEnumerable(), 99); Assert.AreEqual(sut.Count, data.Count()); Assert.AreEqual(sut.Desc, ps.Desc); Assert.AreEqual(sut.OrderBy, ps.OrderBy); Assert.AreEqual(sut.Page, ps.Page); Assert.AreEqual(sut.Total, 99); }
public void SpaceTrip_Validation_DistanceMustBeNonNegative() { // Arrange const int NUMBER_OF_INSTANCES = 1000; var spaceTrips = new Faker <SpaceTrip>() .CustomInstantiator(s => new SpaceTrip( s.Random.Decimal(decimal.MinValue, -0.00000000001M).ToString() )).Generate(NUMBER_OF_INSTANCES); // Act spaceTrips.ForEach(s => s.IsValid()); // Assert Assert.Empty(spaceTrips.Where(s => s.IsValid())); Assert.Equal(NUMBER_OF_INSTANCES, spaceTrips.Count( s => s.ValidationResult.Errors.Select( e => e.Message == "Distance can not be less than 0(zero)").Any())); }
public void ShouldBeAllContent() { var fakeCustomers = new Faker <Customer>() .Rules((f, o) => o.Name = f.Name.FullName()) .Generate(100) .AsQueryable(); var value = Helper.Expression <Customer>("name=is-null=false"); var query = new RSqlQuery <Customer>(value); var pageable = new RSqlPageable <Customer>(0, 100); var controller = new MockController(); var page = fakeCustomers.Page(pageable, query); var expected = controller.Page(page); expected .Should().BeOfType <ObjectResult>(); ((ObjectResult)expected).StatusCode .Should().Be((int)HttpStatusCode.OK); ((ObjectResult)expected).Value.As <IRSqlPage <Customer> >() .Should().NotBeNull(); ((IRSqlPage <Customer>)((ObjectResult)expected).Value).Content .Count.Should().Be(fakeCustomers.Count()); ((IRSqlPage <Customer>)((ObjectResult)expected).Value).HasNext .Should().BeFalse(); }