Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using Mindscape.LightSpeed;
- using Mindscape.LightSpeed.Logging;
- using NUnit.Framework;
- namespace LightSpeedRepro
- {
- public class FooBarDTO
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public IEnumerable<string> Bars { get; set; }
- }
- [TestFixture]
- public class Class1
- {
- public IQueryable<FooBarDTO> getQuery(IQueryable<Foo> foos, IQueryable<Bar> bars)
- {
- return
- (from foo in foos
- join bar in bars on foo.Id equals bar.FooId into foobar
- let barlist = foobar.OrderBy(x => x.Name).Select(x => x.Name)
- select new FooBarDTO()
- {
- Id = foo.Id,
- Name = foo.Name,
- Bars = barlist
- }).Take(1);
- }
- [Test]
- public void TestLightSpeed()
- {
- //Arrange
- var context = new LightSpeedContext<LightSpeedModel1UnitOfWork>("Context")
- {
- Logger = new ConsoleLogger(),
- };
- using (var uow = context.CreateUnitOfWork())
- {
- var foo1 = new Foo() {Name = "Foo_1"};
- var foo2 = new Foo() {Name = "Foo_2"};
- uow.Add(foo1);
- uow.Add(foo2);
- uow.Add(new Bar() {Name = "Foo_1_Bar_1", Foo = foo1});
- uow.Add(new Bar() {Name = "Foo_1_Bar_2", Foo = foo1});
- uow.Add(new Bar() {Name = "Foo_1_Bar_3", Foo = foo1});
- uow.Add(new Bar() {Name = "Foo_2_Bar_4", Foo = foo2});
- uow.Add(new Bar() {Name = "Foo_2_Bar_5", Foo = foo2});
- uow.Add(new Bar() {Name = "Foo_2_Bar_6", Foo = foo2});
- uow.SaveChanges(true);
- }
- //Act
- using (var uow = context.CreateUnitOfWork())
- {
- var query = getQuery(uow.Foos, uow.Bars);
- //Assert
- var actual = query.OrderBy(x => x.Name).FirstOrDefault();
- Assert.AreEqual("Foo_1", actual.Name);
- Assert.AreEqual(3, actual.Bars.Count());
- Assert.AreEqual("Foo_1_Bar_1", actual.Bars.ToArray()[0]);
- Assert.AreEqual("Foo_1_Bar_2", actual.Bars.ToArray()[1]);
- Assert.AreEqual("Foo_1_Bar_3", actual.Bars.ToArray()[2]);
- }
- }
- [Test]
- public void TestStandardLinq()
- {
- //Arrange
- var foos = new List<Foo>()
- {
- new Foo() {Name = "Foo_1", Id = 1},
- new Foo() {Name = "Foo_2", Id = 2},
- };
- var bars = new List<Bar>()
- {
- new Bar() {Name = "Foo_1_Bar_1", FooId = 1, Id = 1},
- new Bar() {Name = "Foo_1_Bar_2", FooId = 1, Id = 2},
- new Bar() {Name = "Foo_1_Bar_3", FooId = 1, Id = 3},
- new Bar() {Name = "Foo_2_Bar_4", FooId = 2, Id = 4},
- new Bar() {Name = "Foo_2_Bar_5", FooId = 2, Id = 5},
- new Bar() {Name = "Foo_2_Bar_6", FooId = 2, Id = 6},
- };
- var query = getQuery(foos.AsQueryable(), bars.AsQueryable());
- //Assert
- var actual = query.OrderBy(x => x.Name).FirstOrDefault();
- Assert.AreEqual("Foo_1", actual.Name);
- Assert.AreEqual(3, actual.Bars.Count());
- Assert.AreEqual("Foo_1_Bar_1", actual.Bars.ToArray()[0]);
- Assert.AreEqual("Foo_1_Bar_2", actual.Bars.ToArray()[1]);
- Assert.AreEqual("Foo_1_Bar_3", actual.Bars.ToArray()[2]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement