public void CanSaveSoftware() { var sw = new Software { Name = "ActiveRecord" }; dao.Save(sw); conv.Commit(); int count = 0; conv.Execute(s => count = s.Query<Software>().Where(ar => ar.Name == "ActiveRecord").Count()); Assert.That(count, Is.EqualTo(1)); }
public void CanFindSavedSoftware() { var sw = new Software { Name = "ActiveRecord" }; dao.Save(sw); var id = sw.Id; var sw2 = dao.Find(id); Assert.That(sw2.Id, Is.EqualTo(sw.Id)); Assert.That(sw2.Name, Is.EqualTo(sw.Name)); }
public void SimpleSmokeTest() { AR.StartDefaultConversation(); var software = new Software { Name = "FooBar" }; software.Save(); AR.Commit(); var loaded = AR.Linq<Software>().Where(s => s.Name == "FooBar").First(); // Will be from 1st level cache, hence same object Assert.That(loaded, Is.SameAs(software)); AR.EndDefaultConversation(); }
public void CustomDaosCanBeAdded() { var guid = Guid.NewGuid(); var software = new Software { Id = guid, Name = "FooBar" }; var mock = new MockInstaller(true); var dao = MockRepository.GenerateMock<IDao<Software>>(); dao.Expect(d => d.Find(guid)).Return(software); mock.RegisterDaoDouble(dao); var container = mock.GetConfiguredContainer(); Assert.That(container.Resolve<IDao<Software>>().Find(guid), Is.SameAs(software)); var ex = Assert.Throws<InvalidOperationException>( () => container.Resolve<IDao<Installation>>().Find(guid)); Assert.That(ex.Message.ToLower(), Contains.Substring("unexpected")); Assert.That(ex.Message.ToLower(), Contains.Substring("strict")); }
public void SmokeTestOnDifferentSessions() { AR.StartDefaultConversation(); var software = new Software { Name = "FooBar" }; software.Save(); Assert.That(software.Id, Is.Not.EqualTo(Guid.Empty)); AR.Commit(); AR.Restart(); var loaded = AR.Linq<Software>().Where(s => s.Name == "FooBar").First(); // Will not be from 1st level cache, hence different object Assert.That(loaded, Is.Not.SameAs(software)); Assert.That(loaded.Id, Is.EqualTo(software.Id)); AR.EndDefaultConversation(); }
public void DirtyEntitiesAreNotFlushedBeforeCommit() { var software = new Software { Name = "Foo" }; using (var session = sessionFactory.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Save(software); tx.Commit(); } } software = null; using (var session = sessionFactory.OpenSession()) { using (var tx = session.BeginTransaction()) { software = session.Query<Software>().First(); } Assert.That(software, Is.Not.Null); Assert.That(software.Name, Is.EqualTo("Foo")); software.Name = "Bar"; Assert.That(software.Name, Is.EqualTo("Bar")); var all = session.Query<Software>().ToList(); //using (var tx = session.BeginTransaction()) // tx.Commit(); } software = null; using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) software = session.Query<Software>().First(); Assert.That(software.Name, Is.EqualTo("Foo")); }
public void DirtyEntitiesCanBeCommittedLater() { var software = new Software { Name = "Foo" }; using (var session = sessionFactory.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Save(software); tx.Commit(); } } software = null; using (var session = sessionFactory.OpenSession()) { using (var tx = session.BeginTransaction()) { software = session.Query<Software>().First(); } Assert.That(software, Is.Not.Null); Assert.That(software.Name, Is.EqualTo("Foo")); software.Name = "Bar"; Assert.That(software.Name, Is.EqualTo("Bar")); using (var tx = session.BeginTransaction()) tx.Commit(); } software = null; using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) software = session.Query<Software>().First(); Assert.That(software.Name, Is.EqualTo("Bar")); }
public void SmokeTest() { // resolving those is only needed when AR is not used... var dao = container.Resolve<IDao<Software>>(); var c = container.Resolve<IConversation>(); var cc = container.Resolve<IConversationContext>(); cc.SetDefaultConversation(c); Assert.That(dao, Is.Not.Null); var software = new Software { Name = "ActiveRecord" }; dao.Save(software); c.Commit(); var loaded = dao.Linq().Where(s => s.Name == "ActiveRecord").First(); Assert.That(loaded.Id, Is.EqualTo(software.Id)); dao.Delete(software); c.Commit(); Assert.That(dao.Linq().Count(), Is.EqualTo(0)); }
public void FullTest() { // Arrange var guid = Guid.NewGuid(); var software = new Software { Id = Guid.Empty, Name = "FooBar" }; var mock = new MockInstaller(true); var dao = MockRepository.GenerateMock<IDao<Software>>(); dao.Expect(d => d.Save(software)).WhenCalled(i => { software.Id = guid; }); dao.Expect(d => d.Find(guid)).Return(software); mock.RegisterDaoDouble(dao); var conv = MockRepository.GenerateMock<IConversation>(); conv.Expect(c => c.Execute(Arg<Action>.Is.Anything)).WhenCalled(i => ((Action)i.Arguments[0]).Invoke()); conv.Expect(c => c.Commit()); mock.RegisterConversationDouble(conv); AR.Install(mock); // Act using (var conversation = AR.StartConversation()) { conv.Execute(() => software.Save()); conv.Commit(); Assert.That(AR.Find<Software>(guid), Is.SameAs(software)); } //Assert dao.VerifyAllExpectations(); conv.VerifyAllExpectations(); }
public void ExtForget() { var software = new Software { Name = "ActiveRecord" }; mocks.Dao.Expect(d => d.Forget(software)); software.Forget(); }
public void ExtAdd() { var software = new Software { Name = "ActiveRecord" }; mocks.Dao.Expect(d => d.Add(software)); software.Add(); }
public void ExtDelete() { var software = new Software { Name = "ActiveRecord" }; mocks.Dao.Expect(d => d.Delete(software)); software.Delete(); }
public void Peek() { var id = Guid.NewGuid(); var software = new Software { Name = "ActiveRecord" }; mocks.Dao.Expect(d => d.Peek(id)).Return(software); Assert.That(AR.Peek<Software>(id), Is.SameAs(software)); }
public void Replace() { var software = new Software { Name = "ActiveRecord" }; mocks.Dao.Expect(d => d.Replace(software)); AR.Replace(software); }
public void CanQuerySavedSoftware() { var sw = new Software { Name = "ActiveRecord" }; dao.Save(sw); var query = from soft in dao.Linq() where soft.Name == "ActiveRecord" select soft; Assert.That(query.Count(), Is.EqualTo(1)); var sw2 = query.First(); Assert.That(sw2.Id, Is.EqualTo(sw.Id)); Assert.That(sw2.Name, Is.EqualTo(sw.Name)); }
public void CanAttachDetachSoftware() { Guid id; int count = 0; var sw = new Software { Name = "ActiveRecord" }; dao.Save(sw); id = sw.Id; conv.Commit(); conv.Execute(s => count = s.Query<Software>().Where(e => e.Name == "ActiveRecord").Count()); Assert.That(count, Is.EqualTo(1)); var sw2 = dao.Find(id); sw2.Name = "ActiveRecord vNext"; dao.Forget(sw2); conv.Commit(); conv.Execute(s => count = s.Query<Software>().Where(e => e.Name == "ActiveRecord").Count()); Assert.That(count, Is.EqualTo(1)); dao.Save(sw2); conv.Commit(); conv.Execute(s => count = s.Query<Software>().Where(e => e.Name == "ActiveRecord vNext").Count()); Assert.That(count, Is.EqualTo(1)); }
public void DifferentSessionsHoldDifferentObjectsAndNoAutomaticFlushOccurs() { var software = new Software { Name = "Foo" }; using (var session = sessionFactory.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Save(software); tx.Commit(); } } software = null; ISession session1 = null, session2 = null; try { session1 = sessionFactory.OpenSession(); session2 = sessionFactory.OpenSession(); Software software1, software2; using (session1.BeginTransaction()) software1 = session1.Query<Software>().First(); using (session2.BeginTransaction()) software2 = session2.Query<Software>().First(); Assert.That(software1.Id,Is.EqualTo(software2.Id)); Assert.That(software1, Is.Not.SameAs(software2)); software2.Name = "Bar"; using (session2.BeginTransaction()) Assert.That(session2.Query<Software>().Where(s=>s.Name == "Bar").Count(), Is.EqualTo(1)); // flush must occur using (session1.BeginTransaction()) session1.Refresh(software1); Assert.That(software1.Name, Is.EqualTo("Foo")); } finally { if (session1 != null) session1.Dispose(); if (session2 != null) session2.Dispose(); } }