public void Handle_should_update_correct_size() { var widget = new Product { Name = "widget"}; var gadget = new Product { Name = "gadget"}; var sizes = new[] { new Size {Product = widget, Name = "Small", IsActive = false, IsInStock = false}, new Size {Product = widget, Name = "Medium", IsActive = true, IsInStock = false}, new Size {Product = widget, Name = "Small", IsActive = true, IsInStock = false}, // should update this one new Size {Product = gadget, Name = "Small", IsActive = true, IsInStock = false}, }; sizeRepository.GetAllDelegate = () => sizes.AsQueryable(); var @event = new StockItemInStockChanged("Small", "widget", true); handler.Handle(@event); sizes[2].IsInStock.ShouldBeTrue(); sizes[0].IsInStock.ShouldBeFalse(); sizes[1].IsInStock.ShouldBeFalse(); sizes[3].IsInStock.ShouldBeFalse(); }
public void FindPackagesOverloadLooksForSearchTermsInSpecificFields() { // Arrange var packages = new[] { PackageUtility.CreatePackage("Foo.Qux", description: "Some desc"), PackageUtility.CreatePackage("X-Package", tags: " lib qux "), PackageUtility.CreatePackage("Filtered"), PackageUtility.CreatePackage("B", description: "This is a package for qux and not one for baz"), }; // Act var result1 = packages.AsQueryable().Find(new[] { "Description", "Tags" }, "Qux"); var result2 = packages.AsQueryable().Find(new[] { "Id" }, "Filtered"); // Assert Assert.Equal(new[] { packages[1], packages[3] }, result1.ToArray()); Assert.Equal(new[] { packages[2], }, result2.ToArray()); }
public void SetUpPagedList(int pageIndex, int pageSize, int? totalCount) { var collection = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; if (totalCount < 0) { pagedList = new PagedList<int>(collection.AsQueryable(), pageIndex, pageSize); } else { pagedList = new PagedList<int>(collection.AsQueryable(), pageIndex, pageSize, totalCount); } }
public void GetByName_VirtualMachineDoesNotExist_ReturnsNull() { // Arrange var machineList = new[] { new VirtualMachine {Name = "Machine1"}, new VirtualMachine {Name = "Machine2"}, new VirtualMachine {Name = "Machine3"} }; var repository = MockRepository.GenerateMock<IVirtualMachineRepository>(); repository.Expect(x => x.Read()) .Repeat.Once() .Return(machineList.AsQueryable()); var messenger = MockRepository.GenerateStub<IMessenger>(); var controller = new VirtualMachinesController(repository, messenger); // Act var result = controller.Get("FakeMachine"); // Assert Assert.That(result, Is.Null); }
public void GetByName_VirtualMachineExists_RepositoryIsCalled() { // Arrange var machineList = new[] { new VirtualMachine {Name = "Machine1"}, new VirtualMachine {Name = "Machine2"}, new VirtualMachine {Name = "Machine3"} }; var repository = MockRepository.GenerateMock<IVirtualMachineRepository>(); repository.Expect(x => x.Read()) .Repeat.Once() .Return(machineList.AsQueryable()); var messenger = MockRepository.GenerateStub<IMessenger>(); var controller = new VirtualMachinesController(repository, messenger); // Act controller.Get("Machine2"); // Assert repository.VerifyAllExpectations(); }
public void CanExecute() { //arrange var gameRecords = new[] { new GameRecord { Moves = new[] { new GameMoveRecord{ Value = 0 } }, }, new GameRecord { Moves = new[] { new GameMoveRecord() }, }, }; var repoMock = new Mock<IRepository>(); repoMock.Setup(x => x.Query<GameRecord>()).Returns(gameRecords.AsQueryable()); var query = new FindGames(); var handler = new FindGamesHandler(repoMock.Object); //act var result = handler.Execute(query); //assert Assert.AreEqual(2, result.Count()); Assert.AreEqual(100, result.First().PercentageComplete); Assert.AreEqual(0, result.Last().PercentageComplete); }
static void Main() { var languages = new[] { "C#", "J#", "VB", "Delphi", "F#", "COBOL", "Python" }; var queryable = languages.AsQueryable().Where(l => l.EndsWith("#") && l != "j#") .Take(3).Select(l => new { Name = l, IsSelected = true }); new VisualizerDevelopmentHost(queryable.Expression, typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeObjectSource)).ShowVisualizer(); }
public void It_gets_an_expression_to_map_A_to_B() { mapper.Map<A, B>(); var expr = mapper.GetMapExpression<A, B>(); var objects = new[]{new A{String="hello world", Int=42}, new A{String="Magic", Int=8}}; var mapped = objects.AsQueryable().Select(expr); Assert.False (mapped.Any (x => x.String == null)); }
public override void When() { this.matchingUserConfiguration = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = TestValues.CONFIGURATION_ROW_KEY }; var nonMatchingUserConfiguration1 = new UserConfiguration { PartitionKey = "Non-matchingPartitionKey", RowKey = TestValues.CONFIGURATION_ROW_KEY }; var nonMatchingUserConfiguration2 = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = "Non-matchingRowKey" }; var userConfigurations = new[] { this.matchingUserConfiguration, nonMatchingUserConfiguration1, nonMatchingUserConfiguration2 }; this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations.AsQueryable()); this.userConfiguration = this.UserConfigurationRepository.GetByNameIdentifier(); }
public void WhenCreatingSelectExpressionFromXmlMemberOnPropertyThenGetsPropertyValue() { var nameResolver = new MemberNameResolver(); var factory = new SelectExpressionFactory<FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver)); var items = new[] { new FakeItem { IntValue = 2 } }; var expression = factory.Create("Number"); dynamic result = items.AsQueryable().Select(expression).First(); Assert.AreEqual(2, result.Number); }
public void WhenCreatingSelectExpressionFromDataMemberOnFieldThenGetsFieldValue() { var nameResolver = new MemberNameResolver(); var factory = new SelectExpressionFactory<FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver)); var items = new[] { new FakeItem { StringValue = "test" } }; var expression = factory.Create("Text"); dynamic result = items.AsQueryable().Select(expression).First(); Assert.AreEqual("test", result.Text); }
public void TestFindLatest() { var context = new Mock<Context>(); var rates = new[] { new Rate { CurrencyCode = "EUR" }, new Rate { CurrencyCode = "USD" } }; var contextRates = DbSetMockBuilder.Build(rates.AsQueryable()); context.Setup(c => c.Rates).Returns(contextRates.Object); var currencyRatesService = new CurrencyRatesService(context.Object); var latestRates = currencyRatesService.FindLatest(); Assert.That(latestRates, Is.EqualTo(rates)); }
public void It_gets_an_expression_to_map_aggregate_to_aggregate() { mapper.Map<AggregateA, AggregateB> (); var expr = mapper.GetMapExpression<AggregateA, AggregateB> (); var objects = new[] { new AggregateA {Prop=new A{String="hello world", Int=42}}, new AggregateA{Prop=new A{String="Magic", Int=8}} }; var mapped = objects.AsQueryable ().Select (expr); Assert.False (mapped.Any (x => x.Prop == null || x.Prop.String == null)); }
protected override void Because_of() { var sourceList = new[] { new Source { Child1 = new ChildSource(), Child2 = new ChildSource(), Child3 = new ChildSource() } }; _dests = sourceList.AsQueryable().ProjectTo<Dest>(d => d.Child2).ToArray(); }
public void TestFind() { var context = new Mock<Context>(); var rates = new[] { new Rate { Id = 123, CurrencyCode = "EUR" } }; var contextRates = DbSetMockBuilder.Build(rates.AsQueryable()); contextRates.Setup(cr => cr.Include("File")).Returns(contextRates.Object); context.Setup(c => c.Rates).Returns(contextRates.Object); var currencyRatesService = new CurrencyRatesService(context.Object); var rate = currencyRatesService.Find(123); Assert.That(rate, Is.EqualTo(rates.First())); }
public void Sort_Descending_SortsDescending() { var people = new[] { new Person {FirstName = "Bob"}, new Person {FirstName = "Jane"}, new Person {FirstName = "Dan"} }; var firstNameDescending = new SortField("FirstName", SortField.SortDirectionType.DESC); var peopleSortedByFirstNameDescending = people.AsQueryable().SortBySortField(firstNameDescending); var firstPerson = peopleSortedByFirstNameDescending.First(); Expect(firstPerson.FirstName == "Jane"); }
public void Handle_should_update_default_size() { var widget = new Product {Name = "widget"}; var sizes = new[] { new Size {Product = widget, Name = "-", IsActive = false, IsInStock = false}, }; sizeRepository.GetAllDelegate = () => sizes.AsQueryable(); var @event = new StockItemInStockChanged("-", "widget", true); handler.Handle(@event); sizes[0].IsInStock.ShouldBeTrue(); }
public void Should_project_null_value() { var items = new[] { new Parent { Value = 5 } }; var projected = items.AsQueryable().Project().To<ParentDto>().ToList(); projected[0].Value.ShouldEqual(5); projected[0].ChildValue.ShouldBeNull(); projected[0].ChildGrandChildValue.ShouldBeNull(); }
public void FindPackagesOverloadReturnsEmptySequenceIfTermIsNotFoundInProperties() { // Arrange var packages = new[] { PackageUtility.CreatePackage("Foo.Qux"), PackageUtility.CreatePackage("X-Package", tags: " lib qux "), PackageUtility.CreatePackage("Filtered"), PackageUtility.CreatePackage("B", description: "This is a package for qux and not one for baz"), }; // Act var result1 = packages.AsQueryable().Find(new[] { "Summary" }, "Qux"); // Assert Assert.Empty(result1); }
protected override void Because_of() { var sourceList = new[] { new Source { Child1 = new ChildSource(), Child2 = new ChildSource(), Child3 = new ChildSource(), Child4 = new ChildSource() { GrandChild = new GrandChildSource() } } }; _dests = sourceList.AsQueryable().UseAsDataSource(Configuration).For<Dest>(d => d.Child2, d => d.Child4, d => d.Child4.GrandChild).ToArray(); }
public void Sort_MultipleSort_Sorts() { var people = new[] { new Person {FirstName = "Jane", LastName = "Moe"}, new Person {FirstName = "Bob", LastName = "Doe"}, new Person {FirstName = "Jane", LastName = "Doe"}, new Person {FirstName = "Dan", LastName = "Doe"} }; var sortByFirstName = new SortField("FirstName", SortField.SortDirectionType.ASC); var sortByLastName = new SortField("LastName", SortField.SortDirectionType.ASC); var peopleSortedByFirstThenLastName = people.AsQueryable().SortBySortField(sortByFirstName, sortByLastName); var lastPerson = peopleSortedByFirstThenLastName.Last(); Expect(lastPerson.FirstName == "Jane"); Expect(lastPerson.LastName == "Moe"); }
public JsonResult CreateOrderDetail(int id, OrderDetailViewModel orderDetailViewModel, [DataSourceRequest] DataSourceRequest dataSourceRequest) { var order = _orderRepository.GetAllOrders().SingleOrDefault(o => o.OrderId == id); if (order.OrderDate > orderDetailViewModel.ValueDate) { ModelState.AddModelError("OrderDate", "Order detail can't pre-date order"); } if (ModelState.IsValid) { orderDetailViewModel.OrderId = id; var orderDetail = Mapper.Map<OrderDetail>(orderDetailViewModel); _orderDetailRepository.Add(orderDetail); _orderDetailRepository.SaveChanges(); orderDetailViewModel.OrderDetailId = orderDetail.OrderDetailId; } var resultData = new[] { orderDetailViewModel }; return Json(resultData.AsQueryable().ToDataSourceResult(dataSourceRequest, ModelState)); }
public JsonResult UpdateOrderDetail([DataSourceRequest] DataSourceRequest dataSourceRequest, OrderDetailViewModel orderDetailViewModel) { var order = _orderRepository.GetOrderById(orderDetailViewModel.OrderId); if (order.OrderDate > orderDetailViewModel.ValueDate) { ModelState.AddModelError("OrderDate", "Order detail can't pre-date order"); } if (ModelState.IsValid) { var recordToUpdate = _orderDetailRepository.GetOrderDetailById(orderDetailViewModel.OrderDetailId); recordToUpdate.NetWeight = orderDetailViewModel.NetWeight; recordToUpdate.Origin = orderDetailViewModel.Origin; recordToUpdate.PricePerUnitOfWeight = orderDetailViewModel.PricePerUnitOfWeight; recordToUpdate.Units = orderDetailViewModel.Units; recordToUpdate.UnitWeight = orderDetailViewModel.UnitWeight; recordToUpdate.ValueDate = orderDetailViewModel.ValueDate; recordToUpdate.PackageTypeId = int.Parse(orderDetailViewModel.PackageTypeId); _orderRepository.SaveChanges(); } var resultData = new[] { orderDetailViewModel }; return Json(resultData.AsQueryable().ToDataSourceResult(dataSourceRequest, ModelState)); }
private IQueryable<Customer> ArrangeCustomers() { var data = new[] { new Customer { Gender = Gender.Female, IsActive = true, Name = "Foo" }, new Customer { Gender = Gender.Male, IsActive = false, Name = "Bar" } }; return data.AsQueryable(); }
public JsonResult DeleteOrderDetail(OrderDetailViewModel orderDetailViewModel, [DataSourceRequest] DataSourceRequest dataSourceRequest) { var recordToDelete = _orderDetailRepository.GetOrderDetailById(orderDetailViewModel.OrderDetailId); if (recordToDelete != null) { _orderDetailRepository.Remove(recordToDelete); _orderDetailRepository.SaveChanges(); } var resultData = new[] { orderDetailViewModel }; return Json(resultData.AsQueryable().ToDataSourceResult(dataSourceRequest)); }
public ActionResult GetItems(GridParams g) { var items = new[] { new Wicked { Name = "" } }; return Json(new GridModelBuilder<Wicked>(items.AsQueryable(), g).Build()); }
public ActionResult UsersCreate([DataSourceRequest] DataSourceRequest request, UserViewModel user) { if (this.ModelState.IsValid) { var entity = new User { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, Salary = 0, }; this.UserService.Add(entity, user.RoleId); user.Id = entity.Id; } var resultData = new[] { user }; return this.Json(resultData.AsQueryable().ToDataSourceResult(request, this.ModelState)); }
public void Get_HasVirtualMachines_ReturnsList() { // Arrange var machineList = new[] { new VirtualMachine {Name = "Machine1"}, new VirtualMachine {Name = "Machine2"}, new VirtualMachine {Name = "Machine3"} }; var repository = MockRepository.GenerateMock<IVirtualMachineRepository>(); repository.Expect(x => x.Read()) .Repeat.Once() .Return(machineList.AsQueryable()); var messenger = MockRepository.GenerateStub<IMessenger>(); var controller = new VirtualMachinesController(repository, messenger); // Act var result = controller.Get(); // Assert Assert.That(result.Any(), Is.True); repository.VerifyAllExpectations(); }
public void Get_HasManyVirtualMachines_ReturnsPartialList() { // Arrange var machineList = new[] { new VirtualMachine {Name = "Machine1"}, new VirtualMachine {Name = "Machine2"}, new VirtualMachine {Name = "Machine3"}, new VirtualMachine {Name = "Machine4"}, new VirtualMachine {Name = "Machine5"}, new VirtualMachine {Name = "Machine6"}, new VirtualMachine {Name = "Machine7"}, new VirtualMachine {Name = "Machine8"}, new VirtualMachine {Name = "Machine9"}, new VirtualMachine {Name = "Machine10"}, new VirtualMachine {Name = "Machine11"}, new VirtualMachine {Name = "Machine12"}, new VirtualMachine {Name = "Machine13"}, new VirtualMachine {Name = "Machine14"}, new VirtualMachine {Name = "Machine15"}, new VirtualMachine {Name = "Machine16"}, new VirtualMachine {Name = "Machine17"}, new VirtualMachine {Name = "Machine18"}, new VirtualMachine {Name = "Machine19"}, new VirtualMachine {Name = "Machine20"}, new VirtualMachine {Name = "Machine21"}, new VirtualMachine {Name = "Machine22"}, new VirtualMachine {Name = "Machine23"}, new VirtualMachine {Name = "Machine24"}, new VirtualMachine {Name = "Machine25"}, new VirtualMachine {Name = "Machine26"}, new VirtualMachine {Name = "Machine27"} }; var repository = MockRepository.GenerateMock<IVirtualMachineRepository>(); repository.Expect(x => x.Read()) .Repeat.Once() .Return(machineList.AsQueryable()); var messenger = MockRepository.GenerateStub<IMessenger>(); var controller = new VirtualMachinesController(repository, messenger); // Act var result = controller.Get(); // Assert Assert.That(result.Count(), Is.EqualTo(25)); repository.VerifyAllExpectations(); }
public void Should_not_fail() { var items = new[] { new Parent { Value = 5 } }; var projected = items.AsQueryable().ProjectTo<ParentDto>(_config).ToList(); typeof(NullReferenceException).ShouldNotBeThrownBy(() => items.AsQueryable().ProjectTo<ParentDto>(_config).ToList()); Assert.NotNull(projected[0].Date); }