/// <summary> /// Initializes a new instance of the <see cref="MessageRepositoryTests"/> class. /// </summary> public MessageRepositoryTests() { var options = new DbContextOptionsBuilder <HelloWorldContext>() .UseInMemoryDatabase($"HelloWorld{Guid.NewGuid()}") .Options; this.helloWorldContextTestDouble = new HelloWorldContext(options); this.systemUnderTest = new MessageRepository(this.helloWorldContextTestDouble); }
public static void Route(Activity activity) { if (_messenger == null) { _messenger = new Messenger(activity.ServiceUrl); _context = new HelloWorldContext(_messenger); var loop = _context.RunAsync(); } _messenger.Route(activity); }
public async Task Test() { DbContextOptions <HelloWorldContext> options = new DbContextOptions <HelloWorldContext>(); HelloWorldContext context = new HelloWorldContext(options); HelloWorldRepository repo = new HelloWorldRepository(context); HelloWorldController controller = new HelloWorldController(repo); string str = await controller.GetStringAsync(); Assert.AreEqual(str, "Hello World"); }
private void Initialize() { using (var db = new HelloWorldContext()) { var _modelRepository = new ModelDbRepository(db); var userTypes = (from ut in _modelRepository.Fetch <UserType>() select ut).ToList(); if (!userTypes.Any(u => u.UserTypeId == 1)) { Trace.TraceInformation("Inserting UserType"); var userTypeSystem = new UserType { UserTypeId = 1, UserTypeDescription = "System", CreatedOn = DateTime.Now, CreatedByUserName = "******" }; _modelRepository.Add(userTypeSystem); } if (!userTypes.Any(u => u.UserTypeId == 2)) { Trace.TraceInformation("Inserting UserType"); var userTypeBusiness = new UserType { UserTypeId = 2, UserTypeDescription = "Business", CreatedOn = DateTime.Now, CreatedByUserName = "******" }; _modelRepository.Add(userTypeBusiness); } _modelRepository.SaveChanges(); userTypes = (from ut in _modelRepository.Fetch <UserType>() select ut).ToList(); var users = (from u in _modelRepository.Fetch <User>() select u).ToList(); if (!users.Any(u => u.UserId == 1)) { Trace.TraceInformation("Inserting UserType"); var userJohn = new User { UserId = 1, FirstName = "John", LastName = "Doe", CreatedByUserName = "******", CreatedOn = DateTime.Now, UserTypeId = userTypes.FirstOrDefault().UserTypeId }; _modelRepository.Add(userJohn); } if (!users.Any(u => u.UserId == 2)) { Trace.TraceInformation("Inserting UserType"); var userJane = new User { UserId = 2, FirstName = "Jane", LastName = "Doe", CreatedByUserName = "******", CreatedOn = DateTime.Now, UserTypeId = userTypes.FirstOrDefault().UserTypeId }; _modelRepository.Add(userJane); } _modelRepository.SaveChanges(); } }
public HelloWorldController(HelloWorldContext context) { _context = context; if (_context.HelloWorldItems.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. _context.HelloWorldItems.Add(new HelloWorldItem()); _context.SaveChanges(); } }
public HelloWorldController(HelloWorldContext context) { _context = context; if (_context.HelloWorldItems.Count() == 0) { _context.HelloWorldItems.Add(new HelloWorldItem { Name = "Item1" }); _context.SaveChanges(); } }
private static HelloWorldRepository TestRepo() { var builder = new DbContextOptionsBuilder <HelloWorldContext>(); builder.UseInMemoryDatabase(databaseName: "TestRepo"); var context = new HelloWorldContext(builder.Options); var repo = new HelloWorldRepository(context); return(repo); }
public HelloWorldController(HelloWorldContext context) { _context = context; if (_context.PensionCompanies.Count() == 0) { // Create a new PensionCompany if collection is empty, // which means you can't delete all PensionCompanies. _context.PensionCompanies.Add(new PensionCompany { Name = "PlatinPension" }); _context.PensionCompanies.Add(new PensionCompany { Name = "BedreEndIngen Pension" }); _context.SaveChanges(); } }
static public bool AjouterEmploye(Employe employe) { try { using (var db = new HelloWorldContext()) { db.Employes.Add(employe); var count = db.SaveChanges(); } } catch (System.Exception e) { throw e; } return(true); }
static public Employe ObtenirEmploye(int id) { Employe employe = null; try { using (var db = new HelloWorldContext()) { employe = db.Employes.Find(id); } } catch (System.Exception e) { throw e; } return(employe); }
static void Main(string[] args) { Console.WriteLine("Hello world!"); using (var db = new HelloWorldContext()) { Console.WriteLine(); Console.WriteLine("Les employés en base de données :"); foreach (var employe in db.Employes) { Console.WriteLine(" - {0} {1}", employe.Nom, employe.Prenom); foreach (var telephone in employe.Telephones) { Console.WriteLine(" -- {0} {1}", telephone.TypeTelephone.Libelle, telephone.Numero); } } } var e = Traitement.ObtenirEmploye(1); Console.WriteLine("{0} {1}", e.Nom, e.Prenom); // foreach (var telephone in employe.Telephones) // { // Console.WriteLine("{0} {1}", telephone.Numero, telephone.TypeTelephone.Libelle); // } // using (var db = new HelloWorldContext()) // { // db.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/adonet" }); // var count = db.SaveChanges(); // Console.WriteLine("{0} records saved to database", count); // Console.WriteLine(); // Console.WriteLine("All blogs in database:"); // foreach (var blog in db.Blogs) // { // Console.WriteLine(" - {0}", blog.Url); // } // } }
public string HelloWorld(string firstName) { try { Initialize(); using (var db = new HelloWorldContext()) { var _modelRepository = new ModelDbRepository(db); var user = (from u in _modelRepository.Fetch <User>() where u.FirstName == firstName select u).FirstOrDefault(); if (user == null) { return($"Hello World - user {firstName} don't exists"); } return($"Hello {firstName}"); } } catch (Exception ex) { //TODO: Log error return(ex.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="MessageRepository"/> class. /// </summary> /// <param name="helloWorldContext">A <see cref="HelloWorldContext"/>.</param> public MessageRepository( HelloWorldContext helloWorldContext) { this.helloWorldContext = helloWorldContext; }
public StudentController(HelloWorldContext context) { _context = context; }
public GradesController(HelloWorldContext context) { _context = context; }
public PersonService(HelloWorldContext context) { _context = context; }
public HelloWorldRepository(HelloWorldContext context) { _context = context; }
public MoviesController(HelloWorldContext context) //The constructor uses Dependency Injection to inject the database context (MvcMovieContext) into the controller. { _context = context; }
private void Awake() { context = new HelloWorldContext(this); }
public SlackAPIController(HelloWorldContext context) { _context = context; }
public PeopleController(HelloWorldContext context) { _context = context; }
public HelloWorld() { this.context = new HelloWorldContext(this); this.context.Observer = ObserverConsole.Instance; }