public void CanAddNewManafacturer()
        {
            var manafacturer = new Manafacturer
            {
                Name = "TestManafacturer 6",
                Website = "www.testco6.co.uk"
            };

            IManafacturerRepository repository = new ManafacturerRepository();
            repository.Add(manafacturer);

            // use session to try to load the Manafacturer
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Manafacturer>(manafacturer.ManafacturerId);
                // Test that the Manafacturer was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(manafacturer, fromDb);
                Assert.AreEqual(manafacturer.Name, fromDb.Name);
                Assert.AreEqual(manafacturer.Website, fromDb.Website);
            }
        }
        public void CanUpdateExistingManafacturer()
        {
            if (_manafacturers != null)
            {
                var manafacturer = _manafacturers[0];
                manafacturer.Name = "TestManafacturerRename";
                manafacturer.Website = "www.TestManafacturerWebsiteChange.co.uk";

                IManafacturerRepository repository = new ManafacturerRepository();
                repository.Update(manafacturer);

                // use session to try to load the Manafacturer
                using (ISession session = _sessionFactory.OpenSession())
                {
                    var fromDb = session.Get<Manafacturer>(manafacturer.ManafacturerId);
                    Assert.AreEqual(manafacturer.Name, fromDb.Name);
                    Assert.AreEqual(manafacturer.Website, fromDb.Website);
                }
            }
        }
        public void CanRemoveExistingManafacturer()
        {
            var manafacturer = _manafacturers[0];
            IManafacturerRepository repository = new ManafacturerRepository();
            repository.Remove(manafacturer);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Manafacturer>(manafacturer.ManafacturerId);
                Assert.IsNull(fromDb);
            }
        }
        public void CanGetExistingManafacturerList()
        {
            IManafacturerRepository repository = new ManafacturerRepository();
            var fromDb = repository.List();

            Assert.AreEqual(5, fromDb.Count);
            Assert.IsTrue(IsInManafacturerCollection(_manafacturers[0], fromDb));
            Assert.IsTrue(IsInManafacturerCollection(_manafacturers[1], fromDb));
            Assert.IsTrue(IsInManafacturerCollection(_manafacturers[2], fromDb));
            Assert.IsTrue(IsInManafacturerCollection(_manafacturers[3], fromDb));
            Assert.IsTrue(IsInManafacturerCollection(_manafacturers[4], fromDb));
        }
        public void CanGetExistingManafacturerByManafacturerName()
        {
            IManafacturerRepository repository = new ManafacturerRepository();
            var fromDb = repository.GetByName(_manafacturers[1].Name);

            Assert.IsNotNull(fromDb);
            Assert.AreNotSame(_manafacturers[1], fromDb);
            Assert.AreEqual(_manafacturers[1].ManafacturerId, fromDb.ManafacturerId);
        }
        public void CanGetDistinctManafacturerNameList()
        {
            IManafacturerRepository repository = new ManafacturerRepository();
            var fromDb = repository.DistinctNamesList();

            Assert.AreEqual(5, fromDb.Count);
            Assert.IsTrue(IsInManafacturerNameCollection(_manafacturers[0].Name, fromDb));
            Assert.IsTrue(IsInManafacturerNameCollection(_manafacturers[1].Name, fromDb));
            Assert.IsTrue(IsInManafacturerNameCollection(_manafacturers[2].Name, fromDb));
            Assert.IsTrue(IsInManafacturerNameCollection(_manafacturers[3].Name, fromDb));
            Assert.IsTrue(IsInManafacturerNameCollection(_manafacturers[4].Name, fromDb));
        }
        public void CanCheckAndAddManafacturerWhereNotExisting()
        {
            var manafacturer = new Manafacturer
            {
                Name = "TestManafacturer 7",
                Website = "www.testco7.co.uk"
            };
            IManafacturerRepository repository = new ManafacturerRepository();
            var fromDb = repository.DistinctNamesList();
            Assert.IsFalse(IsInManafacturerNameCollection(manafacturer.Name, fromDb));

            var newManFromDb = repository.GetByManafacturerId(repository.CheckExistingNamesAdd(manafacturer.Name));
            Assert.IsTrue(manafacturer.Name == newManFromDb.Name);
        }