public JsonDataContext CreateNewContext(IContext context) { var myContext = new JsonDataContext(); myContext.Configuration.ProxyCreationEnabled = false; return(myContext); }
public void Setup() { _mockHttp = new MockHttpMessageHandler(); _mockHttp.When("*") .Respond("application/json", @"[{ ""name"":""Bob"",""gender"":""Male"",""age"":23,""pets"":[{""name"":""Garfield"",""type"":""Cat""}]}]"); _httpClient = new HttpClient(_mockHttp); _jsonDataContext = new JsonDataContext(_httpClient); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddControllers(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/GuestLogin"; options.LogoutPath = "/Account/GuestLogin?handler=SignOut"; options.ClaimsIssuer = "FoodMaster"; options.Cookie.MaxAge = TimeSpan.FromDays(5); options.Cookie.IsEssential = true; options.Cookie.Name = "FoodMaster"; options.EventsType = typeof(CookieValidatorEvents); }); services.AddScoped <CookieValidatorEvents>(); services.AddAutoMapper(this.GetType().Assembly); services.AddSingleton <JsonDataContext>(_ => JsonDataContext.Create()); services.AddSingleton(s => s.GetRequiredService <JsonDataContext>().Meals); services.AddSingleton(s => s.GetRequiredService <JsonDataContext>().Ingredients); services.AddSingleton(s => s.GetRequiredService <JsonDataContext>().Users); services.AddSingleton(s => s.GetRequiredService <JsonDataContext>().Orders); services.AddSingleton(s => s.GetRequiredService <JsonDataContext>().Categories); services.AddScoped <IStockService, StockService>(); services.AddScoped <IMealsService, MealsService>(); services.AddScoped <IUsersService, UsersService>(); services.AddScoped <IOrdersService, OrdersService>(); services.AddHttpContextAccessor(); services.AddScoped <ICartService>(s => { var carts = s.GetRequiredService <JsonDataContext>().Carts; var httpContextAccessor = s.GetRequiredService <IHttpContextAccessor>(); var userId = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var userCart = carts.FirstOrDefault(cart => cart.UserId == userId); if (userCart == null) { userCart = new Cart { UserId = userId, Items = new List <CartItem>() }; carts.Add(userCart); } var mealService = s.GetRequiredService <IMealsService>(); return(new CartService(userCart.Items, mealService)); }); services.AddSingleton <WriteToDiskFilterAttribute>(); services.AddSingleton <IDiscountProvider, BirthdayDiscountProvider>(); }
static void Main(string[] args) { var db = new JsonDataContext<Book>(); var books = LoadBooksFromLibrary(db); foreach(var book in books) { Console.WriteLine("{0} by {1}", book.Title, book.Creator); } var bookSaver = new BookSaver(); //bookSaver.Save(books.First()); }
static void Main(string[] args) { var db = new JsonDataContext <Book>(); var books = LoadBooksFromLibrary(db); foreach (var book in books) { Console.WriteLine("{0} by {1}", book.Title, book.Creator); } var bookSaver = new BookSaver(); //bookSaver.Save(books.First()); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Books = new System.Windows.Forms.ListView(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // Books // var db = new JsonDataContext<Book>(); var books = LoadBooksFromLibrary(db); var items = books.Select(b => new ListViewItem(new string[] { b.ID.ToString(), b.Title, b.Creator })).ToArray(); this.Books.Columns.Add("ID", 50); this.Books.Columns.Add("Title", 100); this.Books.Columns.Add("Creator", 100); foreach (var item in items) { this.Books.Items.Add(item); } this.Books.Location = new System.Drawing.Point(111, 122); this.Books.Name = "Books"; this.Books.Size = new System.Drawing.Size(321, 119); this.Books.TabIndex = 0; this.Books.UseCompatibleStateImageBehavior = false; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(119, 97); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(37, 13); this.label1.TabIndex = 1; this.label1.Text = "Books"; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(553, 387); this.Controls.Add(this.label1); this.Controls.Add(this.Books); this.Name = "MainForm"; this.Text = "Main Form"; this.ResumeLayout(false); this.PerformLayout(); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Books = new System.Windows.Forms.ListView(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // Books // var db = new JsonDataContext <Book>(); var books = LoadBooksFromLibrary(db); var items = books.Select(b => new ListViewItem(new string[] { b.ID.ToString(), b.Title, b.Creator })).ToArray(); this.Books.Columns.Add("ID", 50); this.Books.Columns.Add("Title", 100); this.Books.Columns.Add("Creator", 100); foreach (var item in items) { this.Books.Items.Add(item); } this.Books.Location = new System.Drawing.Point(111, 122); this.Books.Name = "Books"; this.Books.Size = new System.Drawing.Size(321, 119); this.Books.TabIndex = 0; this.Books.UseCompatibleStateImageBehavior = false; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(119, 97); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(37, 13); this.label1.TabIndex = 1; this.label1.Text = "Books"; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(553, 387); this.Controls.Add(this.label1); this.Controls.Add(this.Books); this.Name = "MainForm"; this.Text = "Main Form"; this.ResumeLayout(false); this.PerformLayout(); }
public void Save_EmptyList_ShouldDeleteFile() { //Arrange var dataContext = new JsonDataContext <Book>("books.json"); if (!File.Exists("books.json")) { File.Create("books.json"); } //Act dataContext.Save(null); //Assert bool fileExists = File.Exists("books.json"); Assert.IsFalse(fileExists); }
public void LoadData_DataExists_ShouldReturnCollection() { //Arrange var dataContext = new JsonDataContext <Book>("books.json"); var books = new List <Book>(); var book = new Book(); book.Id = 1; book.Title = "Hello"; book.Author = "World"; book.DateOfissue = 1984; books.Add(book); dataContext.Save(books); //Act IEnumerable <Book> actual = dataContext.LoadData(); //Assert Assert.IsNotNull(actual); }
public PersonRepository(JsonDataContext entityContext) : base(entityContext) { }
public FriendRepository(JsonDataContext entityContext) : base(entityContext) { }
public WriteToDiskFilterAttribute(JsonDataContext dataContext) { this.dataContext = dataContext; }
protected BaseRepository(JsonDataContext entityContext) { _entityContext = entityContext; }
public JsonRepositoryBase(JsonDataContextFactory <T> jsonDataContextFactory) { _dataContext = jsonDataContextFactory.Create(); }