コード例 #1
0
        public BackendTest()
        {
            var optionsBuilder = new DbContextOptionsBuilder <NotesAPIContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            NotesAPIContext context = new NotesAPIContext(optionsBuilder.Options);

            _controller = new NotesController(context);
            CreateTestData(context);
        }
        //Notes note;

        public IntegrationTest()
        {
            var host = new TestServer(
                new WebHostBuilder()
                .UseEnvironment("Testing")
                .UseStartup <Startup>());

            _context = host.Host.Services.GetService(typeof(NotesAPIContext)) as NotesAPIContext;
            _client  = host.CreateClient();

            notes = new List <Notes>();
            notes.Add(note);
            notes.Add(note1);
            _context.AddRange(notes);
            _context.SaveChanges();
            //CreateList(notes);
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, NotesAPIContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseHttpsRedirection();
            app.UseMvc();
            context.Database.Migrate();
        }
コード例 #4
0
 public NotesServices(IOptions <Settings> settings)
 {
     _context = new NotesAPIContext(settings);
 }
コード例 #5
0
        private void CreateTestData(NotesAPIContext context)
        {
            var notes = new List <Notes>();

            Notes note = new Notes();

            note.Title = "title1";
            note.Label = new List <Label>
            {
                new Label {
                    LabelName = "label1"
                },
                new Label {
                    LabelName = "label2"
                }
            };
            note.IsPlainText = true;
            note.IsPinned    = true;
            note.Content     = new List <Content>()
            {
                new Content {
                    ContentData = "content ...... .... ..."
                }
            };
            notes.Add(note);

            Notes note1 = new Notes();

            note1.Title = "title2";
            note1.Label = new List <Label>
            {
                new Label {
                    LabelName = "label21"
                },
                new Label {
                    LabelName = "label2"
                }
            };
            note1.IsPlainText = false;

            notes.Add(note1);


            Notes note2 = new Notes();

            note2.Title = "title3";
            note2.Label = new List <Label>
            {
                new Label {
                    LabelName = "label31"
                },
                new Label {
                    LabelName = "label32"
                }
            };
            note2.IsPlainText = false;
            note2.IsPinned    = true;
            notes.Add(note2);

            //{
            //        Title = "title1",
            //        Label = new List<Label>
            //        {
            //            new Label{LabelName="label1"},
            //            new Label{LabelName="label2"}
            //        },
            //        IsPlainText = true
            //    },

            //    {
            //        Title = "title2",
            //        Label = new List<Label>
            //        {
            //            new Label{LabelName="label21"},
            //            new Label{LabelName="label22"}
            //        },
            //        IsPlainText = false
            //    }
            //};

            List <Notes> temp = notes as List <Notes>;

            context.AddRange(notes);
            context.SaveChanges();

            // Console.WriteLine(notes[0].Id +" ========= "+notes[1].Id);
        }
コード例 #6
0
 public NotesController(NotesAPIContext aPIContext)
 {
     _notesContext = aPIContext;
 }
コード例 #7
0
 public NotesService(NotesAPIContext context)
 {
     _context = context;
 }