public void Can_Comment_A_Saved_Post() { var newPost = new Post() { Body = "Corpo do post!", Title = "Titulo do post", Slug = "Titulo do post".Slugify(), Author = "Renata Fan" }; var repository = new NHibernateRepository<Post>(SessionFactory, null); repository.Add(newPost); Session.Flush(); Post saved = repository.FirstOrDefault(c => c.Id == newPost.Id); saved.Comment("Eeeeeeeeeeeu!", "Chapolin", "*****@*****.**"); Session.Flush(); Assert.AreEqual(1, saved.Comments.Count()); Assert.AreEqual("Chapolin", saved.Comments.FirstOrDefault().Author); Assert.AreEqual("Eeeeeeeeeeeu!", saved.Comments.FirstOrDefault().Text); Assert.AreEqual("*****@*****.**", saved.Comments.FirstOrDefault().Mail); }
public void AddsArrayOfElementsToTheRepository() { //// SETUP var testEntities = new List<TestEntity> { new TestEntity { Name = "One" }, new TestEntity { Name = "Two" }, new TestEntity { Name = "Three" } }; using (var session = GetInMemoryDatabaseSession()) { // Mock session factory that will provide the in-memory session. var mockSessionFactory = new Mock<ISessionFactory>(); mockSessionFactory.Setup(mock => mock.OpenSession()).Returns(session); // Setup target var target = new NHibernateRepository<TestEntity>(mockSessionFactory.Object); // EXECUTE var result = target.Add(testEntities); //// VERIFY var query = session.Query<TestEntity>(); Assert.True(result); Assert.AreEqual(testEntities.Count, query.Count()); foreach (var entity in testEntities) { Assert.True(query.Contains(entity)); } } }
public void Can_Change_A_Saved_Post() { var newPost = new Post() { Body = "Corpo do post!", Title = "Titulo do post", Slug = "Titulo do post".Slugify(), Author = "Renata Fan" }; var repository = new NHibernateRepository<Post>(SessionFactory, null); repository.Add(newPost); Session.Flush(); Post saved = repository.FirstOrDefault(c => c.Id == newPost.Id); saved.Title += "Changed"; saved.Body += "Changed"; saved.Slug += saved.Title.Slugify(); Session.Flush(); Assert.AreEqual("Corpo do post!Changed", saved.Body); Assert.AreEqual("Titulo do postChanged", saved.Title); }
public void Test_Create_Child_ActivityDetail() { ChildActivityDetail cg = new ChildActivityDetail() { EventDate = DateTime.Today, StartTime = DateTime.Now, Child = new ChildDetail() { Key = 1 }, Activity = new ChildActivityType() { Key = 3 } }; NHibernateRepository ds = new NHibernateRepository(_sessionFactory); using (ctx = ctx.Start()) { ctx.BeginTransaction(); ds.Add(cg); ctx.Commit(); Console.WriteLine(cg.Key); Assert.That(cg.Key > 0); } }
public IEnumerable <string> Add <T>(T entity) where T : class { using (NHibernateRepository <T> repository = new NHibernateRepository <T>(ConnectionString, DomainAssemblyName)) { IEnumerable <string> rules; repository.Add(entity, out rules); return(rules); } }
public void Add(StockLevelModel stockLevel) { NHibernateUnitOfWork unitOfWork = (NHibernateUnitOfWork)UnitOfWork.Start(); IRepository <StockLevelModel, int> stockLevelRepository = new NHibernateRepository <StockLevelModel, int>(unitOfWork); stockLevelRepository.Add(stockLevel); unitOfWork.SaveChanges(); unitOfWork.Dispose(); }
public void Add(WarehouseModel warehouse) { NHibernateUnitOfWork unitOfWork = (NHibernateUnitOfWork)UnitOfWork.Start(); IRepository <WarehouseModel, int> warehouseRepository = new NHibernateRepository <WarehouseModel, int>(unitOfWork); warehouseRepository.Add(warehouse); unitOfWork.SaveChanges(); unitOfWork.Dispose(); }
private void LoadPosts(NHibernateRepository<Post> repository) { for (int i = 0; i < 10; i++) { var post = new Post() { Body = "Body" + i, Title = "Title" + i, Slug = ("Title" + i).Slugify(), Author = "Renata Fan" }; repository.Add(post); } Session.Flush(); }
public void Can_Create_A_New_Post() { var newPost = new Post() { Body = "Corpo do post!", Title = "Titulo do post", Slug = "Titulo do post".Slugify(), Author = "Renata Fan" }; var repository = new NHibernateRepository<Post>(SessionFactory, null); repository.Add(newPost); Session.Flush(); Assert.IsNotNull(newPost.Id); Assert.IsTrue(newPost.CreatedAt.IsToday()); Assert.AreEqual("Corpo do post!", newPost.Body); Assert.AreEqual("Titulo do post", newPost.Title); Assert.AreEqual("Renata Fan", newPost.Author); }
public void Can_Delete_A_Saved_Post() { var newPost = new Post() { Body = "Corpo do post!", Title = "Titulo do post", Slug = "Titulo do post".Slugify(), Author = "Renata Fan" }; var repository = new NHibernateRepository<Post>(SessionFactory, null); repository.Add(newPost); Session.Flush(); Post saved = repository.FirstOrDefault(c => c.Id == newPost.Id); repository.Remove(saved); Session.Flush(); Assert.AreEqual(0, repository.Count); }
public virtual void ChangeState(ComponentState state) { Severity oldSeverity = SeverityCode; Timestamp = state.Timestamp; SeverityCode = state.SeverityCode; if (state.SeverityCode != Severity.Info) { SeverityCode = state.SeverityCode; Timestamp = state.Timestamp; Message = ((state.Message != null) && !state.Message.Equals(System.DBNull.Value)) ? state.Message : "No message"; } state.ParentComponent = this; //if (States == null) //{ // States = new List<ComponentState>(); //} //States.Add(state); if (!Config.Section.Current.StoreDuplicateComponentStateEvents && (oldSeverity == SeverityCode)) return; using (var stateRepository = new NHibernateRepository<ComponentState>()) { stateRepository.Add(state); } if (oldSeverity != SeverityCode) { if (oldSeverity == Severity.Fatal && IsWorkSeverity(SeverityCode)) { using (var incidentRepository = new ComponentIncidentRepository()) { incidentRepository.CloseAll(state); } } if (IsWorkSeverity(oldSeverity) && SeverityCode == Severity.Fatal) { using (var incidentRepository = new ComponentIncidentRepository()) { var unclosedList = incidentRepository.GetUnclosedList(this); if (unclosedList.Count == 0) { var incident = new ComponentIncident() {ParentComponent = this, InitialComponentState = state}; incidentRepository.Add(incident); } } } ParentDevice.OnComponentStateChanged(this); } }
public void AddSingleElementToTheRepository() { //// SETUP var testEntity = new TestEntity { Name = "One" }; using (var session = GetInMemoryDatabaseSession()) { // Mock session factory that will provide the in-memory session. var mockSessionFactory = new Mock<ISessionFactory>(); mockSessionFactory.Setup(mock => mock.OpenSession()).Returns(session); // Setup target var target = new NHibernateRepository<TestEntity>(mockSessionFactory.Object); // EXECUTE var result = target.Add(testEntity); // VERIFY var query = session.Query<TestEntity>(); Assert.True(result); Assert.True(query.Contains(testEntity)); Assert.AreEqual(1, query.Count()); } }
public void ReturnsFalseOnFailure() { using (var session = GetInMemoryDatabaseSession()) { // Mock session factory that will provide the in-memory session. var mockSessionFactory = new Mock<ISessionFactory>(); mockSessionFactory.Setup(mock => mock.OpenSession()).Returns(session); // Setup target var target = new NHibernateRepository<TestEntity>(mockSessionFactory.Object); // EXECUTE var resultSingle = target.Add((TestEntity)null); var resultListing = target.Add(new List<TestEntity> { (TestEntity)null }); //// VERIFY var query = session.Query<TestEntity>(); Assert.False(resultSingle); Assert.False(resultListing); Assert.AreEqual(0, query.Count()); } }
public virtual AComponent GetOrCreateComponent(Component.Type typeCode, int position) { AComponent result; lock (GlobalLocker.DeviceComponentLocker) { try { result = GetComponentByExternal(typeCode, position); } catch (Exception ex) { Logger.Warn("Component not found", ex); result = CreateComponent(typeCode, position); using (var compRepository = new NHibernateRepository<AComponent>()) { compRepository.Add(result); } } } return result; }