public NewsViewModel.Preview CreateNews(String title)
        {
            YoumotoDbContext context = this.context ?? new YoumotoDbContext();
            News             newNews = NewsPersister.Create(title);

            context.News.Add(newNews);
            context.SaveChanges();

            return(new NewsViewModel.Preview(newNews));
        }
Beispiel #2
0
        public void CreateAndSaveNews()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                News news = NewsPersister.Create(NewsTests.newsTitle);

                context.News.Add(news);
                context.SaveChanges();

                Assert.AreEqual(NewsTests.newsTitle, news.Title);
            }
        }
        public void CreateAndSaveManufacturer()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Manufacturer manufacturer = Manufacturer.Create(ManufacturerTests.manufacturerName);

                context.Manufacturers.Add(manufacturer);
                context.SaveChanges();

                Assert.AreEqual(ManufacturerTests.manufacturerName, manufacturer.Name);
            }
        }
Beispiel #4
0
        public void CreateAndSaveVehicle()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Vehicle vehicle = Vehicle.Create(VehicleTests.vehicleName);

                context.Vehicles.Add(vehicle);
                context.SaveChanges();

                Assert.AreEqual(VehicleTests.vehicleName, vehicle.Name);
            }
        }
        public NewsViewModel.Details AddPicture(Guid newsGuid, String pictureUrl)
        {
            YoumotoDbContext context = this.context ?? new YoumotoDbContext();

            var result = NewsPersister.LoadSingle(context, newsGuid);

            var newPicture = NewsPersister.CreatePicture(result, pictureUrl);

            context.NewsPictures.Add(newPicture);
            context.SaveChanges();

            return(new Models.NewsViewModel.Details(result));
        }
        public void TestLoadSingleWithExistingGuid()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Picture newPicture = PicturePersister.Create();
                context.Pictures.Add(newPicture);
                context.SaveChanges();

                var picture = PicturePersister.LoadSingle(context, newPicture.Guid);
                Assert.IsNotNull(picture);
                Assert.AreEqual(newPicture, picture);
            }
        }
Beispiel #7
0
        public void CreateAndSaveSeries()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Manufacturer manufacturer = Manufacturer.Create(SeriesTests.manufacturerName);
                Series       series       = Series.Create(manufacturer, SeriesTests.seriesName);

                context.Manufacturers.Add(manufacturer);
                context.Series.Add(series);
                context.SaveChanges();

                Assert.AreEqual(SeriesTests.seriesName, series.Name);
            }
        }
        public NewsViewModel.Details DeleteVehicle(Guid newsVehicleGuid)
        {
            YoumotoDbContext context = this.context ?? new YoumotoDbContext();

            var item = NewsPersister.LoadSingleVehicle(context, newsVehicleGuid);
            var news = item.News;

            context.NewsVehicles.Remove(item);
            context.SaveChanges();

            var result = new Models.NewsViewModel.Details(news);

            return(result);
        }
        public NewsViewModel.Details AddVehicle(Guid newsGuid, Guid vehicleGuid)
        {
            YoumotoDbContext context = this.context ?? new YoumotoDbContext();

            var result  = NewsPersister.LoadSingle(context, newsGuid);
            var vehicle = VehiclePersister.LoadSingle(context, vehicleGuid);

            var newPicture = NewsPersister.CreateVehicle(result, vehicle);

            context.NewsVehicles.Add(newPicture);
            context.SaveChanges();

            return(new Models.NewsViewModel.Details(result));
        }
        public void CreateNewsPicture()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                String      url         = "https://www.youmoto.com/test.jpg";
                News        news        = NewsPersister.Create("MyTitle");
                NewsPicture newsPicture = NewsPersister.CreatePicture(news, url);

                context.News.Add(news);
                context.SaveChanges();

                Assert.AreEqual(1, context.News.Count());
                Assert.AreEqual(1, context.NewsPictures.Count());
                Assert.AreEqual(1, context.News.First().NewsPictures.Count());
                Assert.AreEqual(url, context.News.First().NewsPictures.First().ImageLink);
            }
        }
Beispiel #11
0
        public void LoadNewsPagedSecoundChunk()
        {
            Int32 newsCount = 5;

            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                List <News> testNews = this.CreateTestNews(newsCount, context);

                context.SaveChanges();

                var paged = NewsPersister.LoadLatestPaged(context, 2, 2).ToList();

                Assert.AreEqual(2, paged.Count());
                Assert.AreEqual(testNews[newsCount - 3].Guid, paged[0].Guid);
                Assert.AreEqual(testNews[newsCount - 4].Guid, paged[1].Guid);
            }
        }
Beispiel #12
0
        public void CreateAndSaveVehicleWithAssociationToManufacturer()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Manufacturer manufacturer = Manufacturer.Create(VehicleTests.manufacturerName);
                context.Manufacturers.Add(manufacturer);

                Vehicle vehicle = Vehicle.Create(VehicleTests.vehicleName);
                context.Vehicles.Add(vehicle);

                ManufacturerVehicle manufacturerVehicle = ManufacturerVehicle.Create(manufacturer, vehicle);
                context.ManufacturerVehicles.Add(manufacturerVehicle);

                context.SaveChanges();

                Assert.AreEqual(1, vehicle.ManufacturerVehicles.Count());
                Assert.AreEqual(manufacturer, vehicle.ManufacturerVehicles.First().Manufacturer);
            }
        }