public void ShouldAllowTwoDifferentContextsToBeLoadedInTheSameAppDomain() { //Arrange var container = new WindsorContainer(); var configuration = new AggregateConfiguration("Test", new IMappingConfiguration[] { new FooMappingConfiguration(), new BarMappingConfiguration() }, null, null, new[] {typeof (Foo), typeof (Bar)}); var secondConfiguration = new AggregateConfiguration("Test", new IMappingConfiguration[] {new FooMappingConfiguration()}, null, null, new[] {typeof (Foo)}); container.Register( Component.For<IAggregateConfiguration>().Instance(configuration).Named(AggregateConfigurationKeyFactory.GenerateKey<Foo,Bar>()), Component.For<IAggregateConfiguration>().Instance(secondConfiguration).Named(AggregateConfigurationKeyFactory.GenerateKey<Foo>())); var windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); IDataContext context = AggregateContextFactory.Create<Foo, Bar>(); IDataContext contextTwo = AggregateContextFactory.Create<Foo>(); var foo = new Foo(); var bar = new Bar(); // Act context.Add(foo); context.Add(bar); contextTwo.Add(foo); // Assert // peek under the covers and ensure that each add went // to the right DbContext. Assert.AreNotEqual(context.GetType().FullName, contextTwo.GetType().FullName); ObjectContext objectContext = ((IObjectContextAdapter) context).ObjectContext; Assert.IsTrue(objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 2); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).First().EntitySet.Name == "Foos"); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Last().EntitySet.Name == "Bars"); ObjectContext objectContextTwo = ((IObjectContextAdapter) contextTwo).ObjectContext; Assert.IsTrue(objectContextTwo.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 1); Assert.IsTrue( objectContextTwo.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Single().EntitySet.Name == "Foos"); }
public void CanFilterWithABasicCriteria() { //arrange var expectedItem = new Foo {Name = "Devlin", Id = 16}; var items = new List<Foo> { new Foo {Name = "Test", Id = 15}, expectedItem }; //act IEnumerable<Foo> results = items.FilterBy(Criteria.Field<string>("Name").IsEqualTo("Devlin")); //assert Assert.IsTrue(results.Any()); Assert.AreEqual(expectedItem, results.Single()); }
public void ShouldReturnFoo() { //Arrange var context = new TestDataContext(Settings.Default.Connection, new FooMappingConfiguration(), new ConsoleOutLogger("Test", LogLevel.All, true, true, true, string.Empty)); var item = new Foo(); context.Add(item); context.Commit(); var target = Queries.GetById<Foo>(item.Id); //Act var result = target.Execute(context); //Assert Assert.AreEqual(item.Id, result.Id); context.Remove(result); context.Commit(); }
public void When_Paging_Should_Affect_The_Base_Query_Before_It_Is_Executed() { //Arrange var targetFoo = new Foo(); var context = MockRepository.GenerateStrictMock<IDataContext>(); context.Expect(x => x.AsQueryable<Foo>()).Return(new List<Foo> { new Foo(), new Foo(), new Foo(), new Foo(), targetFoo }.AsQueryable()).Repeat.Once(); var query = new FindFoo(); //Act IEnumerable<Foo> retVal = query.Skip(4).Take(1).Execute(context); //Assert retVal.First().ShouldBeSame(targetFoo); }
public void CanFilterWithAnOrCriteria() { //arrange var expectedItem = new Foo {Name = "Devlin", Id = 16, Address = "Testing"}; var expectedItemTwo = new Foo {Name = "Tim", Id = 10, Address = "Not the one"}; var items = new List<Foo> { new Foo {Name = "Test", Id = 15}, expectedItemTwo, expectedItem }; //act IEnumerable<Foo> results = items.FilterBy(Criteria.Field<string>("Name").IsEqualTo("Devlin") .Or(Criteria.Field<string>("Name") .IsEqualTo("Tim"))); //assert Assert.AreEqual(2, results.Count()); Assert.AreEqual(expectedItem, results.Single(x => x.Name == "Devlin")); Assert.AreEqual(expectedItemTwo, results.Single(x => x.Name == "Tim")); }
public void ShouldAddToTheCorrectContext() { // Arrange var container = new WindsorContainer(); var configuration = new AggregateConfiguration("Test", new IMappingConfiguration[] { new FooMappingConfiguration(), new BarMappingConfiguration() }, null, null, new[] {typeof (Foo), typeof (Bar)}); container.Register( Component.For<IAggregateConfiguration>().Instance(configuration) .Named(AggregateConfigurationKeyFactory.GenerateKey<Foo,Bar>())); string typeName = string.Format("{0},{1}", typeof (Foo).FullName, typeof (Bar).FullName); var windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); IDataContext context = AggregateContextFactory.Create<Foo, Bar>(); var foo = new Foo(); var bar = new Bar(); // Act context.Add(foo); context.Add(bar); // Assert // peek under the covers and ensure that each add went // to the right DbContext. ObjectContext objectContext = ((IObjectContextAdapter) context).ObjectContext; Assert.IsTrue(objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 2); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).First().EntitySet.Name == "Foos"); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Last().EntitySet.Name == "Bars"); }
public void ShouldReturnAllFoos() { //Arrange var context = new TestDataContext(Settings.Default.Connection, new FooMappingConfiguration(), new ConsoleOutLogger("Test", LogLevel.All, true, true, true, string.Empty)); var item = new Foo(); var item2 = new Foo(); context.Add(item); context.Add(item2); context.Commit(); var expectedCount = context.AsQueryable<Foo>().Count(); var target = Queries.FindAll<Foo>(); //Act var results = target.Execute(context); //Assert Assert.AreEqual(results.Count(), expectedCount); context.Remove(item); context.Remove(item2); context.Commit(); }