public void Test_Delete_IfSerieIsNull()
        {
            m_MockSeriePropertyPresenter.Serie = null;

            ISerieService serieService = ObjectFactory.GetInstance<ISerieService>();
            var series = serieService.GetAll();

            SeriePropertyPresenter seriePropertyPresenter = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyPresenter.Delete();

            Assert.AreEqual(series.Count, serieService.GetAll().Count);
        }
        public void Test_SetFieldsEmpty()
        {
            SeriePropertyPresenter seriePropertyService = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyService.SetFieldsEmpty();

            Assert.AreEqual(string.Empty, m_MockSeriePropertyPresenter.Name.Text);
            Assert.AreEqual(string.Empty, m_MockSeriePropertyPresenter.Description.Text);
            Assert.AreEqual(string.Empty, m_MockSeriePropertyPresenter.PublicationYear.Text);

            ICategoryService categoryService = ObjectFactory.GetInstance<ICategoryService>();
            var category = categoryService.GetById(1);

            Assert.AreEqual(category.Id.ToString(), m_MockSeriePropertyPresenter.ChooseCategory.SelectedItem.Value);
            Assert.AreEqual(category.Name, m_MockSeriePropertyPresenter.ChooseCategory.SelectedItem.Text);
        }
        public void Test_Delete_IfSerieIsNotNull()
        {
            ISerieService serieService = ObjectFactory.GetInstance<ISerieService>();
            int oldSerieCount = serieService.GetAll().Count;
            serieService.SaveOrUpdate(new Serie{ Id = 0, Name = "Test", Description = "test", PublicationYear = DateTime.Today, Category = new Category { Id = 1}});

            var series = serieService.GetAll();

            Assert.AreEqual(oldSerieCount + 1, series.Count);
            m_MockSeriePropertyPresenter.Serie = series.OrderBy(x => x.Id).LastOrDefault();

            SeriePropertyPresenter seriePropertyPresenter = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyPresenter.Delete();

            Assert.AreEqual(series.Count-1, serieService.GetAll().Count);
        }
        public void Test_Update_IfYearIsNotValid()
        {
            m_MockSeriePropertyPresenter.Serie = new Serie{ Id = 0, Name = "name", Description = "desc", PublicationYear = new DateTime(1700, 1, 1), Category = new Category { Id = 1 }};

            SeriePropertyPresenter seriePropertyService = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyService.SetFields();

            Assert.IsFalse(seriePropertyService.Update());

            Assert.IsTrue(m_MockSeriePropertyPresenter.ErrorMessage.Visible);
            string expected = "Bitte geben Sie ein gültiges Jahr ein!" + Environment.NewLine;
            Assert.AreEqual(expected, m_MockSeriePropertyPresenter.ErrorMessage.Text);
        }
        public void Test_Update_IfNameAndYearAreValid()
        {
            m_MockSeriePropertyPresenter.Serie = new Serie{ Id = 0, Name = "test serie update", Description = "desc serie update", PublicationYear = new DateTime(1981, 1, 1), Category = new Category { Id = 1 }};

            SeriePropertyPresenter seriePropertyService = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyService.SetFields();

            Assert.IsTrue(seriePropertyService.Update());

            Assert.IsFalse(m_MockSeriePropertyPresenter.ErrorMessage.Visible);
            Assert.AreEqual(string.Empty, m_MockSeriePropertyPresenter.ErrorMessage.Text);

            //Revert saving
            ISerieService serieService = ObjectFactory.GetInstance<ISerieService>();
            var series = serieService.GetAll();
            serieService.DeleteById(series[series.Count - 1].Id);
        }
        public void Test_SetToViewMode()
        {
            SeriePropertyPresenter seriePropertyService = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            seriePropertyService.SetToEditMode();

            Assert.IsFalse(m_MockSeriePropertyPresenter.NewSerieButton.Visible);
            Assert.IsFalse(m_MockSeriePropertyPresenter.NewFigurButton.Visible);
            Assert.IsTrue(m_MockSeriePropertyPresenter.SaveButton.Visible);
            Assert.IsFalse(m_MockSeriePropertyPresenter.DeleteButton.Visible);
            Assert.IsTrue(m_MockSeriePropertyPresenter.CancelButton.Visible);
        }
        public void Test_SetFields_CateogryIsNotNull()
        {
            SeriePropertyPresenter seriePropertyService = new SeriePropertyPresenter(m_MockSeriePropertyPresenter);
            m_MockSeriePropertyPresenter.Serie = new Serie{ Id = 0, Name = "Test", Description = "Desc", PublicationYear = new DateTime(2000, 1, 1),
                                                        Category = new Category {Id = 1}};
            seriePropertyService.SetFields();

            Assert.AreEqual("Test", m_MockSeriePropertyPresenter.Name.Text);
            Assert.AreEqual("Desc", m_MockSeriePropertyPresenter.Description.Text);
            Assert.AreEqual("2000", m_MockSeriePropertyPresenter.PublicationYear.Text);

            ICategoryService categoryService = ObjectFactory.GetInstance<ICategoryService>();
            var category = categoryService.GetById(1);

            Assert.AreEqual(category.Id.ToString(), m_MockSeriePropertyPresenter.ChooseCategory.SelectedItem.Value);
            Assert.AreEqual(category.Name, m_MockSeriePropertyPresenter.ChooseCategory.SelectedItem.Text);
        }