public bool Update(Figur figur) { IValidator validator = ObjectFactory.GetInstance<IValidator>(); bool isValid = true; if (!validator.IsValidString(m_FigurPropertyPresenter.Name.Text)) { m_FigurPropertyPresenter.ErrorMessage.Text = "Bitte geben Sie einen Namen für die Figur ein!" + Environment.NewLine; m_FigurPropertyPresenter.ErrorMessage.Visible = true; isValid = false; } if (!validator.IsValidPrice(m_FigurPropertyPresenter.Price.Text)) { m_FigurPropertyPresenter.ErrorMessage.Text += "Bitte geben Sie einen gültigen Preis ein!" + Environment.NewLine; m_FigurPropertyPresenter.ErrorMessage.Visible = true; isValid = false; } if (!isValid) return false; IFigurService figurService = ObjectFactory.GetInstance<IFigurService>(); figurService.SaveOrUpdate(new Figur { Id = figur == null ? 0 : figur.Id, Name = m_FigurPropertyPresenter.Name.Text, Description = m_FigurPropertyPresenter.Description.Text, Price = Convert.ToDecimal(m_FigurPropertyPresenter.Price.Text), Serie = new Serie { Id = Convert.ToInt32(m_FigurPropertyPresenter.ChooseSerie.SelectedValue) } }); m_FigurPropertyPresenter.ErrorMessage.Visible = false; return true; }
public void Delete(Figur figur) { if (figur == null) return; IFigurService figurService = ObjectFactory.GetInstance<IFigurService>(); figurService.DeleteById(figur.Id); }
protected override void Because() { using (IUnitOfWork uow = UnitOfWork.Start()) { using (IGenericTransaction transaction = uow.BeginTransaction()) { m_Id = m_FigurRepository.Add(m_Figur); m_NewFigur = m_FigurRepository.GetById(m_Id); transaction.Rollback(); } } }
public void Test_AddFigur() { IFigurRepository figurRepository = ObjectFactory.GetInstance<IFigurRepository>(); Figur figur = new Figur { Id = 1, Name = "Name", Description = "Test", Price = (decimal) 1.11, Serie = new Serie { Id = 1} }; figurRepository.Add(figur); int figurId = figurRepository.GetAll().FindLast(x => x.Id > 0).Id; Figur newFigur = figurRepository.GetById(figurId); Assert.IsNotNull(newFigur); Assert.AreEqual(figurId, newFigur.Id); Assert.AreEqual("Name", newFigur.Name); Assert.AreEqual("Test", newFigur.Description); Assert.AreEqual(1.11, newFigur.Price); Assert.AreEqual(1, newFigur.Serie.Id); figurRepository.DeleteById(figurId); Assert.IsFalse(figurRepository.HasId(figurId)); }
protected override void Context() { m_FigurRepository = ObjectFactory.GetInstance<IFigurRepository>(); m_Figur = new Figur { Id = 0, Name = "test", Description = "desc", Price = (decimal)1.67, Serie = new Serie { Id = 15 } }; }
protected override void Because() { using (UnitOfWork.Start()) { m_ReturnValue = m_FigurRepository.GetById(FigurId); } }
public void Test_TryInsertFigurWithWrongConstraint_ShouldFail() { IFigurRepository figurRepository = ObjectFactory.GetInstance<IFigurRepository>(); Figur figur = new Figur { Id = 0, Name = "test", Description = "desc", Price = (decimal)1.67, Serie = new Serie { Id = 15 } }; figurRepository.Add(figur); }