Beispiel #1
0
        public void CreateReadUpdateDelete_Works()
        {
            CrudAccessor crud = new CrudAccessor();

            crud.Run(@"CREATE TABLE IF NOT EXISTS CrudItem ( Id integer PRIMARY KEY AUTOINCREMENT, Counter integer NOT NULL, String nvarchar(50) NULL );");
            crud.Run(@"DELETE FROM CrudItem;");

            IList <CrudItem> newItems = Enumerable.Range(0, 20).Select(i => new CrudItem()
            {
                Counter = i
            }).ToList();

            crud.Create(newItems);

            newItems.ShouldAllBe(it => it.Id > 0);

            foreach (CrudItem item in newItems)
            {
                item.Counter *= 2;
            }

            crud.Update(newItems);

            IList <CrudItem> getItems = crud.Get <CrudItem>();

            getItems.Select(it => it.Counter).ShouldBe(Enumerable.Range(0, 20).Select(i => i * 2));

            crud.Delete(getItems);

            crud.Get <CrudItem>().ShouldBeEmpty();
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Invalid arguments.");

                return(-1);
            }

            string connectionString = args[0];
            string resultsPath      = args[1];

            if (File.Exists(resultsPath))
            {
                File.Delete(resultsPath);
            }

            Console.WriteLine();
            Console.WriteLine("| ConnectionString: " + connectionString);
            Console.WriteLine("| ResultsPath: " + resultsPath);
            Console.WriteLine();
            Console.WriteLine("> Running integration code...");

            Settings.ConnectionString = connectionString;

            CrudAccessor accessor = new CrudAccessor();

            accessor.Clear();

            var newMovies = new[]
            {
                new Movie()
                {
                    Id = 1, Title = "Coming to America", ReleaseYear = 1988
                },
                new Movie()
                {
                    Id = 2, Title = "Coming 2 America", ReleaseYear = 2020
                },
                new Movie()
                {
                    Id = 3, Title = "Coming 3 America", ReleaseYear = 2028
                },
            };

            var newDetails = new MovieDetails()
            {
                MovieId = 1, Tagline = "The Four Funniest Men in America are Eddie Murphy"
            };

            var newCast = new[]
            {
                new MovieCast()
                {
                    Id = 1, MovieId = 1, Actor = "Eddie Murphy", Plays = "Prince Akeem"
                },
                new MovieCast()
                {
                    Id = 2, MovieId = 1, Actor = "Arsenio Hall", Plays = "Semmi"
                },
                new MovieCast()
                {
                    Id = 3, MovieId = 2, Actor = "Eddie Murphy", Plays = "Randy Jackson"
                },
            };

            accessor.Create(newMovies);
            accessor.Create(newDetails);
            accessor.Create(newCast);

            var updateDetails = new MovieDetails()
            {
                MovieId = 1, Tagline = "This summer, Prince Akeem discovers America."
            };
            var deleteMovie = new Movie()
            {
                Id = 3
            };

            accessor.Update(updateDetails);
            accessor.Delete(deleteMovie);

            var movies = accessor.GetDatabaseView();

            VerifyModel(movies);

            accessor.VerifyImport();

            Console.WriteLine($"> Ran to EOF. Writing results to '{resultsPath}'.");
            Console.WriteLine();

            File.WriteAllText(resultsPath, "OK");

            return(0);
        }